Skip to content

Commit

Permalink
Fix problems with footnote display on Kindles
Browse files Browse the repository at this point in the history
1. Amazon "strongly recommends" the use of the `aside` element.
2. 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).
  • Loading branch information
Porges committed Mar 24, 2018
1 parent 151cc54 commit c11617c
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,20 @@ footnoteSection opts notes = do
slideVariant <- gets stSlideVariant
epubVersion <- gets stEPUBVersion
let hrtag = if html5 then H5.hr else H.hr
let elementType = if html5 then H5.section else H5.div
let elementType = if html5 then H5.section else H.div
let container x
| slideVariant /= NoSlides = elementType ! A.class_ "footnotes slide" $ x
| epubVersion == Just EPUB3 = elementType ! A.class_ "footnotes" ! customAttribute "epub:type" "footnotes" $ x
| otherwise = elementType ! A.class_ "footnotes" $ x
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 >> nl opts >>
-- if HTML5 then we're using <aside> and not <li>
(if html5 then id else H.ol) (mconcat notes >> nl opts)
>> nl opts)

-- | Parse a mailto link; return Just (name, domain) or Nothing.
parseMailto :: String -> Maybe (String, String)
Expand Down Expand Up @@ -1165,20 +1169,19 @@ blockListToNote :: PandocMonad m => WriterOptions -> String -> [Block] -> StateT
blockListToNote opts ref blocks =
-- 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
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.li
let noteItem = noteElement ! prefixedId opts ("fn" ++ ref) $ contents
epubVersion <- gets stEPUBVersion
let noteItem' = case epubVersion of
Just EPUB3 -> noteItem ! customAttribute "epub:type" "footnote"
Expand Down

0 comments on commit c11617c

Please sign in to comment.