aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-03-08 09:21:43 -0800
committerGitHub <[email protected]>2023-03-08 09:21:43 -0800
commit92b3179e494391e1f717cf0314a0f3f15add5937 (patch)
tree2b4010df779e50907cec03dfdf99eb38feeca7bf /src
parentdd50fef01f5effb415e0c62a5345a0ab4eb14769 (diff)
HTML writer: Use different structure for epub footnotes. (#8676)
Many EPUB readers are thrown off by pandoc's current footnote output. Both the ol and the fact that the footnote backlink is at the end of the note seem to pose problems. With this commit, we now create a list of aside (or div) elements, instead of an ordered list. Each element begins with a note number that is linked back to the note reference. (So, the backlink occurs at the beginning rather than the end.) References: - https://kindlegen.s3.amazonaws.com/AmazonKindlePublishingGuidelines.pdf - http://kb.daisy.org/publishing/docs/html/notes.html See #8672, closes #5583. Thanks to @Porges and @lewer.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs84
1 files changed, 50 insertions, 34 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 9619e24ad..adc3f491d 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -559,11 +559,12 @@ footnoteSection refLocation startCounter notes = do
hrtag
-- Keep the previous output exactly the same if we don't
-- have multiple notes sections
- if startCounter == 1
- then H.ol $ mconcat notes >> nl
- else H.ol ! A.start (fromString (show startCounter)) $
- mconcat notes >> nl
- nl
+ case epubVersion of
+ Just _ -> mconcat notes
+ Nothing | startCounter == 1 ->
+ (H.ol (nl >> mconcat notes)) >> nl
+ Nothing -> (H.ol ! A.start (fromString (show startCounter)) $
+ nl >> mconcat notes) >> nl
-- | Parse a mailto link; return Just (name, domain) or Nothing.
parseMailto :: Text -> Maybe (Text, Text)
@@ -1612,36 +1613,51 @@ blockListToNote :: PandocMonad m
=> WriterOptions -> Text -> [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 kvs = [("role","doc-backlink") | html5]
- let backlink = [Link ("",["footnote-back"],kvs)
- [Str "↩"] ("#" <> "fnref" <> ref,"")]
- let blocks' = if null blocks
- then []
- else let lastBlock = last blocks
- otherBlocks = init blocks
- in case lastBlock of
- Para [Image (_,cls,_) _ (_,tit)]
- | "fig:" `T.isPrefixOf` tit
- || "r-stretch" `elem` cls
- -> otherBlocks ++ [lastBlock,
- Plain backlink]
- Para lst -> otherBlocks ++
- [Para (lst ++ backlink)]
- Plain lst -> otherBlocks ++
- [Plain (lst ++ backlink)]
- _ -> otherBlocks ++ [lastBlock,
- Plain backlink]
- 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 >> noteItem'
+ html5 <- gets stHtml5
+ case epubVersion of
+ Nothing -> do -- web page
+ -- 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 kvs = [("role","doc-backlink") | html5]
+ let backlink = [Link ("",["footnote-back"],kvs)
+ [Str "↩"] ("#" <> "fnref" <> ref,"")]
+ let blocks' = if null blocks
+ then []
+ else let lastBlock = last blocks
+ otherBlocks = init blocks
+ in case lastBlock of
+ Para [Image (_,cls,_) _ (_,tit)]
+ | "fig:" `T.isPrefixOf` tit
+ || "r-stretch" `elem` cls
+ -> otherBlocks ++ [lastBlock,
+ Plain backlink]
+ Para lst -> otherBlocks ++
+ [Para (lst ++ backlink)]
+ Plain lst -> otherBlocks ++
+ [Plain (lst ++ backlink)]
+ _ -> otherBlocks ++ [lastBlock,
+ Plain backlink]
+ contents <- blockListToHtml opts blocks'
+ let noteItem = H.li ! prefixedId opts ("fn" <> ref) $ contents
+ return $ noteItem >> nl
+ Just epubv -> do
+ let kvs = [("role","doc-backlink") | html5]
+ let backlink = Link ("",["footnote-back"],kvs)
+ [Str ref] ("#" <> "fnref" <> ref,"")
+ let blocks' =
+ case blocks of
+ (Para ils : rest) ->
+ Para (backlink : Str "." : Space : ils) : rest
+ (Plain ils : rest) ->
+ Plain (backlink : Str "." : Space : ils) : rest
+ _ -> Para [backlink , Str "."] : blocks
+ contents <- blockListToHtml opts blocks'
+ let noteItem = (if epubv == EPUB3
+ then H5.aside ! customAttribute "epub:type" "footnote"
+ else H.div) ! prefixedId opts ("fn" <> ref)
+ $ nl >> contents >> nl
+ return $ noteItem >> nl
inDiv :: PandocMonad m=> Text -> Html -> StateT WriterState m Html
inDiv cls x = do