mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Merge pull request #3807 from aloisklink/docs/update-code-highlighting-theme
Use `github-dark` to highlight fence blocks in vitepress docs
This commit is contained in:
commit
09ed41b7d2
@ -91,7 +91,6 @@
|
|||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"remark": "^14.0.2",
|
"remark": "^14.0.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"shiki": "^0.11.1",
|
|
||||||
"start-server-and-test": "^1.14.0",
|
"start-server-and-test": "^1.14.0",
|
||||||
"typedoc": "^0.23.18",
|
"typedoc": "^0.23.18",
|
||||||
"typedoc-plugin-markdown": "^3.13.6",
|
"typedoc-plugin-markdown": "^3.13.6",
|
||||||
|
@ -4,6 +4,8 @@ import { MermaidMarkdown } from 'vitepress-plugin-mermaid';
|
|||||||
import { defineConfig, MarkdownOptions } from 'vitepress';
|
import { defineConfig, MarkdownOptions } from 'vitepress';
|
||||||
|
|
||||||
const allMarkdownTransformers: MarkdownOptions = {
|
const allMarkdownTransformers: MarkdownOptions = {
|
||||||
|
// the shiki theme to highlight code blocks
|
||||||
|
theme: 'github-dark',
|
||||||
config: async (md) => {
|
config: async (md) => {
|
||||||
await MermaidExample(md);
|
await MermaidExample(md);
|
||||||
MermaidMarkdown(md);
|
MermaidMarkdown(md);
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import type { MarkdownRenderer } from 'vitepress';
|
import type { MarkdownRenderer } from 'vitepress';
|
||||||
|
|
||||||
// Note: using "import shiki from 'shiki' and then "const highlighter = await shiki.getHighlighter(...) does not work 2022-11-15
|
|
||||||
import { getHighlighter } from 'shiki';
|
|
||||||
|
|
||||||
const MermaidExample = async (md: MarkdownRenderer) => {
|
const MermaidExample = async (md: MarkdownRenderer) => {
|
||||||
const defaultRenderer = md.renderer.rules.fence;
|
const defaultRenderer = md.renderer.rules.fence;
|
||||||
|
|
||||||
@ -10,26 +7,29 @@ const MermaidExample = async (md: MarkdownRenderer) => {
|
|||||||
throw new Error('defaultRenderer is undefined');
|
throw new Error('defaultRenderer is undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
const highlighter = await getHighlighter({
|
|
||||||
theme: 'material-palenight',
|
|
||||||
langs: ['mermaid'],
|
|
||||||
});
|
|
||||||
|
|
||||||
md.renderer.rules.fence = (tokens, index, options, env, slf) => {
|
md.renderer.rules.fence = (tokens, index, options, env, slf) => {
|
||||||
const token = tokens[index];
|
const token = tokens[index];
|
||||||
|
|
||||||
if (token.info.trim() === 'mermaid-example') {
|
if (token.info.trim() === 'mermaid-example') {
|
||||||
const highlight = highlighter
|
if (!md.options.highlight) {
|
||||||
.codeToHtml(token.content, { lang: 'mermaid' })
|
// this function is always created by vitepress, but we need to check it
|
||||||
.replace(/<span/g, '<span v-pre')
|
// anyway to make TypeScript happy
|
||||||
.replace('#2e3440ff', 'transparent')
|
throw new Error(
|
||||||
.replace('#292D3E', 'transparent');
|
'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 `<h5>Code:</h5>
|
return `<h5>Code:</h5>
|
||||||
<div class="language-mermaid">
|
<div class="language-mermaid">
|
||||||
<button class="copy"></button>
|
<button class="copy"></button>
|
||||||
<span class="lang">mermaid</span>
|
<span class="lang">mermaid</span>
|
||||||
${highlight}
|
${
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<h5>Diagram:</h5>`;
|
<h5>Diagram:</h5>`;
|
||||||
}
|
}
|
||||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -275,9 +275,6 @@ importers:
|
|||||||
rimraf:
|
rimraf:
|
||||||
specifier: ^3.0.2
|
specifier: ^3.0.2
|
||||||
version: 3.0.2
|
version: 3.0.2
|
||||||
shiki:
|
|
||||||
specifier: ^0.11.1
|
|
||||||
version: 0.11.1
|
|
||||||
start-server-and-test:
|
start-server-and-test:
|
||||||
specifier: ^1.14.0
|
specifier: ^1.14.0
|
||||||
version: 1.14.0
|
version: 1.14.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user