@@ -4,15 +4,14 @@ import { visit } from 'unist-util-visit';
44import { Node } from 'hast-util-heading-rank' ;
55import { toString } from 'mdast-util-to-string' ;
66import * as shiki from 'shiki' ;
7-
87let highlighter : shiki . Highlighter ;
98
109/**
1110 * Matches any `pre code` elements and extracts the raw code and titles from the code block and assigns to the parent.
1211 * @returns
1312 */
1413export default function rehypeCodeBlocks ( ) : ( ast : Node ) => void {
15- function visitor ( node : any , _i : number , parent : any ) {
14+ function visitor ( node : any , i : number , parent : any ) {
1615 if ( ! parent || parent . tagName !== 'pre' || node . tagName !== 'code' ) {
1716 return ;
1817 }
@@ -21,6 +20,21 @@ export default function rehypeCodeBlocks(): (ast: Node) => void {
2120
2221 const raw = toString ( node ) ;
2322
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+
2438 // If the user provides the `console` language, we add the 'shell' language and remove $ from the raw code, for copying purposes.
2539 if ( language === 'console' ) {
2640 const removedDollarSymbol = raw . replace ( / ^ ( ^ * ) \$ / g, '' ) ;
0 commit comments