diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index c7a4703ae404..0ccb36559c28 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 @\
@ blocks we've already pushed out , stMath :: Bool -- ^ Math is used in document , stQuotes :: Bool -- ^ 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 diff --git a/test/command/8770-block.md b/test/command/8770-block.md new file mode 100644 index 000000000000..43762c97e5f3 --- /dev/null +++ b/test/command/8770-block.md @@ -0,0 +1,75 @@ +``` +% pandoc -t html5 --reference-location=block +# Section 1 + +hello[^1] + +: Sample table.[^2] + +----------- + Fruit[^3] +----------- + Bans[^4] +----------- + +# Section 2 + +dolly[^5] + +[^1]: doc footnote +[^2]: caption footnote +[^3]: header footnote +[^4]: table cell footnote +[^5]: doc footnote +^D +

Section 1

+

hello1

+ + + +++ + + + + + + + + + + +
Sample table.2
Fruit3
Bans4
+ +

Section 2

+

dolly5

+ +``` diff --git a/test/command/8770-document.md b/test/command/8770-document.md new file mode 100644 index 000000000000..da19acd93a4f --- /dev/null +++ b/test/command/8770-document.md @@ -0,0 +1,66 @@ +``` +% pandoc -t html5 --reference-location=document +# Section 1 + +hello[^1] + +: Sample table.[^2] + +----------- + Fruit[^3] +----------- + Bans[^4] +----------- + +# Section 2 + +dolly[^5] + +[^1]: doc footnote +[^2]: caption footnote +[^3]: header footnote +[^4]: table cell footnote +[^5]: doc footnote +^D +

Section 1

+

hello1

+ + +++ + + + + + + + + + + +
Sample table.2
Fruit3
Bans4
+

Section 2

+

dolly5

+
+
+
    +
  1. doc footnote↩︎

  2. +
  3. caption footnote↩︎

  4. +
  5. header footnote↩︎

  6. +
  7. table cell footnote↩︎

  8. +
  9. doc footnote↩︎

  10. +
+
+``` diff --git a/test/command/8770-section.md b/test/command/8770-section.md new file mode 100644 index 000000000000..07f063a2e683 --- /dev/null +++ b/test/command/8770-section.md @@ -0,0 +1,72 @@ +``` +% pandoc -t html5 --reference-location=section +# Section 1 + +hello[^1] + +: Sample table.[^2] + +----------- + Fruit[^3] +----------- + Bans[^4] +----------- + +# Section 2 + +dolly[^5] + +[^1]: doc footnote +[^2]: caption footnote +[^3]: header footnote +[^4]: table cell footnote +[^5]: doc footnote +^D +

Section 1

+

hello1

+ + +++ + + + + + + + + + + +
Sample table.2
Fruit3
Bans4
+ +

Section 2

+

dolly5

+ +```