Skip to content

Commit

Permalink
Fix issue hoedown#125: Don't escape HTML tags in tables of contents.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stevewolter committed Dec 1, 2014
1 parent 3afc3ec commit 737304d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ toc_header(hoedown_buffer *ob, const hoedown_buffer *content, int level, const h
}

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

NULL,
NULL,
rndr_normal_text,

NULL,
toc_finalize
Expand Down
15 changes: 15 additions & 0 deletions test/MarkdownTest_1.0.3/Tests/Formatting in Table of Contents.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ul>
<li>
<a href="#toc_0">Header with special &amp; characters</a>
<ul>
<li>
<a href="#toc_1">With <code>Code</code></a>
<ul>
<li>
<a href="#toc_2">With <em>Emphasis</em></a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Header with special & characters

## With `Code`

### With *Emphasis*
5 changes: 5 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"input": "MarkdownTest_1.0.3/Tests/Code Spans.text",
"output": "MarkdownTest_1.0.3/Tests/Code Spans.html"
},
{
"input": "MarkdownTest_1.0.3/Tests/Formatting in Table of Contents.text",
"output": "MarkdownTest_1.0.3/Tests/Formatting in Table of Contents.html",
"flags": ["--html-toc", "-t", "3"]
},
{
"input": "MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.text",
"output": "MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.html"
Expand Down

0 comments on commit 737304d

Please sign in to comment.