File tree 2 files changed +18
-6
lines changed
2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ function parseChildren(
223
223
}
224
224
}
225
225
}
226
- } else {
226
+ } else if ( parent && context . options . isPreTag ( parent . tag ) ) {
227
227
// remove leading newline per html spec
228
228
// https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
229
229
const first = nodes [ 0 ]
Original file line number Diff line number Diff line change @@ -141,12 +141,24 @@ describe('DOM parser', () => {
141
141
142
142
// #908
143
143
test ( '<pre> tag should remove leading newline' , ( ) => {
144
- const rawText = `\nhello`
144
+ const rawText = `\nhello<div>\nbye</div> `
145
145
const ast = parse ( `<pre>${ rawText } </pre>` , parserOptions )
146
- expect ( ( ast . children [ 0 ] as ElementNode ) . children [ 0 ] ) . toMatchObject ( {
147
- type : NodeTypes . TEXT ,
148
- content : rawText . slice ( 1 )
149
- } )
146
+ expect ( ( ast . children [ 0 ] as ElementNode ) . children ) . toMatchObject ( [
147
+ {
148
+ type : NodeTypes . TEXT ,
149
+ content : `hello`
150
+ } ,
151
+ {
152
+ type : NodeTypes . ELEMENT ,
153
+ children : [
154
+ {
155
+ type : NodeTypes . TEXT ,
156
+ // should not remove the leading newline for nested elements
157
+ content : `\nbye`
158
+ }
159
+ ]
160
+ }
161
+ ] )
150
162
} )
151
163
} )
152
164
You can’t perform that action at this time.
0 commit comments