@@ -19,26 +19,6 @@ marked.Lexer.prototype.lex = function lex(src) {
1919} ;
2020
2121const renderer = new marked . Renderer ( ) ;
22- renderer . heading = ( text , level ) => {
23- // Small title. No need for an anchor.
24- // It's reducing the risk of duplicated id and it's fewer elements in the DOM.
25- if ( level >= 4 ) {
26- return `<h${ level } >${ text } </h${ level } >` ;
27- }
28-
29- // eslint-disable-next-line no-underscore-dangle
30- const hash = textToHash ( text , global . __MARKED_UNIQUE__ ) ;
31-
32- return [
33- `<h${ level } >` ,
34- `<a class="anchor-link" id="${ hash } "></a>` ,
35- text ,
36- `<a class="anchor-link-style" aria-hidden="true" aria-label="anchor" href="#${ hash } ">` ,
37- '<svg><use xlink:href="#anchor-link-icon" /></svg>' ,
38- '</a>' ,
39- `</h${ level } >` ,
40- ] . join ( '' ) ;
41- } ;
4222
4323const externs = [
4424 'https://material.io/' ,
@@ -304,6 +284,28 @@ function MarkdownElement(props) {
304284 // eslint-disable-next-line no-underscore-dangle
305285 global . __MARKED_USER_LANGUAGE__ = userLanguage ;
306286
287+ // need to reset on every render to make textToHash concurrent-safe
288+ const headingIdCache = { } ;
289+ renderer . heading = ( headingText , level ) => {
290+ // Small title. No need for an anchor.
291+ // It's reducing the risk of duplicated id and it's fewer elements in the DOM.
292+ if ( level >= 4 ) {
293+ return `<h${ level } >${ headingText } </h${ level } >` ;
294+ }
295+
296+ const hash = textToHash ( headingText , headingIdCache ) ;
297+
298+ return [
299+ `<h${ level } >` ,
300+ `<a class="anchor-link" id="${ hash } "></a>` ,
301+ headingText ,
302+ `<a class="anchor-link-style" aria-hidden="true" aria-label="anchor" href="#${ hash } ">` ,
303+ '<svg><use xlink:href="#anchor-link-icon" /></svg>' ,
304+ '</a>' ,
305+ `</h${ level } >` ,
306+ ] . join ( '' ) ;
307+ } ;
308+
307309 /* eslint-disable react/no-danger */
308310 return (
309311 < div
0 commit comments