File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ function parseChildren(
223223 }
224224 }
225225 }
226- } else {
226+ } else if ( parent && context . options . isPreTag ( parent . tag ) ) {
227227 // remove leading newline per html spec
228228 // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
229229 const first = nodes [ 0 ]
Original file line number Diff line number Diff line change @@ -141,12 +141,24 @@ describe('DOM parser', () => {
141141
142142 // #908
143143 test ( '<pre> tag should remove leading newline' , ( ) => {
144- const rawText = `\nhello`
144+ const rawText = `\nhello<div>\nbye</div> `
145145 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+ ] )
150162 } )
151163 } )
152164
You can’t perform that action at this time.
0 commit comments