Skip to content

Commit 58e9fed

Browse files
authored
Merge pull request #1622 from UziTech/render-html
Render html in heading
2 parents cf3d0a0 + 193a41e commit 58e9fed

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/Slugger.js

Lines changed: 3 additions & 0 deletions
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(/<[!\/a-z].*?>/ig, '')
18+
// remove unwanted chars
1619
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
1720
.replace(/\s/g, '-');
1821

src/TextRenderer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module.exports = class TextRenderer {
2020
return text;
2121
}
2222

23+
html(text) {
24+
return text;
25+
}
26+
2327
text(text) {
2428
return text;
2529
}

test/specs/new/headings_id.html

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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)