mirror of
https://github.com/fverdugo/XM_40017.git
synced 2025-12-29 10:18:31 +01:00
build based on e6474b1
This commit is contained in:
@@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user