Skip to content

Commit

Permalink
fix(toc): title should escape html entities
Browse files Browse the repository at this point in the history
Fixes #2198, Closes #2437
  • Loading branch information
JLHwung committed Dec 1, 2017
1 parent 50b5eb9 commit d0e01f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/helper/toc.js
Expand Up @@ -25,7 +25,7 @@ function tocHelper(str, options) {
headings.each(function() {
var level = +this.name[1];
var id = $(this).attr('id');
var text = $(this).text();
var text = $(this).html();

lastNumber[level - 1]++;

Expand Down
9 changes: 8 additions & 1 deletion test/scripts/helpers/toc.js
Expand Up @@ -16,7 +16,8 @@ describe('toc', () => {
'<h2 id="title_1_3">Title 1.3</h2>',
'<h3 id="title_1_3_1">Title 1.3.1</h3>',
'<h1 id="title_2">Title 2</h1>',
'<h2 id="title_2_1">Title 2.1</h2>'
'<h2 id="title_2_1">Title 2.1</h2>',
'<h1 id="title_3">Title should escape &amp;, &lt;, &apos;, and &quot;</h1>'
].join('');

var genResult = options => {
Expand Down Expand Up @@ -102,6 +103,12 @@ describe('toc', () => {
'<span class="' + className + '-text">Title 2</span>',
'</a>',
ifTrue(maxDepth >= 2, resultTitle_2_1, ''),
'</li>',
'<li class="' + className + '-item ' + className + '-level-1">',
'<a class="' + className + '-link" href="#title_3">',
ifTrue(listNumber, '<span class="' + className + '-number">3.</span> ', ''),
'<span class="' + className + '-text">Title should escape &amp;, &lt;, &apos;, and &quot;</span>',
'</a>',
'</li>'
].join('');

Expand Down

0 comments on commit d0e01f5

Please sign in to comment.