File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,14 +86,18 @@ const tikzTransformer: UnifiedPlugin<
8686 hast . Root
8787> = ( { carta, options } ) => {
8888 return async function ( tree ) {
89- visit ( tree , ( node , index , parent ) => {
89+ visit ( tree , ( pre , index , parent ) => {
9090 if ( typeof document === 'undefined' ) {
9191 // Cannot run outside the browser
9292 return ;
9393 }
9494
95- if ( node . type !== 'element' ) return ;
96- const element = node as hast . Element ;
95+ if ( pre . type !== 'element' ) return ;
96+ const preElement = pre as hast . Element ;
97+ if ( preElement . tagName !== 'pre' ) return ;
98+ const element = pre . children . at ( 0 ) as hast . Element | undefined ;
99+ if ( ! element ) return ;
100+
97101 if ( element . tagName !== 'code' ) return ;
98102 if ( ! element . properties [ 'className' ] ) return ;
99103 if ( ! ( element . properties [ 'className' ] as string [ ] ) . includes ( 'language-tikz' ) ) return ;
@@ -130,6 +134,7 @@ const tikzTransformer: UnifiedPlugin<
130134 }
131135
132136 const hastNode = fromDom ( container ) as hast . Element ;
137+
133138 parent ?. children . splice ( index ! , 1 , hastNode ) ;
134139
135140 return [ SKIP , index ! ] ;
You can’t perform that action at this time.
0 commit comments