From b062117ef4aba429518533f502a4181e67a1acf5 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 2 Feb 2019 16:14:58 -0800 Subject: HTML5 writer: implement WAI-ARIA roles for (end)notes. See #4213. --- src/Text/Pandoc/Writers/HTML.hs | 37 +++++++++++++++++++++++++------------ test/writer.html5 | 20 ++++++++++---------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 7329d8197..8a55cae65 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -521,7 +521,9 @@ footnoteSection opts notes = do , epubVersion == Just EPUB3 = H5.section ! A.class_ "footnotes" ! customAttribute "epub:type" "footnotes" $ x - | html5 = H5.section ! A.class_ "footnotes" $ x + | html5 = H5.section ! A.class_ "footnotes" + ! customAttribute "role" "doc-endnotes" + $ x | slideVariant /= NoSlides = H.div ! A.class_ "footnotes slide" $ x | otherwise = H.div ! A.class_ "footnotes" $ x return $ @@ -1183,6 +1185,8 @@ inlineToHtml opts inline = do $ toHtml ref return $ case epubVersion of Just EPUB3 -> link ! customAttribute "epub:type" "noteref" + _ | html5 -> link ! H5.customAttribute + "role" "doc-noteref" _ -> link (Cite cits il)-> do contents <- inlineListToHtml opts il let citationIds = unwords $ map citationId cits @@ -1191,12 +1195,17 @@ inlineToHtml opts inline = do then result ! customAttribute "data-cites" (toValue citationIds) else result -blockListToNote :: PandocMonad m => WriterOptions -> String -> [Block] -> StateT WriterState m Html -blockListToNote opts ref blocks = +blockListToNote :: PandocMonad m + => WriterOptions -> String -> [Block] + -> StateT WriterState m Html +blockListToNote opts ref blocks = do + html5 <- gets stHtml5 -- If last block is Para or Plain, include the backlink at the end of -- that block. Otherwise, insert a new Plain block with the backlink. - let backlink = [Link ("",["footnote-back"],[]) [Str "↩"] ("#" ++ "fnref" ++ ref,[])] - blocks' = if null blocks + let kvs = if html5 then [("role","doc-backlink")] else [] + let backlink = [Link ("",["footnote-back"],kvs) + [Str "↩"] ("#" ++ "fnref" ++ ref,[])] + let blocks' = if null blocks then [] else let lastBlock = last blocks otherBlocks = init blocks @@ -1207,13 +1216,16 @@ blockListToNote opts ref blocks = [Plain (lst ++ backlink)] _ -> otherBlocks ++ [lastBlock, Plain backlink] - in do contents <- blockListToHtml opts blocks' - let noteItem = H.li ! prefixedId opts ("fn" ++ ref) $ contents - epubVersion <- gets stEPUBVersion - let noteItem' = case epubVersion of - Just EPUB3 -> noteItem ! customAttribute "epub:type" "footnote" - _ -> noteItem - return $ nl opts >> noteItem' + contents <- blockListToHtml opts blocks' + let noteItem = H.li ! prefixedId opts ("fn" ++ ref) $ contents + epubVersion <- gets stEPUBVersion + let noteItem' = case epubVersion of + Just EPUB3 -> noteItem ! + customAttribute "epub:type" "footnote" + _ | html5 -> noteItem ! + customAttribute "role" "doc-endnote" + _ -> noteItem + return $ nl opts >> noteItem' isMathEnvironment :: String -> Bool isMathEnvironment s = "\\begin{" `isPrefixOf` s && @@ -1434,6 +1446,7 @@ html5Attributes = Set.fromList , "rel" , "required" , "reversed" + , "role" , "rows" , "rowspan" , "sandbox" diff --git a/test/writer.html5 b/test/writer.html5 index 57b937653..39b5344dd 100644 --- a/test/writer.html5 +++ b/test/writer.html5 @@ -526,25 +526,25 @@ Blah

Here is a movie movie icon.


Footnotes

-

Here is a footnote reference,1 and another.2 This should not be a footnote reference, because it contains a space.[^my note] Here is an inline note.3

+

Here is a footnote reference,1 and another.2 This should not be a footnote reference, because it contains a space.[^my note] Here is an inline note.3

-

Notes can go in quotes.4

+

Notes can go in quotes.4

    -
  1. And in list items.5
  2. +
  3. And in list items.5

This paragraph should not be part of the note, as it is not indented.

-
+

    -
  1. Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.

  2. -
  3. Here’s the long note. This one contains multiple blocks.

    +
  4. Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.

  5. +
  6. Here’s the long note. This one contains multiple blocks.

    Subsequent blocks are indented to show that they belong to the footnote (as with list items).

      { <code> }
    -

    If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.

  7. -
  8. This is easier to type. Inline notes may contain links and ] verbatim characters, as well as [bracketed text].

  9. -
  10. In quote.

  11. -
  12. In list.

  13. +

    If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.

    +
  14. This is easier to type. Inline notes may contain links and ] verbatim characters, as well as [bracketed text].

  15. +
  16. In quote.

  17. +
  18. In list.

-- cgit v1.2.3