Skip to content

Commit 05001e6

Browse files
javoskiyyx990803
authored andcommitted
fix(compiler): should keep newline after unary tags in <pre> (#8965)
fix #8950
1 parent 2bb3199 commit 05001e6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/compiler/parser/html-parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function parseHTML (html, options) {
106106
const startTagMatch = parseStartTag()
107107
if (startTagMatch) {
108108
handleStartTag(startTagMatch)
109-
if (shouldIgnoreFirstNewline(lastTag, html)) {
109+
if (shouldIgnoreFirstNewline(startTagMatch.tagName, html)) {
110110
advance(1)
111111
}
112112
continue

test/unit/modules/compiler/parser.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,15 @@ describe('parser', () => {
667667
expect(pre2.children[0].text).toBe('\nabc')
668668
})
669669

670+
it('keep first newline after unary tag in <pre>', () => {
671+
const options = extend({}, baseOptions)
672+
const ast = parse('<pre>abc<input>\ndef</pre>', options)
673+
expect(ast.children[1].type).toBe(1)
674+
expect(ast.children[1].tag).toBe('input')
675+
expect(ast.children[2].type).toBe(3)
676+
expect(ast.children[2].text).toBe('\ndef')
677+
})
678+
670679
it('forgivingly handle < in plain text', () => {
671680
const options = extend({}, baseOptions)
672681
const ast = parse('<p>1 < 2 < 3</p>', options)

0 commit comments

Comments
 (0)