File tree 2 files changed +20
-7
lines changed
2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,13 @@ export const linkPlugin = (
32
32
) {
33
33
normalizeHref ( hrefAttr )
34
34
}
35
+
36
+ // encode vite-specific replace strings in case they appear in URLs
37
+ // this also excludes them from build-time replacements (which injects
38
+ // <wbr/> and will break URLs)
39
+ hrefAttr [ 1 ] = hrefAttr [ 1 ]
40
+ . replace ( / \b i m p o r t \. m e t a / g, 'import%2Emeta' )
41
+ . replace ( / \b p r o c e s s \. e n v / g, 'process%2Eenv' )
35
42
}
36
43
return self . renderToken ( tokens , idx , options )
37
44
}
Original file line number Diff line number Diff line change @@ -30,6 +30,15 @@ export function createMarkdownToVueRenderFn(
30
30
const md = createMarkdownRenderer ( srcDir , options )
31
31
pages = pages . map ( ( p ) => slash ( p . replace ( / \. m d $ / , '' ) ) )
32
32
33
+ const userDefineRegex = userDefines
34
+ ? new RegExp (
35
+ `\\b(${ Object . keys ( userDefines )
36
+ . map ( ( key ) => key . replace ( / [ - [ \] / { } ( ) * + ? . \\ ^ $ | ] / g, '\\$&' ) )
37
+ . join ( '|' ) } )`,
38
+ 'g'
39
+ )
40
+ : null
41
+
33
42
return (
34
43
src : string ,
35
44
file : string ,
@@ -66,14 +75,11 @@ export function createMarkdownToVueRenderFn(
66
75
. replace ( / \b p r o c e s s \. e n v / g, 'process.<wbr/>env' )
67
76
68
77
// also avoid replacing vite user defines
69
- if ( userDefines ) {
70
- const regex = new RegExp (
71
- `\\b(${ Object . keys ( userDefines )
72
- . map ( ( key ) => key . replace ( / [ - [ \] / { } ( ) * + ? . \\ ^ $ | ] / g, '\\$&' ) )
73
- . join ( '|' ) } )`,
74
- 'g'
78
+ if ( userDefineRegex ) {
79
+ html = html . replace (
80
+ userDefineRegex ,
81
+ ( _ ) => `${ _ [ 0 ] } <wbr/>${ _ . slice ( 1 ) } `
75
82
)
76
- html = html . replace ( regex , ( _ ) => `${ _ [ 0 ] } <wbr/>${ _ . slice ( 1 ) } ` )
77
83
}
78
84
}
79
85
You can’t perform that action at this time.
0 commit comments