Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render html in heading #1622

Merged
merged 3 commits into from Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Slugger.js
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
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
@@ -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
@@ -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"