File tree 6 files changed +24
-7
lines changed
6 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ import { version } from "../../package.json";
5
5
6
6
export default withMermaid (
7
7
defineConfig ( {
8
+ // mermaidPlugin: {
9
+ // class: "mermaid my-class", // set additional css classes for parent container
10
+ // },
8
11
lang : "en-US" ,
9
12
title : "VitePress Plugin Mermaid" ,
10
13
description : "Mermaid support for vitepress" ,
Original file line number Diff line number Diff line change @@ -31,11 +31,13 @@ export default withMermaid({
31
31
mermaid: {
32
32
// refer https://mermaid.js.org/config/setup/modules/mermaidAPI.html#mermaidapi-configuration-defaults for options
33
33
},
34
+ // optionally set additional config for plugin itself with MermaidPluginConfig
35
+ mermaidPlugin: {
36
+ class: " mermaid my-class" , // set additional css classes for parent container
37
+ },
34
38
});
35
39
```
36
40
37
- Use in any Markdown file
38
-
39
41
Code with ```mmd
40
42
41
43
``` mmd
Original file line number Diff line number Diff line change 1
1
<template >
2
- <div v-html =" svg" class =" mermaid " ></div >
2
+ <div v-html =" svg" : class =" props.class " ></div >
3
3
</template >
4
4
5
5
<script setup>
@@ -27,6 +27,11 @@ const props = defineProps({
27
27
type: String ,
28
28
required: true ,
29
29
},
30
+ class: {
31
+ type: String ,
32
+ required: false ,
33
+ default: " mermaid" ,
34
+ }
30
35
});
31
36
32
37
const svg = ref (null );
Original file line number Diff line number Diff line change 1
1
import { type UserConfig } from "vitepress" ;
2
2
import { MermaidMarkdown } from "./mermaid-markdown" ;
3
- import { MermaidPlugin } from "./mermaid-plugin" ;
3
+ import { MermaidPlugin , MermaidPluginConfig } from "./mermaid-plugin" ;
4
4
import { MermaidConfig } from "mermaid/dist/config.type" ;
5
5
6
6
export { MermaidMarkdown } from "./mermaid-markdown" ;
@@ -11,14 +11,15 @@ export { UserConfig };
11
11
declare module "vitepress" {
12
12
interface UserConfig {
13
13
mermaid ?: MermaidConfig ;
14
+ mermaidPlugin ?: MermaidPluginConfig ;
14
15
}
15
16
}
16
17
17
18
export const withMermaid = ( config : UserConfig ) => {
18
19
if ( ! config . markdown ) config . markdown = { } ;
19
20
const markdownConfigOriginal = config . markdown . config || ( ( ) => { } ) ;
20
21
config . markdown . config = ( ...args ) => {
21
- MermaidMarkdown ( ...args ) ;
22
+ MermaidMarkdown ( ...args , config . mermaidPlugin ) ;
22
23
markdownConfigOriginal ( ...args ) ;
23
24
} ;
24
25
Original file line number Diff line number Diff line change 1
- export const MermaidMarkdown = ( md ) => {
1
+ export const MermaidMarkdown = ( md , pluginOptions ) => {
2
2
const sum = ( o ) => {
3
3
function pad ( hash , len ) {
4
4
while ( hash . length < len ) {
@@ -61,10 +61,11 @@ export const MermaidMarkdown = (md) => {
61
61
if ( token . info . trim ( ) === "mermaid" ) {
62
62
try {
63
63
const key = index ;
64
+ const cssClass = pluginOptions ?. class || 'mermaid' ;
64
65
return `
65
66
<Suspense>
66
67
<template #default>
67
- <Mermaid id="mermaid-${ key } " graph="${ encodeURIComponent (
68
+ <Mermaid id="mermaid-${ key } " class=" ${ cssClass } " graph="${ encodeURIComponent (
68
69
token . content
69
70
) } "></Mermaid>
70
71
</template>
Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ interface MermaidPluginOptions extends MermaidConfig {
9
9
externalDiagrams : ExternalDiagramDefinition [ ] ;
10
10
}
11
11
12
+ // Additional configuration for plugin itself. Separate model, not to risk name conflicts with future MermaidConfig options
13
+ export interface MermaidPluginConfig {
14
+ class ?: string ;
15
+ }
16
+
12
17
const DEFAULT_OPTIONS : MermaidConfig = {
13
18
//We set loose as default here because is needed to load images
14
19
securityLevel : "loose" ,
You can’t perform that action at this time.
0 commit comments