diff options
| author | Sam May <[email protected]> | 2023-04-09 15:09:36 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-02-12 18:45:47 -0800 |
| commit | 758ff050b28d18c3830c85f34c1538897fd7af9b (patch) | |
| tree | e44d5f0f0a547f73f92d85bf29956fc6bff468e3 /src | |
| parent | bf674e8ddd1ddb78d6300f362a3cd98ac9382b8a (diff) | |
HTML5 writer: Add suffix to multiple footnote section ids
The first (and often only) `<aside id=footnotes>` block remains
unchanged, however any additional blocks from `--reference-location` are
distinguished as `#footnotes-2`, `#footnotes-3`, and so on. No other
existing writer seems to implement per-section IDs, including HTML4.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index c7a4703ae..0ccb36559 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -87,6 +87,7 @@ import Data.String (fromString) data WriterState = WriterState { stNotes :: [Html] -- ^ List of notes , stEmittedNotes :: Int -- ^ How many notes we've already pushed out to the HTML + , stEmittedNoteBlocks :: Int -- ^ How many @\<div class=footnote>@ blocks we've already pushed out , stMath :: Bool -- ^ Math is used in document , stQuotes :: Bool -- ^ <q> tag is used , stHighlighting :: Bool -- ^ Syntax highlighting is used @@ -102,7 +103,11 @@ data WriterState = WriterState } defaultWriterState :: WriterState -defaultWriterState = WriterState {stNotes= [], stEmittedNotes = 0, stMath = False, stQuotes = False, +defaultWriterState = WriterState {stNotes= [], + stEmittedNotes = 0, + stEmittedNoteBlocks = 0, + stMath = False, + stQuotes = False, stHighlighting = False, stHtml5 = False, stEPUBVersion = Nothing, @@ -530,6 +535,16 @@ footnoteSection opts refLocation startCounter notes = do let hrtag = if refLocation /= EndOfBlock then (if html5 then H5.hr else H.hr) <> nl else mempty + idName <- do + blockCount <- gets stEmittedNoteBlocks + modify $ \st -> st{ stEmittedNoteBlocks = blockCount + 1 } + return $ + -- Keep the first note section's id undecorated to maintain a target for + -- old links which don't expect numbered sections, or for when the notes + -- are rendered all together at the end of the document. + if blockCount <= 0 + then "footnotes" + else "footnotes-" <> show (blockCount + 1) let additionalClassName = case refLocation of EndOfBlock -> "footnotes-end-of-block" EndOfDocument -> "footnotes-end-of-document" @@ -539,17 +554,17 @@ footnoteSection opts refLocation startCounter notes = do let container x | html5 , epubVersion == Just EPUB3 - = H5.section ! A.id "footnotes" + = H5.section ! A.id (fromString idName) ! A.class_ className ! customAttribute "epub:type" "footnotes" $ x | html5 , refLocation == EndOfDocument -- Note: we need a section for a new slide in slide formats. - = H5.section ! A5.id "footnotes" + = H5.section ! A5.id (fromString idName) ! A5.class_ className ! A5.role "doc-endnotes" $ x - | html5 = H5.aside ! prefixedId opts "footnotes" + | html5 = H5.aside ! prefixedId opts (fromString idName) ! A5.class_ className ! A5.role "doc-footnote" $ x |
