From 8d21a9f8d3796665a808584dde09db5b1d2c7787 Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Fri, 7 Feb 2020 00:43:58 -0600 Subject: [PATCH] fix: strip HTML entities like > from slugs --- lib/utils.js | 1 + test/test.js | 4 ++++ 2 files changed, 5 insertions(+) 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)'); + }) });