File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,18 @@ import {useEffect} from 'react';
44export default function Mermaid ( ) {
55 useEffect ( ( ) => {
66 ( async function ( ) {
7+ const escapeHTML = ( str ) => {
8+ return str . replace ( / [ & < > " ' ] / g, function ( match ) {
9+ const escapeMap = {
10+ '&' : '&' ,
11+ '<' : '<' ,
12+ '>' : '>' ,
13+ '"' : '"' ,
14+ "'" : '''
15+ } ;
16+ return escapeMap [ match ] ;
17+ } ) ;
18+ } ;
719 const mermaidBlocks =
820 document . querySelectorAll < HTMLDivElement > ( '.language-mermaid' ) ;
921 if ( mermaidBlocks . length === 0 ) {
@@ -14,7 +26,7 @@ export default function Mermaid() {
1426 mermaidBlocks . forEach ( block => {
1527 // get rid of code highlighting
1628 const code = block . textContent ?? '' ;
17- block . innerHTML = code ;
29+ block . innerHTML = escapeHTML ( code ) ;
1830 // force transparent background
1931 block . style . backgroundColor = 'transparent' ;
2032 const parentCodeTabs = block . closest ( '.code-tabs-wrapper' ) ;
You can’t perform that action at this time.
0 commit comments