Skip to content

Commit

Permalink
fix(compiler): should keep newline after unary tags in <pre> (#8965)
Browse files Browse the repository at this point in the history
fix #8950
  • Loading branch information
javoski authored and yyx990803 committed Nov 30, 2018
1 parent 2bb3199 commit 05001e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/parser/html-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function parseHTML (html, options) {
const startTagMatch = parseStartTag()
if (startTagMatch) {
handleStartTag(startTagMatch)
if (shouldIgnoreFirstNewline(lastTag, html)) {
if (shouldIgnoreFirstNewline(startTagMatch.tagName, html)) {
advance(1)
}
continue
Expand Down
9 changes: 9 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,15 @@ describe('parser', () => {
expect(pre2.children[0].text).toBe('\nabc')
})

it('keep first newline after unary tag in <pre>', () => {
const options = extend({}, baseOptions)
const ast = parse('<pre>abc<input>\ndef</pre>', options)
expect(ast.children[1].type).toBe(1)
expect(ast.children[1].tag).toBe('input')
expect(ast.children[2].type).toBe(3)
expect(ast.children[2].text).toBe('\ndef')
})

it('forgivingly handle < in plain text', () => {
const options = extend({}, baseOptions)
const ast = parse('<p>1 < 2 < 3</p>', options)
Expand Down

0 comments on commit 05001e6

Please sign in to comment.