@@ -79,14 +79,20 @@ export async function highlight(
79
79
transformerNotationHighlight ( ) ,
80
80
transformerNotationErrorLevel ( ) ,
81
81
{
82
+ name : 'vitepress:add-class' ,
82
83
pre ( node ) {
83
84
addClassToHast ( node , 'vp-code' )
84
85
}
86
+ } ,
87
+ {
88
+ name : 'vitepress:clean-up' ,
89
+ pre ( node ) {
90
+ delete node . properties . tabindex
91
+ delete node . properties . style
92
+ }
85
93
}
86
94
]
87
95
88
- const styleRE = / < p r e [ ^ > ] * ( s t y l e = " .* ?" ) /
89
- const preRE = / ^ < p r e ( .* ?) > /
90
96
const vueRE = / - v u e $ /
91
97
const lineNoStartRE = / = ( \d * ) /
92
98
const lineNoRE = / : ( n o - ) ? l i n e - n u m b e r s ( = \d * ) ? $ /
@@ -116,16 +122,6 @@ export async function highlight(
116
122
}
117
123
118
124
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
-
129
125
const mustaches = new Map < string , string > ( )
130
126
131
127
const removeMustache = ( s : string ) => {
@@ -161,6 +157,12 @@ export async function highlight(
161
157
transformers : [
162
158
...transformers ,
163
159
transformerCompactLineOptions ( lineOptions ) ,
160
+ {
161
+ name : 'vitepress:v-pre' ,
162
+ pre ( node ) {
163
+ if ( vPre ) node . properties [ 'v-pre' ] = ''
164
+ }
165
+ } ,
164
166
...userTransformers
165
167
] ,
166
168
meta : {
@@ -174,6 +176,6 @@ export async function highlight(
174
176
} )
175
177
} )
176
178
177
- return fillEmptyHighlightedLine ( cleanup ( restoreMustache ( highlighted ) ) )
179
+ return fillEmptyHighlightedLine ( restoreMustache ( highlighted ) )
178
180
}
179
181
}
0 commit comments