Skip to content

Commit

Permalink
fix(compiler): should only strip leading newline directly in pre tag
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 8, 2020
1 parent 8444078 commit be666eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function parseChildren(
}
}
}
} else {
} else if (parent && context.options.isPreTag(parent.tag)) {
// remove leading newline per html spec
// https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
const first = nodes[0]
Expand Down
22 changes: 17 additions & 5 deletions packages/compiler-dom/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,24 @@ describe('DOM parser', () => {

// #908
test('<pre> tag should remove leading newline', () => {
const rawText = `\nhello`
const rawText = `\nhello<div>\nbye</div>`
const ast = parse(`<pre>${rawText}</pre>`, parserOptions)
expect((ast.children[0] as ElementNode).children[0]).toMatchObject({
type: NodeTypes.TEXT,
content: rawText.slice(1)
})
expect((ast.children[0] as ElementNode).children).toMatchObject([
{
type: NodeTypes.TEXT,
content: `hello`
},
{
type: NodeTypes.ELEMENT,
children: [
{
type: NodeTypes.TEXT,
// should not remove the leading newline for nested elements
content: `\nbye`
}
]
}
])
})
})

Expand Down

0 comments on commit be666eb

Please sign in to comment.