expect(descriptor.template!.content).toBe(content)
})
+ // #1120
+ test('alternative template lang should be treated as plain text', () => {
+ const content = `p(v-if="1 < 2") test`
+ const { descriptor, errors } = parse(
+ `<template lang="pug">` + content + `</template>`
+ )
+ expect(errors.length).toBe(0)
+ expect(descriptor.template!.content).toBe(content)
+ })
+
test('error tolerance', () => {
const { errors } = parse(`<template>`)
expect(errors.length).toBe(1)
isNativeTag: () => true,
// preserve all whitespaces
isPreTag: () => true,
- getTextMode: ({ tag }, parent) => {
+ getTextMode: ({ tag, props }, parent) => {
// all top level elements except <template> are parsed as raw text
// containers
- if (!parent && tag !== 'template') {
+ if (
+ (!parent && tag !== 'template') ||
+ // <template lang="xxx"> should also be treated as raw text
+ props.some(
+ p =>
+ p.type === NodeTypes.ATTRIBUTE &&
+ p.name === 'lang' &&
+ p.value &&
+ p.value.content !== 'html'
+ )
+ ) {
return TextModes.RAWTEXT
} else {
return TextModes.DATA