diff --git a/docs/index.html b/docs/index.html index 422dd7b..728ff7b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1400,6 +1400,7 @@
([\s\S]*?)<\/code><\/pre>/g,
(match, code) => {
- const decodedCode = code
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/&/g, '&')
- .replace(/"/g, '"')
- .replace(/'/g, "'");
- return `${decodedCode}`;
+ // Keep the code HTML-escaped. The browser decodes entities when
+ // renderMermaidDiagrams() reads element.textContent, so no manual
+ // unescaping (and no injection of raw markup) is needed here.
+ return `${code}`;
}
);
@@ -1599,13 +1597,20 @@ Generation Info
const element = mermaidElements[i];
const id = `mermaid-${Date.now()}-${i}`;
element.id = id;
+ // Capture the source up front: on a syntax error mermaid.run() has already
+ // replaced the node's contents with its own error SVG before it throws.
+ const source = element.textContent;
try {
- const { svg } = await mermaid.render(id + '-svg', element.textContent);
- element.innerHTML = svg;
+ // mermaid.run() reads the (still HTML-escaped) diagram source from the
+ // node and writes the sanitised SVG back itself (securityLevel: 'strict'),
+ // so this page never re-parses DOM text as HTML.
+ await mermaid.run({ nodes: [element] });
} catch (error) {
console.error('Mermaid rendering error:', error);
- element.innerHTML = `Error rendering diagram:\n${element.textContent}`;
+ const pre = document.createElement('pre');
+ pre.textContent = `Error rendering diagram:\n${source}`;
+ element.replaceChildren(pre);
}
}
}
@@ -1616,12 +1621,14 @@ Generation Info
loading.style.display = 'none';
content.style.display = 'block';
- content.innerHTML = `
-
- ⚠️ Error
- ${message}
-
- `;
+ const box = document.createElement('div');
+ box.className = 'error';
+ const title = document.createElement('h3');
+ title.textContent = '⚠️ Error';
+ const text = document.createElement('p');
+ text.textContent = message;
+ box.append(title, text);
+ content.replaceChildren(box);
}