diff --git a/packages/mermaid/scripts/docs.mts b/packages/mermaid/scripts/docs.mts
index 42e299c54..31d2a7c8f 100644
--- a/packages/mermaid/scripts/docs.mts
+++ b/packages/mermaid/scripts/docs.mts
@@ -252,11 +252,12 @@ export function transformMarkdownAst({
node.lang = MERMAID_KEYWORD;
return [node];
} else if (MERMAID_EXAMPLE_KEYWORDS.includes(node.lang)) {
- // Return 2 nodes:
+ // If Vitepress, return only the original node with the language now set to 'mermaid-example' (will be rendered using custom renderer)
+ // Else Return 2 nodes:
// 1. the original node with the language now set to 'mermaid-example' (will be rendered as code), and
// 2. a copy of the original node with the language set to 'mermaid' (will be rendered as a diagram)
node.lang = MERMAID_CODE_ONLY_KEYWORD;
- return [node, Object.assign({}, node, { lang: MERMAID_KEYWORD })];
+ return vitepress ? [node] : [node, Object.assign({}, node, { lang: MERMAID_KEYWORD })];
}
// Transform these blocks into block quotes.
diff --git a/packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts b/packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts
index 643ce395e..64a069b4c 100644
--- a/packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts
+++ b/packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts
@@ -9,22 +9,15 @@ const MermaidExample = async (md: MarkdownRenderer) => {
md.renderer.rules.fence = (tokens, index, options, env, slf) => {
const token = tokens[index];
-
- if (token.info.trim() === 'mermaid-example') {
- if (!md.options.highlight) {
- // this function is always created by vitepress, but we need to check it
- // anyway to make TypeScript happy
- throw new Error(
- 'Missing MarkdownIt highlight function (should be automatically created by vitepress'
- );
- }
- return '';
- } else if (token.info.trim() === 'mermaid') {
+ const language = token.info.trim();
+ if (language.startsWith('mermaid')) {
const key = index;
return `
WARNING
${token.content}}
NOTE
${token.content}}
-