diff --git a/packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts b/packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts index 30f044d9881..643ce395e91 100644 --- a/packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts +++ b/packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts @@ -18,20 +18,7 @@ const MermaidExample = async (md: MarkdownRenderer) => { 'Missing MarkdownIt highlight function (should be automatically created by vitepress' ); } - - // doing ```mermaid-example {line-numbers=5 highlight=14-17} is not supported - const langAttrs = ''; - return ` -
Code:
-
- - mermaid - ${ - // html is pre-escaped by the highlight function - // (it also adds `v-pre` to ignore Vue template syntax) - md.options.highlight(token.content, 'mermaid', langAttrs) - } -
`; + return ''; } else if (token.info.trim() === 'mermaid') { const key = index; return ` diff --git a/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue b/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue index 5012d30679d..30d474fda04 100644 --- a/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue +++ b/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue @@ -1,4 +1,11 @@ @@ -18,15 +25,21 @@ const props = defineProps({ }); const svg = ref(''); +const code = ref(decodeURIComponent(props.graph)); + let mut = null; +const updateCode = (event) => { + code.value = event.target.innerText; +}; + onMounted(async () => { mut = new MutationObserver(() => renderChart()); mut.observe(document.documentElement, { attributes: true }); await renderChart(); //refresh images on first render - const hasImages = //.exec(decodeURIComponent(props.graph))?.length > 0; + const hasImages = //.exec(code.value)?.length > 0; if (hasImages) setTimeout(() => { let imgElements = document.getElementsByTagName('img'); @@ -51,16 +64,14 @@ onMounted(async () => { onUnmounted(() => mut.disconnect()); const renderChart = async () => { - console.log('rendering chart' + props.id + props.graph); + console.log('rendering chart' + props.id + code.value); const hasDarkClass = document.documentElement.classList.contains('dark'); const mermaidConfig = { securityLevel: 'loose', startOnLoad: false, theme: hasDarkClass ? 'dark' : 'default', }; - - console.log({ mermaidConfig }); - let svgCode = await render(props.id, decodeURIComponent(props.graph), mermaidConfig); + let svgCode = await render(props.id, code.value, mermaidConfig); // This is a hack to force v-html to re-render, otherwise the diagram disappears // when **switching themes** or **reloading the page**. // The cause is that the diagram is deleted during rendering (out of Vue's knowledge). @@ -70,3 +81,27 @@ const renderChart = async () => { svg.value = `${svgCode} ${salt}`; }; + +