File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,16 @@ h1 { color: red }
106
106
expect ( descriptor . template ! . content ) . toBe ( content )
107
107
} )
108
108
109
+ // #1120
110
+ test ( 'alternative template lang should be treated as plain text' , ( ) => {
111
+ const content = `p(v-if="1 < 2") test`
112
+ const { descriptor, errors } = parse (
113
+ `<template lang="pug">` + content + `</template>`
114
+ )
115
+ expect ( errors . length ) . toBe ( 0 )
116
+ expect ( descriptor . template ! . content ) . toBe ( content )
117
+ } )
118
+
109
119
test ( 'error tolerance' , ( ) => {
110
120
const { errors } = parse ( `<template>` )
111
121
expect ( errors . length ) . toBe ( 1 )
Original file line number Diff line number Diff line change @@ -96,10 +96,20 @@ export function parse(
96
96
isNativeTag : ( ) => true ,
97
97
// preserve all whitespaces
98
98
isPreTag : ( ) => true ,
99
- getTextMode : ( { tag } , parent ) => {
99
+ getTextMode : ( { tag, props } , parent ) => {
100
100
// all top level elements except <template> are parsed as raw text
101
101
// containers
102
- if ( ! parent && tag !== 'template' ) {
102
+ if (
103
+ ( ! parent && tag !== 'template' ) ||
104
+ // <template lang="xxx"> should also be treated as raw text
105
+ props . some (
106
+ p =>
107
+ p . type === NodeTypes . ATTRIBUTE &&
108
+ p . name === 'lang' &&
109
+ p . value &&
110
+ p . value . content !== 'html'
111
+ )
112
+ ) {
103
113
return TextModes . RAWTEXT
104
114
} else {
105
115
return TextModes . DATA
You can’t perform that action at this time.
0 commit comments