From 08a7f662ea305c19efb950b893933f6b0f0350f9 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Mon, 11 Mar 2024 17:03:26 +0530 Subject: [PATCH] Address review comments Support ctrl+enter Support mermaid-nocode Use `contenteditable="plaintext-only"` Co-authored-by: Alois Klink --- packages/mermaid/scripts/docs.mts | 5 +-- .../docs/.vitepress/mermaid-markdown-all.ts | 32 ++++++------------- .../src/docs/.vitepress/theme/Mermaid.vue | 32 ++++++++++++------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/packages/mermaid/scripts/docs.mts b/packages/mermaid/scripts/docs.mts index 42e299c54f..31d2a7c8fd 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 643ce395e9..64a069b4c2 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 ` `; - } - if (token.info.trim() === 'warning') { + } else if (language === 'warning') { return `

WARNING

${token.content}}

`; - } - - if (token.info.trim() === 'note') { + } else if (language === 'note') { return `

NOTE

${token.content}}

`; - } - - if (token.info.trim() === 'regexp') { + } else if (language === 'regexp') { // shiki doesn't yet support regexp code blocks, but the javascript // one still makes RegExes look good token.info = 'javascript'; // use trimEnd to move trailing `\n` outside if the JavaScript regex `/` block token.content = `/${token.content.trimEnd()}/\n`; return defaultRenderer(tokens, index, options, env, slf); - } - - if (token.info.trim() === 'jison') { + } else if (language === 'jison') { return `
jison diff --git a/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue b/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue index 59a5bbba97..a4fb9bf049 100644 --- a/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue +++ b/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue @@ -1,12 +1,14 @@