From dd0712151b4c37fb6050973f50381f04e53310fd Mon Sep 17 00:00:00 2001 From: George Pollard Date: Sat, 24 Mar 2018 21:55:49 +1100 Subject: [PATCH] Fix problems with footnote display on Kindles 1. Backlinks must be at the start of the footnote or it causes Kindle software to mangle the display of footnotes (several footnotes are run together, and soft footnote links do not work as pop-overs). 2. Also, Amazon "strongly recommends" the use of the `aside` element. This is also recommended by Apple. So when using EPUB3 or HTML5, use `aside` elements instead of a list. Due to part 1, we have numbered backlinks at the start of footnotes, so I also changed EPUB2 to wrap with `div` (instead of `aside`) to remove the redundant numbering, and to be consistent with EPUB3 output. --- src/Text/Pandoc/Writers/HTML.hs | 30 ++++++++++++++---------------- test/command/4235.md | 4 +--- test/writer.html4 | 14 ++++++-------- test/writer.html5 | 14 ++++++-------- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index d1a36644596b..34040b42355f 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -490,8 +490,7 @@ footnoteSection opts notes = do return $ if null notes then mempty - else nl opts >> container (nl opts >> hrtag >> nl opts >> - H.ol (mconcat notes >> nl opts) >> nl opts) + else nl opts >> container (nl opts >> hrtag >> mconcat notes >> nl opts) -- | Parse a mailto link; return Just (name, domain) or Nothing. parseMailto :: String -> Maybe (String, String) @@ -1166,22 +1165,21 @@ inlineToHtml opts inline = do blockListToNote :: PandocMonad m => WriterOptions -> String -> [Block] -> StateT WriterState m Html blockListToNote opts ref blocks = - -- If last block is Para or Plain, include the backlink at the end of + -- If first block is Para or Plain, include the backlink at the start of -- that block. Otherwise, insert a new Plain block with the backlink. - let backlink = [Link ("",["footnote-back"],[]) [Str "↩"] ("#" ++ "fnref" ++ ref,[])] - blocks' = if null blocks - then [] - else let lastBlock = last blocks - otherBlocks = init blocks - in case lastBlock of - (Para lst) -> otherBlocks ++ - [Para (lst ++ backlink)] - (Plain lst) -> otherBlocks ++ - [Plain (lst ++ backlink)] - _ -> otherBlocks ++ [lastBlock, - Plain backlink] + let backlink = [Link ("",["footnote-back"],[]) [Str (ref ++ ".")] ("#" ++ "fnref" ++ ref,[]), Space] + blocks' = case blocks of + [] -> [] + (firstBlock:otherBlocks) -> + case firstBlock of + (Para lst) -> Para (backlink ++ lst) : otherBlocks + (Plain lst) -> Plain (backlink ++ lst) : otherBlocks + _ -> Plain backlink : blocks + in do contents <- blockListToHtml opts blocks' - let noteItem = H.li ! prefixedId opts ("fn" ++ ref) $ contents + html5 <- gets stHtml5 + let noteElement = if html5 then H5.aside else H.div + let noteItem = noteElement ! prefixedId opts ("fn" ++ ref) $ contents epubVersion <- gets stEPUBVersion let noteItem' = case epubVersion of Just EPUB3 -> noteItem ! customAttribute "epub:type" "footnote" diff --git a/test/command/4235.md b/test/command/4235.md index a5d5456761fe..bc8d33121e7f 100644 --- a/test/command/4235.md +++ b/test/command/4235.md @@ -5,8 +5,6 @@ This.^[Has a footnote.]

This.1


-
    -
  1. Has a footnote.

  2. -
+
``` diff --git a/test/writer.html4 b/test/writer.html4 index dc889f07a149..8c4a310064ee 100644 --- a/test/writer.html4 +++ b/test/writer.html4 @@ -534,16 +534,14 @@ Blah

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.

    +

    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. 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.

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

  6. -
  7. In quote.

  8. -
  9. In list.

  10. -
+

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

+

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

+

4. In quote.

+

5. In list.

diff --git a/test/writer.html5 b/test/writer.html5 index 53fcb84e28df..061646147064 100644 --- a/test/writer.html5 +++ b/test/writer.html5 @@ -536,16 +536,14 @@ Blah

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. -
  5. This is easier to type. Inline notes may contain links and ] verbatim characters, as well as [bracketed text].

  6. -
  7. In quote.

  8. -
  9. In list.

  10. -
+

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

+ + +