Skip to content

Commit

Permalink
add html test to heading ids
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Mar 20, 2020
1 parent f01ba94 commit 7330a9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Slugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = class Slugger {
let slug = value
.toLowerCase()
.trim()
// remove html tags
.replace(/<!?\/?[\w-]+(?: .*)?\/?>/g, '')
// remove unwanted chars
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
.replace(/\s/g, '-');

Expand Down
4 changes: 3 additions & 1 deletion test/specs/new/headings_id.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h3 id="heading-with-html">Heading with <em>html</em></h3>

<h3 id="heading-with-a-link">Heading with a <a href="http://github.com/">link</a></h3>

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

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

<h2 id="and-a-ref-link">And a ref <a href="/some/url" title="link to nowhere">link</a></h2>
<h2 id="and-a-ref-link">And a ref <a href="/some/url" title="link to nowhere">link</a></h2>
4 changes: 3 additions & 1 deletion test/specs/new/headings_id.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Heading with <em>html</em>

### Heading with a [link](http://github.com/)

### Heading with some _italic text_
Expand All @@ -11,4 +13,4 @@

## And a ref [link][destination]

[destination]: /some/url "link to nowhere"
[destination]: /some/url "link to nowhere"

0 comments on commit 7330a9c

Please sign in to comment.