Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add html test to heading ids
  • Loading branch information
UziTech committed Mar 20, 2020
commit 7330a9ca3d3b1d6de8730953beb0777f43beedec
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"