Skip to content

Commit

Permalink
fix: docs code highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
emersonbottero committed Sep 27, 2024
1 parent 3f75c18 commit 4e4d7c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions packages/mermaid/scripts/docs.mts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ const MERMAID_MAJOR_VERSION = MERMAID_RELEASE_VERSION.split('.')[0];
const CDN_URL = 'https://cdn.jsdelivr.net/npm'; // 'https://unpkg.com';

const MERMAID_KEYWORD = 'mermaid';
const MERMAID_CODE_ONLY_KEYWORD = 'mermaid-example';
const MERMAID_CODE_ONLY_KEYWORD = 'mmd';
const MERMAID_DIAGRAM_ONLY = 'mermaid-nocode';

// These keywords will produce both a mermaid diagram and a code block with the diagram source
const MERMAID_EXAMPLE_KEYWORDS = [MERMAID_KEYWORD, 'mmd', MERMAID_CODE_ONLY_KEYWORD]; // 'mmd' is an old keyword that used to be used
const MERMAID_EXAMPLE_KEYWORDS = [MERMAID_KEYWORD, MERMAID_CODE_ONLY_KEYWORD]; // 'mmd' is an new keyword that should be used to highlight code using shiki

// These will be transformed into block quotes
const BLOCK_QUOTE_KEYWORDS = ['note', 'tip', 'warning', 'danger'];
Expand Down Expand Up @@ -99,7 +99,7 @@ const generateHeader = (file: string): string => {
const sourcePathRelativeToGenerated = posix.join(relativePath, filePathFromRoot);
return `
> **Warning**
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
> ## Please edit the corresponding file in [${filePathFromRoot}](${sourcePathRelativeToGenerated}).`;
};

Expand Down Expand Up @@ -253,9 +253,9 @@ export function transformMarkdownAst({
node.lang = MERMAID_KEYWORD;
return [node];
} else if (MERMAID_EXAMPLE_KEYWORDS.includes(node.lang)) {
// If Vitepress, return only the original node with the language now set to 'mermaid-example' (will be rendered using custom renderer)
// If Vitepress, return only the original node with the language now set to 'mmd' (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
// 1. the original node with the language now set to 'mmd' (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 vitepress ? [node] : [node, Object.assign({}, node, { lang: MERMAID_KEYWORD })];
Expand Down Expand Up @@ -318,7 +318,7 @@ export function transformMarkdownAst({
* documentation
*
* 1. include any included files (copy and insert the source)
* 2. Add a `mermaid-example` block before every `mermaid` or `mmd` block On the main documentation site (one
* 2. Add a `mmd` block before every `mermaid` block On the main documentation site (one
* place where the documentation is published), this will show the code for the mermaid diagram
* 3. Transform blocks to block quotes as needed
* 4. Add the text that says the file is automatically generated
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/docs/.vitepress/mermaid-markdown-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const MermaidExample = (md: MarkdownRenderer) => {
if (language.startsWith('mermaid')) {
const key = index;
return `
<Suspense>
<Suspense>
<template #default>
<Mermaid id="mermaid-${key}" :showCode="${
language === 'mermaid-example'
language === 'mmd'
}" graph="${encodeURIComponent(token.content)}"></Mermaid>
</template>
<!-- loading state via #fallback slot -->
Expand Down

0 comments on commit 4e4d7c4

Please sign in to comment.