summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README20
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs14
-rw-r--r--tests/s5.basic.html8
-rw-r--r--tests/s5.fancy.html8
-rw-r--r--tests/s5.fragment.html3
-rw-r--r--tests/s5.inserts.html3
-rw-r--r--tests/writer.html29
-rw-r--r--tests/writer.smart.html29
8 files changed, 108 insertions, 6 deletions
diff --git a/README b/README
index 8a75d90da..d64654376 100644
--- a/README
+++ b/README
@@ -261,6 +261,26 @@ markdown test suite, type `make test-markdown`.)
[standard markdown]: http://daringfireball.net/projects/markdown/syntax
+## Section Headings
+
+Pandoc creates an invisible anchor in front of every HTML section
+heading. The ID of this anchor is derived from the section heading
+itself: spaces are converted to underscores, and formatting, links,
+and other markup are removed. Thus, for example, the source
+
+ ## Aristotle's *De Anima*
+
+gets converted to HTML as follows:
+
+ <a id="Aristotle's_De_Anima"></a>
+ <h2>Aristotle's <em>De Anima</em></h2>
+
+This makes it easy to provide internal links that jump to a particular
+place in a document. To provide a link to the heading above, for
+example, just insert:
+
+ [Back to Aristotle](#Aristotle's_De_Anima)
+
## Lists
Pandoc behaves differently from standard markdown on some "edge
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index f1bd0f8b5..7ba506acb 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -154,12 +154,14 @@ blockToHtml options (OrderedList lst) =
let attribs = if (writerIncremental options) then " class=\"incremental\"" else "" in
"<ol" ++ attribs ++ ">\n" ++ (concatMap (listItemToHtml options) lst) ++ "</ol>\n"
blockToHtml options HorizontalRule = "<hr />\n"
-blockToHtml options (Header level lst) = if ((level > 0) && (level <= 6)) then
- "<h" ++ (show level) ++ ">" ++
- (inlineListToHtml options lst) ++
- "</h" ++ (show level) ++ ">\n"
- else
- "<p>" ++ (inlineListToHtml options lst) ++ "</p>\n"
+blockToHtml options (Header level lst) =
+ let contents = inlineListToHtml options lst in
+ let simplify = gsub "<[^>]*>" "" . gsub " " "_" in
+ if ((level > 0) && (level <= 6))
+ then "<a id=\"" ++ simplify contents ++ "\"></a>\n" ++
+ "<h" ++ (show level) ++ ">" ++ contents ++
+ "</h" ++ (show level) ++ ">\n"
+ else "<p>" ++ contents ++ "</p>\n"
listItemToHtml options list = "<li>" ++ (concatMap (blockToHtml options) list) ++ "</li>\n"
-- | Convert list of Pandoc inline elements to HTML.
diff --git a/tests/s5.basic.html b/tests/s5.basic.html
index 919b09da6..88510a74c 100644
--- a/tests/s5.basic.html
+++ b/tests/s5.basic.html
@@ -723,18 +723,24 @@ window.onresize = function(){setTimeout('fontScale()', 50);}</script>
<div id="currentSlide"></div>
<div id="header"></div>
<div id="footer">
+<a id="July_15,_2006"></a>
<h1>July 15, 2006</h1>
+<a id="My_S5_Document"></a>
<h2>My S5 Document</h2>
</div>
</div>
<div class="presentation">
<div class="slide">
+<a id="My_S5_Document"></a>
<h1>My S5 Document</h1>
+<a id="Sam_Smith,_Jen_Jones"></a>
<h3>Sam Smith, Jen Jones</h3>
+<a id="July_15,_2006"></a>
<h4>July 15, 2006</h4>
</div>
<div class="slide">
+<a id="First_slide"></a>
<h1>First slide</h1>
<ul>
<li>first bullet</li>
@@ -742,6 +748,7 @@ window.onresize = function(){setTimeout('fontScale()', 50);}</script>
</ul>
</div>
<div class="slide">
+<a id="Smarty"></a>
<h1>Smarty</h1>
<ul class="incremental">
<li>"Hello there"</li>
@@ -750,6 +757,7 @@ window.onresize = function(){setTimeout('fontScale()', 50);}</script>
</ul>
</div>
<div class="slide">
+<a id="Math"></a>
<h1>Math</h1>
<ul>
<li>$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</li>
diff --git a/tests/s5.fancy.html b/tests/s5.fancy.html
index 8686a8542..e015f7b99 100644
--- a/tests/s5.fancy.html
+++ b/tests/s5.fancy.html
@@ -1635,18 +1635,24 @@ else
<div id="currentSlide"></div>
<div id="header"></div>
<div id="footer">
+<a id="July_15,_2006"></a>
<h1>July 15, 2006</h1>
+<a id="My_S5_Document"></a>
<h2>My S5 Document</h2>
</div>
</div>
<div class="presentation">
<div class="slide">
+<a id="My_S5_Document"></a>
<h1>My S5 Document</h1>
+<a id="Sam_Smith,_Jen_Jones"></a>
<h3>Sam Smith, Jen Jones</h3>
+<a id="July_15,_2006"></a>
<h4>July 15, 2006</h4>
</div>
<div class="slide">
+<a id="First_slide"></a>
<h1>First slide</h1>
<ul class="incremental">
<li>first bullet</li>
@@ -1654,6 +1660,7 @@ else
</ul>
</div>
<div class="slide">
+<a id="Smarty"></a>
<h1>Smarty</h1>
<ul>
<li>&ldquo;Hello there&rdquo;</li>
@@ -1662,6 +1669,7 @@ else
</ul>
</div>
<div class="slide">
+<a id="Math"></a>
<h1>Math</h1>
<ul class="incremental">
<li>$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</li>
diff --git a/tests/s5.fragment.html b/tests/s5.fragment.html
index 370b9c111..240bafb35 100644
--- a/tests/s5.fragment.html
+++ b/tests/s5.fragment.html
@@ -1,8 +1,10 @@
+<a id="First_slide"></a>
<h1>First slide</h1>
<ul>
<li>first bullet</li>
<li>second bullet</li>
</ul>
+<a id="Smarty"></a>
<h1>Smarty</h1>
<blockquote>
<ul>
@@ -11,6 +13,7 @@
<li>And 'ellipses'...</li>
</ul>
</blockquote>
+<a id="Math"></a>
<h1>Math</h1>
<ul>
<li>$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</li>
diff --git a/tests/s5.inserts.html b/tests/s5.inserts.html
index 7be33a2c8..ba6ae5f48 100644
--- a/tests/s5.inserts.html
+++ b/tests/s5.inserts.html
@@ -13,11 +13,13 @@ STUFF INSERTED
<body>
STUFF INSERTED
<h1 class="title">My S5 Document</h1>
+<a id="First_slide"></a>
<h1>First slide</h1>
<ul>
<li>first bullet</li>
<li>second bullet</li>
</ul>
+<a id="Smarty"></a>
<h1>Smarty</h1>
<blockquote>
<ul>
@@ -26,6 +28,7 @@ STUFF INSERTED
<li>And 'ellipses'...</li>
</ul>
</blockquote>
+<a id="Math"></a>
<h1>Math</h1>
<ul>
<li>$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</li>
diff --git a/tests/writer.html b/tests/writer.html
index 6fcb949ec..0661fb732 100644
--- a/tests/writer.html
+++ b/tests/writer.html
@@ -12,18 +12,28 @@
<h1 class="title">Pandoc Test Suite</h1>
<p>This is a set of tests for pandoc. Most of them are adapted from John Gruber's markdown test suite.</p>
<hr />
+<a id="Headers"></a>
<h1>Headers</h1>
+<a id="Level_2_with_an_embedded_link"></a>
<h2>Level 2 with an <a href="/url">embedded link</a></h2>
+<a id="Level_3_with_emphasis"></a>
<h3>Level 3 with <em>emphasis</em></h3>
+<a id="Level_4"></a>
<h4>Level 4</h4>
+<a id="Level_5"></a>
<h5>Level 5</h5>
+<a id="Level_1"></a>
<h1>Level 1</h1>
+<a id="Level_2_with_emphasis"></a>
<h2>Level 2 with <em>emphasis</em></h2>
+<a id="Level_3"></a>
<h3>Level 3</h3>
<p>with no blank line</p>
+<a id="Level_2"></a>
<h2>Level 2</h2>
<p>with no blank line</p>
<hr />
+<a id="Paragraphs"></a>
<h1>Paragraphs</h1>
<p>Here's a regular paragraph.</p>
<p>In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. Because a hard-wrapped line in the middle of a paragraph looked like a list item.</p>
@@ -31,6 +41,7 @@
<p>There should be a hard line break<br />
here.</p>
<hr />
+<a id="Block_Quotes"></a>
<h1>Block Quotes</h1>
<p>E-mail style:</p>
<blockquote>
@@ -79,6 +90,7 @@ here.</p>
</blockquote>
<p>And a following paragraph.</p>
<hr />
+<a id="Code_Blocks"></a>
<h1>Code Blocks</h1>
<p>Code:</p>
<pre><code>---- (should be four hyphens)
@@ -95,7 +107,9 @@ this code block is indented by one tab
These should not be escaped: \$ \\ \> \[ \{
</code></pre>
<hr />
+<a id="Lists"></a>
<h1>Lists</h1>
+<a id="Unordered"></a>
<h2>Unordered</h2>
<p>Asterisks tight:</p>
<ul>
@@ -142,6 +156,7 @@ These should not be escaped: \$ \\ \> \[ \{
<li><p>Minus 3</p>
</li>
</ul>
+<a id="Ordered"></a>
<h2>Ordered</h2>
<p>Tight:</p>
<ol>
@@ -183,6 +198,7 @@ These should not be escaped: \$ \\ \> \[ \{
<li><p>Item 3.</p>
</li>
</ol>
+<a id="Nested"></a>
<h2>Nested</h2>
<ul>
<li>Tab<ul>
@@ -218,6 +234,7 @@ These should not be escaped: \$ \\ \> \[ \{
<li><p>Third</p>
</li>
</ol>
+<a id="Tabs_and_spaces"></a>
<h2>Tabs and spaces</h2>
<ul>
<li><p>this is a list item indented with tabs</p>
@@ -232,6 +249,7 @@ These should not be escaped: \$ \\ \> \[ \{
</li>
</ul>
<hr />
+<a id="HTML_Blocks"></a>
<h1>HTML Blocks</h1>
<p>Simple block on one line:</p>
<div>foo</div>
@@ -307,6 +325,7 @@ Blah
<hr class="foo" id="bar">
<hr />
+<a id="Inline_Markup"></a>
<h1>Inline Markup</h1>
<p>This is <em>emphasized</em>, and so <em>is this</em>.</p>
<p>This is <strong>strong</strong>, and so <strong>is this</strong>.</p>
@@ -317,6 +336,7 @@ Blah
<p>So is <strong><em>this</em></strong> word.</p>
<p>This is code: <code>></code>, <code>$</code>, <code>\</code>, <code>\$</code>, <code>&lt;html></code>.</p>
<hr />
+<a id="Smart_quotes,_ellipses,_dashes"></a>
<h1>Smart quotes, ellipses, dashes</h1>
<p>"Hello," said the spider. "'Shelob' is my name."</p>
<p>'A', 'B', and 'C' are letters.</p>
@@ -327,6 +347,7 @@ Blah
<p>Dashes between numbers: 5-7, 255-66, 1987-1999.</p>
<p>Ellipses...and. . .and . . . .</p>
<hr />
+<a id="LaTeX"></a>
<h1>LaTeX</h1>
<ul>
<li>\cite[22-23]{smith.1899}</li>
@@ -352,6 +373,7 @@ Dog &amp; 2 \\
Cat &amp; 1 \\ \hline
\end{tabular}</p>
<hr />
+<a id="Special_Characters"></a>
<h1>Special Characters</h1>
<p>Here is some unicode:</p>
<ul>
@@ -383,7 +405,9 @@ Cat &amp; 1 \\ \hline
<p>Plus: +</p>
<p>Minus: -</p>
<hr />
+<a id="Links"></a>
<h1>Links</h1>
+<a id="Explicit"></a>
<h2>Explicit</h2>
<p>Just a <a href="/url/">URL</a>.</p>
<p><a href="/url/" title="title">URL and title</a>.</p>
@@ -393,6 +417,7 @@ Cat &amp; 1 \\ \hline
<p><a href="/url/" title="title with single quotes">URL and title</a></p>
<p><script type="text/javascript">h='nowhere.net';n='nobody';e=n+'@'+h;document.write('<a href="mailto:'+e+'">'+'Email link'+'<\/a>');</script><noscript>Email link (nobody [at] nowhere.net)</noscript></p>
<p><a href="">Empty</a>.</p>
+<a id="Reference"></a>
<h2>Reference</h2>
<p>Foo <a href="/url/">bar</a>.</p>
<p>Foo <a href="/url/">bar</a>.</p>
@@ -407,11 +432,13 @@ Cat &amp; 1 \\ \hline
</code></pre>
<p>Foo <a href="/url/" title="Title with &quot;quotes&quot; inside">bar</a>.</p>
<p>Foo <a href="/url/" title="Title with &quot;quote&quot; inside">biz</a>.</p>
+<a id="With_ampersands"></a>
<h2>With ampersands</h2>
<p>Here's a <a href="http://example.com/?foo=1&amp;bar=2">link with an ampersand in the URL</a>.</p>
<p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&amp;T</a>.</p>
<p>Here's an <a href="/script?foo=1&amp;bar=2">inline link</a>.</p>
<p>Here's an <a href="/script?foo=1&amp;bar=2">inline link in pointy braces</a>.</p>
+<a id="Autolinks"></a>
<h2>Autolinks</h2>
<p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a></p>
<ul>
@@ -427,11 +454,13 @@ Cat &amp; 1 \\ \hline
<pre><code>or here: &lt;http://example.com/>
</code></pre>
<hr />
+<a id="Images"></a>
<h1>Images</h1>
<p>From "Voyage dans la Lune" by Georges Melies (1902):</p>
<p><img src="lalune.jpg" title="Voyage dans la Lune" alt="lalune"></p>
<p>Here is a movie <img src="movie.jpg" alt="movie"> icon.</p>
<hr />
+<a id="Footnotes"></a>
<h1>Footnotes</h1>
<p>Here is a footnote reference,<sup class="footnoteRef" id="fnref1"><a href="#fn1">1</a></sup> and another.<sup class="footnoteRef" id="fnref2"><a href="#fn2">2</a></sup> This should <em>not</em> be a footnote reference, because it contains a space.[^my note] Here is an inline note.<sup class="footnoteRef" id="fnref3"><a href="#fn3">3</a></sup></p>
<p>This paragraph should not be part of the note, as it is not indented.</p>
diff --git a/tests/writer.smart.html b/tests/writer.smart.html
index 508b0abf5..d5fb3da93 100644
--- a/tests/writer.smart.html
+++ b/tests/writer.smart.html
@@ -12,18 +12,28 @@
<h1 class="title">Pandoc Test Suite</h1>
<p>This is a set of tests for pandoc. Most of them are adapted from John Gruber&rsquo;s markdown test suite.</p>
<hr />
+<a id="Headers"></a>
<h1>Headers</h1>
+<a id="Level_2_with_an_embedded_link"></a>
<h2>Level 2 with an <a href="/url">embedded link</a></h2>
+<a id="Level_3_with_emphasis"></a>
<h3>Level 3 with <em>emphasis</em></h3>
+<a id="Level_4"></a>
<h4>Level 4</h4>
+<a id="Level_5"></a>
<h5>Level 5</h5>
+<a id="Level_1"></a>
<h1>Level 1</h1>
+<a id="Level_2_with_emphasis"></a>
<h2>Level 2 with <em>emphasis</em></h2>
+<a id="Level_3"></a>
<h3>Level 3</h3>
<p>with no blank line</p>
+<a id="Level_2"></a>
<h2>Level 2</h2>
<p>with no blank line</p>
<hr />
+<a id="Paragraphs"></a>
<h1>Paragraphs</h1>
<p>Here&rsquo;s a regular paragraph.</p>
<p>In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. Because a hard-wrapped line in the middle of a paragraph looked like a list item.</p>
@@ -31,6 +41,7 @@
<p>There should be a hard line break<br />
here.</p>
<hr />
+<a id="Block_Quotes"></a>
<h1>Block Quotes</h1>
<p>E-mail style:</p>
<blockquote>
@@ -79,6 +90,7 @@ here.</p>
</blockquote>
<p>And a following paragraph.</p>
<hr />
+<a id="Code_Blocks"></a>
<h1>Code Blocks</h1>
<p>Code:</p>
<pre><code>---- (should be four hyphens)
@@ -95,7 +107,9 @@ this code block is indented by one tab
These should not be escaped: \$ \\ \> \[ \{
</code></pre>
<hr />
+<a id="Lists"></a>
<h1>Lists</h1>
+<a id="Unordered"></a>
<h2>Unordered</h2>
<p>Asterisks tight:</p>
<ul>
@@ -142,6 +156,7 @@ These should not be escaped: \$ \\ \> \[ \{
<li><p>Minus 3</p>
</li>
</ul>
+<a id="Ordered"></a>
<h2>Ordered</h2>
<p>Tight:</p>
<ol>
@@ -183,6 +198,7 @@ These should not be escaped: \$ \\ \> \[ \{
<li><p>Item 3.</p>
</li>
</ol>
+<a id="Nested"></a>
<h2>Nested</h2>
<ul>
<li>Tab<ul>
@@ -218,6 +234,7 @@ These should not be escaped: \$ \\ \> \[ \{
<li><p>Third</p>
</li>
</ol>
+<a id="Tabs_and_spaces"></a>
<h2>Tabs and spaces</h2>
<ul>
<li><p>this is a list item indented with tabs</p>
@@ -232,6 +249,7 @@ These should not be escaped: \$ \\ \> \[ \{
</li>
</ul>
<hr />
+<a id="HTML_Blocks"></a>
<h1>HTML Blocks</h1>
<p>Simple block on one line:</p>
<div>foo</div>
@@ -307,6 +325,7 @@ Blah
<hr class="foo" id="bar">
<hr />
+<a id="Inline_Markup"></a>
<h1>Inline Markup</h1>
<p>This is <em>emphasized</em>, and so <em>is this</em>.</p>
<p>This is <strong>strong</strong>, and so <strong>is this</strong>.</p>
@@ -317,6 +336,7 @@ Blah
<p>So is <strong><em>this</em></strong> word.</p>
<p>This is code: <code>></code>, <code>$</code>, <code>\</code>, <code>\$</code>, <code>&lt;html></code>.</p>
<hr />
+<a id="Smart_quotes,_ellipses,_dashes"></a>
<h1>Smart quotes, ellipses, dashes</h1>
<p>&ldquo;Hello,&rdquo; said the spider. &ldquo;&lsquo;Shelob&rsquo; is my name.&rdquo;</p>
<p>&lsquo;A&rsquo;, &lsquo;B&rsquo;, and &lsquo;C&rsquo; are letters.</p>
@@ -327,6 +347,7 @@ Blah
<p>Dashes between numbers: 5&ndash;7, 255&ndash;66, 1987&ndash;1999.</p>
<p>Ellipses&hellip;and&hellip;and &hellip; .</p>
<hr />
+<a id="LaTeX"></a>
<h1>LaTeX</h1>
<ul>
<li>\cite[22-23]{smith.1899}</li>
@@ -352,6 +373,7 @@ Dog &amp; 2 \\
Cat &amp; 1 \\ \hline
\end{tabular}</p>
<hr />
+<a id="Special_Characters"></a>
<h1>Special Characters</h1>
<p>Here is some unicode:</p>
<ul>
@@ -383,7 +405,9 @@ Cat &amp; 1 \\ \hline
<p>Plus: +</p>
<p>Minus: -</p>
<hr />
+<a id="Links"></a>
<h1>Links</h1>
+<a id="Explicit"></a>
<h2>Explicit</h2>
<p>Just a <a href="/url/">URL</a>.</p>
<p><a href="/url/" title="title">URL and title</a>.</p>
@@ -393,6 +417,7 @@ Cat &amp; 1 \\ \hline
<p><a href="/url/" title="title with single quotes">URL and title</a></p>
<p><script type="text/javascript">h='nowhere.net';n='nobody';e=n+'@'+h;document.write('<a href="mailto:'+e+'">'+'Email link'+'<\/a>');</script><noscript>Email link (nobody [at] nowhere.net)</noscript></p>
<p><a href="">Empty</a>.</p>
+<a id="Reference"></a>
<h2>Reference</h2>
<p>Foo <a href="/url/">bar</a>.</p>
<p>Foo <a href="/url/">bar</a>.</p>
@@ -407,11 +432,13 @@ Cat &amp; 1 \\ \hline
</code></pre>
<p>Foo <a href="/url/" title="Title with &quot;quotes&quot; inside">bar</a>.</p>
<p>Foo <a href="/url/" title="Title with &quot;quote&quot; inside">biz</a>.</p>
+<a id="With_ampersands"></a>
<h2>With ampersands</h2>
<p>Here&rsquo;s a <a href="http://example.com/?foo=1&amp;bar=2">link with an ampersand in the URL</a>.</p>
<p>Here&rsquo;s a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&amp;T</a>.</p>
<p>Here&rsquo;s an <a href="/script?foo=1&amp;bar=2">inline link</a>.</p>
<p>Here&rsquo;s an <a href="/script?foo=1&amp;bar=2">inline link in pointy braces</a>.</p>
+<a id="Autolinks"></a>
<h2>Autolinks</h2>
<p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a></p>
<ul>
@@ -427,11 +454,13 @@ Cat &amp; 1 \\ \hline
<pre><code>or here: &lt;http://example.com/>
</code></pre>
<hr />
+<a id="Images"></a>
<h1>Images</h1>
<p>From &ldquo;Voyage dans la Lune&rdquo; by Georges Melies (1902):</p>
<p><img src="lalune.jpg" title="Voyage dans la Lune" alt="lalune"></p>
<p>Here is a movie <img src="movie.jpg" alt="movie"> icon.</p>
<hr />
+<a id="Footnotes"></a>
<h1>Footnotes</h1>
<p>Here is a footnote reference,<sup class="footnoteRef" id="fnref1"><a href="#fn1">1</a></sup> and another.<sup class="footnoteRef" id="fnref2"><a href="#fn2">2</a></sup> This should <em>not</em> be a footnote reference, because it contains a space.[^my note] Here is an inline note.<sup class="footnoteRef" id="fnref3"><a href="#fn3">3</a></sup></p>
<p>This paragraph should not be part of the note, as it is not indented.</p>