diff --git a/lib/utils.js b/lib/utils.js index 16125e2..2722033 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -59,6 +59,7 @@ utils.slugify = function(str, options) { str = str.toLowerCase(); // `.split()` is often (but not always) faster than `.replace()` + str = str.split(/&[^;]+;/).join('') str = str.split(' ').join('-'); str = str.split(/\t/).join('--'); if (options.stripHeadingTags !== false) { diff --git a/test/test.js b/test/test.js index e93e41b..a0b8379 100644 --- a/test/test.js +++ b/test/test.js @@ -426,4 +426,8 @@ describe('toc.insert', function() { assert.equal(strip(toc.insert(str, { linkify: true })), read('test/expected/insert.md')); assert.equal(strip(toc.insert(str, { linkify: false })), read('test/expected/insert-no-links.md')); }); + + it('should strip HTML entities from slugs', function() { + assert.equal(toc('# <div> elements').content, '- [<div> elements](#div-elements)'); + }) });