Skip to content

Commit 78c1654

Browse files
committed
[docs] Fix emojis/html being included in toc
1 parent ed0f93e commit 78c1654

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

docs/src/modules/utils/parseMarkdown.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,20 @@ ${headers.components
172172

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

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

184191
/**
@@ -207,7 +214,7 @@ ${headers.components
207214
return [
208215
`<h${level}>`,
209216
`<a class="anchor-link" id="${hash}"></a>`,
210-
headingText,
217+
headingHtml,
211218
`<a class="anchor-link-style" aria-hidden="true" aria-label="anchor" href="#${hash}">`,
212219
'<svg><use xlink:href="#anchor-link-icon" /></svg>',
213220
'</a>',

0 commit comments

Comments
 (0)