aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFrancesco Mazzoli <f@mazzo.li>2021-09-10 18:30:05 +0200
committerGitHub <noreply@github.com>2021-09-10 09:30:05 -0700
commit99a4d1d0b06bb68e4d7a10acd642d439842004d1 (patch)
treef25abce6d8620d00fc43b9ee9db7b4b20432c7fb /test
parent1481dae629b97c5b7ad28cd162e22a52c7647784 (diff)
downloadpandoc-99a4d1d0b06bb68e4d7a10acd642d439842004d1.tar.gz
Support `--reference-location` for HTML output (#7461)
The HTML writer now supports `EndOfBlock`, `EndOfSection`, and `EndOfDocument` for reference locations. EPUB and HTML slide show formats are also affected by this change. This works similarly to the markdown writer, but with special care taken to skipping section divs with what regards to the block level. The change also takes care to not modify the output if `EndOfDocument` is used.
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Writers/HTML.hs75
-rw-r--r--test/command/4235.md2
-rw-r--r--test/command/7006.md2
-rw-r--r--test/writer.html42
-rw-r--r--test/writer.html52
5 files changed, 78 insertions, 5 deletions
diff --git a/test/Tests/Writers/HTML.hs b/test/Tests/Writers/HTML.hs
index 404f6da98..50775b171 100644
--- a/test/Tests/Writers/HTML.hs
+++ b/test/Tests/Writers/HTML.hs
@@ -8,8 +8,11 @@ import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder
+htmlWithOpts :: (ToPandoc a) => WriterOptions -> a -> String
+htmlWithOpts opts = unpack . purely (writeHtml4String opts{ writerWrapText = WrapNone }) . toPandoc
+
html :: (ToPandoc a) => a -> String
-html = unpack . purely (writeHtml4String def{ writerWrapText = WrapNone }) . toPandoc
+html = htmlWithOpts def
htmlQTags :: (ToPandoc a) => a -> String
htmlQTags = unpack
@@ -33,6 +36,21 @@ infix 4 =:
=> String -> (a, String) -> TestTree
(=:) = test html
+noteTestDoc :: Blocks
+noteTestDoc =
+ header 1 "Page title" <>
+ header 2 "First section" <>
+ para ("This is a footnote." <>
+ note (para "Down here.") <>
+ " And this is a " <>
+ link "https://www.google.com" "" "link" <>
+ ".") <>
+ blockQuote (para ("A note inside a block quote." <>
+ note (para "The second note.")) <>
+ para "A second paragraph.") <>
+ header 2 "Second section" <>
+ para "Some more text."
+
tests :: [TestTree]
tests =
[ testGroup "inline code"
@@ -86,6 +104,61 @@ tests =
=?> ("<var><code class=\"sourceCode haskell\">" ++
"<span class=\"op\">&gt;&gt;=</span></code></var>")
]
+ , testGroup "footnotes"
+ [ test (htmlWithOpts def{writerReferenceLocation=EndOfDocument})
+ "at the end of a document" $
+ noteTestDoc =?>
+ concat
+ [ "<h1>Page title</h1>"
+ , "<h2>First section</h2>"
+ , "<p>This is a footnote.<a href=\"#fn1\" class=\"footnote-ref\" id=\"fnref1\"><sup>1</sup></a> And this is a <a href=\"https://www.google.com\">link</a>.</p>"
+ , "<blockquote><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>"
+ , "<h2>Second section</h2>"
+ , "<p>Some more text.</p>"
+ , "<div class=\"footnotes footnotes-end-of-document\"><hr /><ol><li id=\"fn1\"><p>Down here.<a href=\"#fnref1\" class=\"footnote-back\">↩︎</a></p></li><li id=\"fn2\"><p>The second note.<a href=\"#fnref2\" class=\"footnote-back\">↩︎</a></p></li></ol></div>"
+ ]
+ , test (htmlWithOpts def{writerReferenceLocation=EndOfBlock})
+ "at the end of a block" $
+ noteTestDoc =?>
+ concat
+ [ "<h1>Page title</h1>"
+ , "<h2>First section</h2>"
+ , "<p>This is a footnote.<a href=\"#fn1\" class=\"footnote-ref\" id=\"fnref1\"><sup>1</sup></a> And this is a <a href=\"https://www.google.com\">link</a>.</p>"
+ , "<div class=\"footnotes footnotes-end-of-block\"><ol><li id=\"fn1\"><p>Down here.<a href=\"#fnref1\" class=\"footnote-back\">↩︎</a></p></li></ol></div>"
+ , "<blockquote><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 class=\"footnotes footnotes-end-of-block\"><ol start=\"2\"><li id=\"fn2\"><p>The second note.<a href=\"#fnref2\" class=\"footnote-back\">↩︎</a></p></li></ol></div>"
+ , "<h2>Second section</h2>"
+ , "<p>Some more text.</p>"
+ ]
+ , test (htmlWithOpts def{writerReferenceLocation=EndOfSection})
+ "at the end of a section" $
+ noteTestDoc =?>
+ concat
+ [ "<h1>Page title</h1>"
+ , "<h2>First section</h2>"
+ , "<p>This is a footnote.<a href=\"#fn1\" class=\"footnote-ref\" id=\"fnref1\"><sup>1</sup></a> And this is a <a href=\"https://www.google.com\">link</a>.</p>"
+ , "<blockquote><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 class=\"footnotes footnotes-end-of-section\"><hr /><ol><li id=\"fn1\"><p>Down here.<a href=\"#fnref1\" class=\"footnote-back\">↩︎</a></p></li><li id=\"fn2\"><p>The second note.<a href=\"#fnref2\" class=\"footnote-back\">↩︎</a></p></li></ol></div>"
+ , "<h2>Second section</h2>"
+ , "<p>Some more text.</p>"
+ ]
+ , test (htmlWithOpts def{writerReferenceLocation=EndOfSection, writerSectionDivs=True})
+ "at the end of a section, with section divs" $
+ noteTestDoc =?>
+ -- Footnotes are rendered _after_ their section (in this case after the level2 section
+ -- that contains it).
+ concat
+ [ "<div class=\"section level1\">"
+ , "<h1>Page title</h1>"
+ , "<div class=\"section level2\">"
+ , "<h2>First section</h2>"
+ , "<p>This is a footnote.<a href=\"#fn1\" class=\"footnote-ref\" id=\"fnref1\"><sup>1</sup></a> And this is a <a href=\"https://www.google.com\">link</a>.</p><blockquote><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><li id=\"fn1\"><p>Down here.<a href=\"#fnref1\" class=\"footnote-back\">↩︎</a></p></li><li id=\"fn2\"><p>The second note.<a href=\"#fnref2\" class=\"footnote-back\">↩︎</a></p></li></ol></div>"
+ , "<div class=\"section level2\"><h2>Second section</h2><p>Some more text.</p></div>"
+ , "</div>"
+ ]
+ ]
]
where
tQ :: (ToString a, ToPandoc a)
diff --git a/test/command/4235.md b/test/command/4235.md
index 8bbf43ff9..4f2644dd6 100644
--- a/test/command/4235.md
+++ b/test/command/4235.md
@@ -3,7 +3,7 @@
This.^[Has a footnote.]
^D
<p>This.<a href="#foofn1" class="footnote-ref" id="foofnref1" role="doc-noteref"><sup>1</sup></a></p>
-<section class="footnotes" role="doc-endnotes">
+<section class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
<li id="foofn1" role="doc-endnote"><p>Has a footnote.<a href="#foofnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
diff --git a/test/command/7006.md b/test/command/7006.md
index e7951fb1a..7e2215cdf 100644
--- a/test/command/7006.md
+++ b/test/command/7006.md
@@ -7,7 +7,7 @@ Test.[^fn]
![Caption.](/image.jpg)
^D
<p>Test.<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>
-<section class="footnotes" role="doc-endnotes">
+<section class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
<li id="fn1" role="doc-endnote"><p>Foo:</p>
diff --git a/test/writer.html4 b/test/writer.html4
index 215a1efb9..257d86ddb 100644
--- a/test/writer.html4
+++ b/test/writer.html4
@@ -665,7 +665,7 @@ Blah
<li>And in list items.<a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a></li>
</ol>
<p>This paragraph should not be part of the note, as it is not indented.</p>
-<div class="footnotes">
+<div class="footnotes footnotes-end-of-document">
<hr />
<ol>
<li id="fn1"><p>Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.<a href="#fnref1" class="footnote-back">↩︎</a></p></li>
diff --git a/test/writer.html5 b/test/writer.html5
index 387df4058..0141bf9fe 100644
--- a/test/writer.html5
+++ b/test/writer.html5
@@ -667,7 +667,7 @@ Blah
<li>And in list items.<a href="#fn5" class="footnote-ref" id="fnref5" 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 class="footnotes" role="doc-endnotes">
+<section class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
<li id="fn1" role="doc-endnote"><p>Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>