@@ -4,15 +4,14 @@ import { visit } from 'unist-util-visit';
4
4
import { Node } from 'hast-util-heading-rank' ;
5
5
import { toString } from 'mdast-util-to-string' ;
6
6
import * as shiki from 'shiki' ;
7
-
8
7
let highlighter : shiki . Highlighter ;
9
8
10
9
/**
11
10
* Matches any `pre code` elements and extracts the raw code and titles from the code block and assigns to the parent.
12
11
* @returns
13
12
*/
14
13
export default function rehypeCodeBlocks ( ) : ( ast : Node ) => void {
15
- function visitor ( node : any , _i : number , parent : any ) {
14
+ function visitor ( node : any , i : number , parent : any ) {
16
15
if ( ! parent || parent . tagName !== 'pre' || node . tagName !== 'code' ) {
17
16
return ;
18
17
}
@@ -21,6 +20,21 @@ export default function rehypeCodeBlocks(): (ast: Node) => void {
21
20
22
21
const raw = toString ( node ) ;
23
22
23
+ if ( language === 'mermaid' ) {
24
+ Object . assign ( parent , {
25
+ type : 'mdxJsxFlowElement' ,
26
+ name : 'Mermaid' ,
27
+ attributes : [
28
+ {
29
+ type : 'mdxJsxAttribute' ,
30
+ name : 'chart' ,
31
+ value : node . children [ 0 ] . value ,
32
+ } ,
33
+ ] ,
34
+ } ) ;
35
+ return ;
36
+ }
37
+
24
38
// If the user provides the `console` language, we add the 'shell' language and remove $ from the raw code, for copying purposes.
25
39
if ( language === 'console' ) {
26
40
const removedDollarSymbol = raw . replace ( / ^ ( ^ * ) \$ / g, '' ) ;
0 commit comments