Skip to content

Commit 737304d

Browse files
committed
Fix issue hoedown#125: Don't escape HTML tags in tables of contents.
Before this patch, a header like "# *A*" was displayed as "<li>&lt;em&gtA&lt;/em&gt;</li>" in the TOC. The error was caused by toc_header doing the HTML escaping. In the normal HTML renderer, the escaping is done by the normal_text hook. This patch uses the same handling to fix the issue.
1 parent 3afc3ec commit 737304d

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/html.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ toc_header(hoedown_buffer *ob, const hoedown_buffer *content, int level, const h
586586
}
587587

588588
hoedown_buffer_printf(ob, "<a href=\"#toc_%d\">", state->toc_data.header_count++);
589-
if (content) escape_html(ob, content->data, content->size);
589+
if (content) hoedown_buffer_put(ob, content->data, content->size);
590590
HOEDOWN_BUFPUTSL(ob, "</a>\n");
591591
}
592592
}
@@ -654,7 +654,7 @@ hoedown_html_toc_renderer_new(int nesting_level)
654654
NULL,
655655

656656
NULL,
657-
NULL,
657+
rndr_normal_text,
658658

659659
NULL,
660660
toc_finalize
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<ul>
2+
<li>
3+
<a href="#toc_0">Header with special &amp; characters</a>
4+
<ul>
5+
<li>
6+
<a href="#toc_1">With <code>Code</code></a>
7+
<ul>
8+
<li>
9+
<a href="#toc_2">With <em>Emphasis</em></a>
10+
</li>
11+
</ul>
12+
</li>
13+
</ul>
14+
</li>
15+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Header with special & characters
2+
3+
## With `Code`
4+
5+
### With *Emphasis*

test/config.json

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"input": "MarkdownTest_1.0.3/Tests/Code Spans.text",
2525
"output": "MarkdownTest_1.0.3/Tests/Code Spans.html"
2626
},
27+
{
28+
"input": "MarkdownTest_1.0.3/Tests/Formatting in Table of Contents.text",
29+
"output": "MarkdownTest_1.0.3/Tests/Formatting in Table of Contents.html",
30+
"flags": ["--html-toc", "-t", "3"]
31+
},
2732
{
2833
"input": "MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.text",
2934
"output": "MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.html"

0 commit comments

Comments
 (0)