Skip to content

Commit 7330a9c

Browse files
committed
add html test to heading ids
1 parent f01ba94 commit 7330a9c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/Slugger.js

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ module.exports = class Slugger {
1313
let slug = value
1414
.toLowerCase()
1515
.trim()
16+
// remove html tags
17+
.replace(/<!?\/?[\w-]+(?: .*)?\/?>/g, '')
18+
// remove unwanted chars
1619
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
1720
.replace(/\s/g, '-');
1821

test/specs/new/headings_id.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<h3 id="heading-with-html">Heading with <em>html</em></h3>
2+
13
<h3 id="heading-with-a-link">Heading with a <a href="http://github.com/">link</a></h3>
24

35
<h3 id="heading-with-some-italic-text">Heading with some <em>italic text</em></h3>
@@ -10,4 +12,4 @@ <h3 id="or-even-code">Or even <code>code</code></h3>
1012

1113
<h3 id="what-about-strikethrough">What about <del>strikethrough</del></h3>
1214

13-
<h2 id="and-a-ref-link">And a ref <a href="/some/url" title="link to nowhere">link</a></h2>
15+
<h2 id="and-a-ref-link">And a ref <a href="/some/url" title="link to nowhere">link</a></h2>

test/specs/new/headings_id.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### Heading with <em>html</em>
2+
13
### Heading with a [link](http://github.com/)
24

35
### Heading with some _italic text_
@@ -11,4 +13,4 @@
1113

1214
## And a ref [link][destination]
1315

14-
[destination]: /some/url "link to nowhere"
16+
[destination]: /some/url "link to nowhere"

0 commit comments

Comments
 (0)