git.iko.soy/typeable/pandoc
on master help sign in
HTML5 writer: implement WAI-ARIA roles for (end)notes.

See #4213.

commitb062117ef4aba429518533f502a4181e67a1acf5 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 2 Feb 2019, 16:14 (8 years ago) parent00cd11c
2 files changed+35−22
src/Text/Pandoc/Writers/HTML.hs+25−12 test/writer.html5+10−10
src/Text/Pandoc/Writers/HTML.hs+25−12
@@ -521,7 +521,9 @@ footnoteSection opts notes = do
521521 , epubVersion == Just EPUB3
522522 = H5.section ! A.class_ "footnotes"
523523 ! customAttribute "epub:type" "footnotes" $ x
524− | html5 = H5.section ! A.class_ "footnotes" $ x
524+ | html5 = H5.section ! A.class_ "footnotes"
525+ ! customAttribute "role" "doc-endnotes"
526+ $ x
525527 | slideVariant /= NoSlides = H.div ! A.class_ "footnotes slide" $ x
526528 | otherwise = H.div ! A.class_ "footnotes" $ x
527529 return $
@@ -1183,6 +1185,8 @@ inlineToHtml opts inline = do
11831185 $ toHtml ref
11841186 return $ case epubVersion of
11851187 Just EPUB3 -> link ! customAttribute "epub:type" "noteref"
1188+ _ | html5 -> link ! H5.customAttribute
1189+ "role" "doc-noteref"
11861190 _ -> link
11871191 (Cite cits il)-> do contents <- inlineListToHtml opts il
11881192 let citationIds = unwords $ map citationId cits
@@ -1191,12 +1195,17 @@ inlineToHtml opts inline = do
11911195 then result ! customAttribute "data-cites" (toValue citationIds)
11921196 else result
11931197
1194−blockListToNote :: PandocMonad m => WriterOptions -> String -> [Block] -> StateT WriterState m Html
1195−blockListToNote opts ref blocks =
1198+blockListToNote :: PandocMonad m
1199+ => WriterOptions -> String -> [Block]
1200+ -> StateT WriterState m Html
1201+blockListToNote opts ref blocks = do
1202+ html5 <- gets stHtml5
11961203 -- If last block is Para or Plain, include the backlink at the end of
11971204 -- that block. Otherwise, insert a new Plain block with the backlink.
1198− let backlink = [Link ("",["footnote-back"],[]) [Str "↩"] ("#" ++ "fnref" ++ ref,[])]
1199− blocks' = if null blocks
1205+ let kvs = if html5 then [("role","doc-backlink")] else []
1206+ let backlink = [Link ("",["footnote-back"],kvs)
1207+ [Str "↩"] ("#" ++ "fnref" ++ ref,[])]
1208+ let blocks' = if null blocks
12001209 then []
12011210 else let lastBlock = last blocks
12021211 otherBlocks = init blocks
@@ -1207,13 +1216,16 @@ blockListToNote opts ref blocks =
12071216 [Plain (lst ++ backlink)]
12081217 _ -> otherBlocks ++ [lastBlock,
12091218 Plain backlink]
1210− in do contents <- blockListToHtml opts blocks'
1211− let noteItem = H.li ! prefixedId opts ("fn" ++ ref) $ contents
1212− epubVersion <- gets stEPUBVersion
1213− let noteItem' = case epubVersion of
1214− Just EPUB3 -> noteItem ! customAttribute "epub:type" "footnote"
1215− _ -> noteItem
1216− return $ nl opts >> noteItem'
1219+ contents <- blockListToHtml opts blocks'
1220+ let noteItem = H.li ! prefixedId opts ("fn" ++ ref) $ contents
1221+ epubVersion <- gets stEPUBVersion
1222+ let noteItem' = case epubVersion of
1223+ Just EPUB3 -> noteItem !
1224+ customAttribute "epub:type" "footnote"
1225+ _ | html5 -> noteItem !
1226+ customAttribute "role" "doc-endnote"
1227+ _ -> noteItem
1228+ return $ nl opts >> noteItem'
12171229
12181230isMathEnvironment :: String -> Bool
12191231isMathEnvironment s = "\\begin{" `isPrefixOf` s &&
@@ -1434,6 +1446,7 @@ html5Attributes = Set.fromList
14341446 , "rel"
14351447 , "required"
14361448 , "reversed"
1449+ , "role"
14371450 , "rows"
14381451 , "rowspan"
14391452 , "sandbox"
test/writer.html5+10−10
@@ -526,25 +526,25 @@ Blah
526526<p>Here is a movie <img src="movie.jpg" alt="movie" /> icon.</p>
527527<hr />
528528<h1 id="footnotes">Footnotes</h1>
529−<p>Here is a footnote reference,<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a> and another.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a> This should <em>not</em> be a footnote reference, because it contains a space.[^my note] Here is an inline note.<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a></p>
529+<p>Here is a footnote reference,<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a> and another.<a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a> This should <em>not</em> be a footnote reference, because it contains a space.[^my note] Here is an inline note.<a href="#fn3" class="footnote-ref" id="fnref3" role="doc-noteref"><sup>3</sup></a></p>
530530<blockquote>
531−<p>Notes can go in quotes.<a href="#fn4" class="footnote-ref" id="fnref4"><sup>4</sup></a></p>
531+<p>Notes can go in quotes.<a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a></p>
532532</blockquote>
533533<ol type="1">
534−<li>And in list items.<a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a></li>
534+<li>And in list items.<a href="#fn5" class="footnote-ref" id="fnref5" role="doc-noteref"><sup>5</sup></a></li>
535535</ol>
536536<p>This paragraph should not be part of the note, as it is not indented.</p>
537−<section class="footnotes">
537+<section class="footnotes" role="doc-endnotes">
538538<hr />
539539<ol>
540−<li id="fn1"><p>Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.<a href="#fnref1" class="footnote-back">↩</a></p></li>
541−<li id="fn2"><p>Here’s the long note. This one contains multiple blocks.</p>
540+<li id="fn1" role="doc-endnote"><p>Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩</a></p></li>
541+<li id="fn2" role="doc-endnote"><p>Here’s the long note. This one contains multiple blocks.</p>
542542<p>Subsequent blocks are indented to show that they belong to the footnote (as with list items).</p>
543543<pre><code> { &lt;code&gt; }</code></pre>
544−<p>If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.<a href="#fnref2" class="footnote-back">↩</a></p></li>
545−<li id="fn3"><p>This is <em>easier</em> to type. Inline notes may contain <a href="http://google.com">links</a> and <code>]</code> verbatim characters, as well as [bracketed text].<a href="#fnref3" class="footnote-back">↩</a></p></li>
546−<li id="fn4"><p>In quote.<a href="#fnref4" class="footnote-back">↩</a></p></li>
547−<li id="fn5"><p>In list.<a href="#fnref5" class="footnote-back">↩</a></p></li>
544+<p>If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.<a href="#fnref2" class="footnote-back" role="doc-backlink">↩</a></p></li>
545+<li id="fn3" role="doc-endnote"><p>This is <em>easier</em> to type. Inline notes may contain <a href="http://google.com">links</a> and <code>]</code> verbatim characters, as well as [bracketed text].<a href="#fnref3" class="footnote-back" role="doc-backlink">↩</a></p></li>
546+<li id="fn4" role="doc-endnote"><p>In quote.<a href="#fnref4" class="footnote-back" role="doc-backlink">↩</a></p></li>
547+<li id="fn5" role="doc-endnote"><p>In list.<a href="#fnref5" class="footnote-back" role="doc-backlink">↩</a></p></li>
548548</ol>
549549</section>
550550</body>