@@ -79,14 +79,20 @@ export async function highlight(
7979 transformerNotationHighlight ( ) ,
8080 transformerNotationErrorLevel ( ) ,
8181 {
82+ name : 'vitepress:add-class' ,
8283 pre ( node ) {
8384 addClassToHast ( node , 'vp-code' )
8485 }
86+ } ,
87+ {
88+ name : 'vitepress:clean-up' ,
89+ pre ( node ) {
90+ delete node . properties . tabindex
91+ delete node . properties . style
92+ }
8593 }
8694 ]
8795
88- const styleRE = / < p r e [ ^ > ] * ( s t y l e = " .* ?" ) /
89- const preRE = / ^ < p r e ( .* ?) > /
9096 const vueRE = / - v u e $ /
9197 const lineNoStartRE = / = ( \d * ) /
9298 const lineNoRE = / : ( n o - ) ? l i n e - n u m b e r s ( = \d * ) ? $ /
@@ -116,16 +122,6 @@ export async function highlight(
116122 }
117123
118124 const lineOptions = attrsToLines ( attrs )
119- const cleanup = ( str : string ) => {
120- return str
121- . replace (
122- preRE ,
123- ( _ , attributes ) =>
124- `<pre ${ vPre } ${ attributes . replace ( ' tabindex="0"' , '' ) } >`
125- )
126- . replace ( styleRE , ( _ , style ) => _ . replace ( style , '' ) )
127- }
128-
129125 const mustaches = new Map < string , string > ( )
130126
131127 const removeMustache = ( s : string ) => {
@@ -161,6 +157,12 @@ export async function highlight(
161157 transformers : [
162158 ...transformers ,
163159 transformerCompactLineOptions ( lineOptions ) ,
160+ {
161+ name : 'vitepress:v-pre' ,
162+ pre ( node ) {
163+ if ( vPre ) node . properties [ 'v-pre' ] = ''
164+ }
165+ } ,
164166 ...userTransformers
165167 ] ,
166168 meta : {
@@ -174,6 +176,6 @@ export async function highlight(
174176 } )
175177 } )
176178
177- return fillEmptyHighlightedLine ( cleanup ( restoreMustache ( highlighted ) ) )
179+ return fillEmptyHighlightedLine ( restoreMustache ( highlighted ) )
178180 }
179181}
0 commit comments