diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-03-14 21:39:32 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-03-14 21:49:05 -0700 |
| commit | 1bfab1d11ecf65362c0e8fde98a66c0e6f08f258 (patch) | |
| tree | 503f014f5307c57a597d63c37c2bd70d06f1152c | |
| parent | 03d80ccd38118d6e75e7d81e62545e95ed5fea3c (diff) | |
HTML writer footnotes changes:
When `--reference-location=section` or `=block`, use an
`aside` element for the notes rather than a `section`.
When `--reference-location=section`, include the `aside`
element inside the section element, rather than outside.
(In slide shows, this option causes footnotes on a slide
to be displayed at the bottom of the slide.)
Closes #8695.
| -rw-r--r-- | MANUAL.txt | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 25 | ||||
| -rw-r--r-- | test/Tests/Writers/HTML.hs | 2 | ||||
| -rw-r--r-- | test/command/4235.md | 4 | ||||
| -rw-r--r-- | test/command/7006.md | 4 | ||||
| -rw-r--r-- | test/writer.html5 | 4 |
6 files changed, 31 insertions, 12 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index 561075732..0afe048e3 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -1013,7 +1013,9 @@ header when requesting a document from a URL: current section, or the document. The default is `document`. Currently this option only affects the `markdown`, `muse`, `html`, `epub`, `slidy`, `s5`, `slideous`, - `dzslides`, and `revealjs` writers. + `dzslides`, and `revealjs` writers. In slide formats, + specifying `--reference-location=section` will cause notes + to be rendered at the bottom of a slide. `--markdown-headings=setext`|`atx` diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 1695c1897..9f61d483c 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -543,7 +543,14 @@ footnoteSection refLocation startCounter notes = do = H5.section ! A.id "footnotes" ! A.class_ className ! customAttribute "epub:type" "footnotes" $ x - | html5 = H5.section ! A5.id "footnotes" + | html5 + , refLocation == EndOfDocument + , slideVariant == RevealJsSlides -- need a section for a new slide: + = H5.section ! A5.id "footnotes" + ! A5.class_ className + ! A5.role "doc-endnotes" + $ x + | html5 = H5.aside ! A5.id "footnotes" ! A5.class_ className ! A5.role "doc-endnotes" $ x @@ -795,7 +802,18 @@ blockToHtmlInner opts (Div (ident, "section":dclasses, dkvs) modify $ \st -> st{ stInSection = True } res <- blockListToHtml opts innerSecs modify $ \st -> st{ stInSection = inSection } - return res + notes <- gets stNotes + let emitNotes = writerReferenceLocation opts == EndOfSection && + not (null notes) + if emitNotes + then do + st <- get + renderedNotes <- footnoteSection (writerReferenceLocation opts) + (stEmittedNotes st + 1) (reverse notes) + modify (\st' -> st'{ stNotes = mempty, + stEmittedNotes = stEmittedNotes st' + length notes }) + return (res <> renderedNotes) + else return res let classes' = nubOrd $ ["title-slide" | titleSlide] ++ ["slide" | slide] ++ ["section" | (slide || writerSectionDivs opts) && @@ -1065,8 +1083,7 @@ blockToHtml opts block = do doc <- blockToHtmlInner opts block st <- get let emitNotes = - (writerReferenceLocation opts == EndOfBlock && stBlockLevel st == 1) || - (writerReferenceLocation opts == EndOfSection && isSection) + writerReferenceLocation opts == EndOfBlock && stBlockLevel st == 1 res <- if emitNotes then do notes <- if null (stNotes st) diff --git a/test/Tests/Writers/HTML.hs b/test/Tests/Writers/HTML.hs index 3ec7a866d..ea313b862 100644 --- a/test/Tests/Writers/HTML.hs +++ b/test/Tests/Writers/HTML.hs @@ -193,7 +193,6 @@ tests = , "<p>A note inside a block quote.<a href=\"#fn2\" class=\"footnote-ref\" id=\"fnref2\"><sup>2</sup></a></p>" , "<p>A second paragraph.</p>" , "</blockquote>" - , "</div>" , "<div class=\"footnotes footnotes-end-of-section\">" , "<hr />" , "<ol>" @@ -201,6 +200,7 @@ tests = , "<li id=\"fn2\"><p>The second note.<a href=\"#fnref2\" class=\"footnote-back\">↩︎</a></p></li>" , "</ol>" , "</div>" + , "</div>" , "<div class=\"section level2\">" , "<h2>Second section</h2>" , "<p>Some more text.</p>" diff --git a/test/command/4235.md b/test/command/4235.md index 09db17eea..79114017f 100644 --- a/test/command/4235.md +++ b/test/command/4235.md @@ -4,12 +4,12 @@ This.^[Has a footnote.] ^D <p>This.<a href="#foofn1" class="footnote-ref" id="foofnref1" role="doc-noteref"><sup>1</sup></a></p> -<section id="footnotes" class="footnotes footnotes-end-of-document" +<aside id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes"> <hr /> <ol> <li id="foofn1"><p>Has a footnote.<a href="#foofnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li> </ol> -</section> +</aside> ``` diff --git a/test/command/7006.md b/test/command/7006.md index 75f0faea7..a2b48c22c 100644 --- a/test/command/7006.md +++ b/test/command/7006.md @@ -8,7 +8,7 @@ Test.[^fn] ^D <p>Test.<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p> -<section id="footnotes" class="footnotes footnotes-end-of-document" +<aside id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes"> <hr /> <ol> @@ -19,5 +19,5 @@ role="doc-endnotes"> </figure> <a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></li> </ol> -</section> +</aside> ``` diff --git a/test/writer.html5 b/test/writer.html5 index 3ca41b0e1..99ff195ef 100644 --- a/test/writer.html5 +++ b/test/writer.html5 @@ -733,7 +733,7 @@ role="doc-noteref"><sup>4</sup></a></p> role="doc-noteref"><sup>5</sup></a></li> </ol> <p>This paragraph should not be part of the note, as it is not indented.</p> -<section id="footnotes" class="footnotes footnotes-end-of-document" +<aside id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes"> <hr /> <ol> @@ -756,6 +756,6 @@ role="doc-backlink">↩︎</a></p></li> <li id="fn5"><p>In list.<a href="#fnref5" class="footnote-back" role="doc-backlink">↩︎</a></p></li> </ol> -</section> +</aside> </body> </html> |
