Skip to content

Commit

Permalink
Merge pull request #1622 from UziTech/render-html
Browse files Browse the repository at this point in the history
Render html in heading
  • Loading branch information
UziTech authored Mar 22, 2020
2 parents cf3d0a0 + 193a41e commit 58e9fed
Show file tree
Hide file tree
Showing 4 changed files with 13 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(/<[!\/a-z].*?>/ig, '')
// remove unwanted chars
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
.replace(/\s/g, '-');

Expand Down
4 changes: 4 additions & 0 deletions src/TextRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module.exports = class TextRenderer {
return text;
}

html(text) {
return text;
}

text(text) {
return text;
}
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"

1 comment on commit 58e9fed

@vercel
Copy link

@vercel vercel bot commented on 58e9fed Mar 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.