Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit af4b00c

Browse files
techknowlogicksilverwind
andauthoredMar 4, 2023
update to mermaid v10 (#23178)
fix #23153 --------- Co-authored-by: silverwind <[email protected]>
1 parent 787a05a commit af4b00c

File tree

4 files changed

+233
-68
lines changed

4 files changed

+233
-68
lines changed
 

‎package-lock.json

Lines changed: 211 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"less": "4.1.3",
3232
"less-loader": "11.1.0",
3333
"license-checker-webpack-plugin": "0.2.1",
34-
"mermaid": "9.3.0",
34+
"mermaid": "10.0.2",
3535
"mini-css-extract-plugin": "2.7.2",
3636
"monaco-editor": "0.34.1",
3737
"monaco-editor-webpack-plugin": "7.0.1",

‎web_src/js/markup/mermaid.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,36 @@ export async function renderMermaid() {
3737
continue;
3838
}
3939

40-
let valid;
4140
try {
42-
valid = mermaid.parse(source);
41+
await mermaid.parse(source);
4342
} catch (err) {
4443
displayError(el, err);
45-
}
46-
47-
if (!valid) {
4844
el.closest('pre').classList.remove('is-loading');
4945
continue;
5046
}
5147

5248
try {
5349
// can't use bindFunctions here because we can't cross the iframe boundary. This
5450
// means js-based interactions won't work but they aren't intended to work either
55-
mermaid.mermaidAPI.render('mermaid', source, (svgStr) => {
56-
const heightStr = (svgStr.match(/viewBox="(.+?)"/) || ['', ''])[1].split(/\s+/)[3];
57-
if (!heightStr) return displayError(el, new Error('Could not determine chart height'));
58-
const iframe = document.createElement('iframe');
59-
iframe.classList.add('markup-render');
60-
iframe.sandbox = 'allow-scripts';
61-
iframe.style.height = `${Math.ceil(parseFloat(heightStr))}px`;
62-
iframe.srcdoc = `<html><head><style>${iframeCss}</style></head><body>${svgStr}</body></html>`;
63-
const mermaidBlock = document.createElement('div');
64-
mermaidBlock.classList.add('mermaid-block');
65-
mermaidBlock.append(iframe);
66-
const btn = makeCodeCopyButton();
67-
btn.setAttribute('data-clipboard-text', source);
68-
mermaidBlock.append(btn);
69-
el.closest('pre').replaceWith(mermaidBlock);
70-
});
51+
const {svg} = await mermaid.render('mermaid', source);
52+
const heightStr = (svg.match(/viewBox="(.+?)"/) || ['', ''])[1].split(/\s+/)[3];
53+
if (!heightStr) return displayError(el, new Error('Could not determine chart height'));
54+
55+
const iframe = document.createElement('iframe');
56+
iframe.classList.add('markup-render');
57+
iframe.sandbox = 'allow-scripts';
58+
iframe.style.height = `${Math.ceil(parseFloat(heightStr))}px`;
59+
iframe.srcdoc = `<html><head><style>${iframeCss}</style></head><body>${svg}</body></html>`;
60+
61+
const mermaidBlock = document.createElement('div');
62+
mermaidBlock.classList.add('mermaid-block');
63+
mermaidBlock.append(iframe);
64+
65+
const btn = makeCodeCopyButton();
66+
btn.setAttribute('data-clipboard-text', source);
67+
68+
mermaidBlock.append(btn);
69+
el.closest('pre').replaceWith(mermaidBlock);
7170
} catch (err) {
7271
displayError(el, err);
7372
}

‎webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default {
234234
'khroma@*': {licenseName: 'MIT'}, // https://github.com/fabiospampinato/khroma/pull/33
235235
},
236236
emitError: true,
237-
allow: '(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT OR ISC OR CPAL-1.0 OR Unlicense)',
237+
allow: '(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT OR ISC OR CPAL-1.0 OR Unlicense OR EPL-1.0 OR EPL-2.0)',
238238
ignore: [
239239
'font-awesome',
240240
],

0 commit comments

Comments
 (0)
Please sign in to comment.