Skip to content

Commit

Permalink
[docs] Fix emojis/html being included in toc
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 29, 2020
1 parent ed0f93e commit 78c1654
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docs/src/modules/utils/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,20 @@ ${headers.components

return render(content, {
highlight: prism,
heading: (headingText, level) => {
heading: (headingHtml, level) => {
// Small title. No need for an anchor.
// It's reducing the risk of duplicated id and it's fewer elements in the DOM.
if (level >= 4) {
return `<h${level}>${headingText}</h${level}>`;
return `<h${level}>${headingHtml}</h${level}>`;
}

const headingText = headingHtml
.replace(
/([\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,
'',
) // remove emojis
.replace(/<\/?[^>]+(>|$)/g, '') // remove HTML
.trim();
const hash = textToHash(headingText, headingHashes);

/**
Expand Down Expand Up @@ -207,7 +214,7 @@ ${headers.components
return [
`<h${level}>`,
`<a class="anchor-link" id="${hash}"></a>`,
headingText,
headingHtml,
`<a class="anchor-link-style" aria-hidden="true" aria-label="anchor" href="#${hash}">`,
'<svg><use xlink:href="#anchor-link-icon" /></svg>',
'</a>',
Expand Down

0 comments on commit 78c1654

Please sign in to comment.