@@ -72,6 +72,7 @@ export const defaultParserOptions: MergedParserOptions = {
72
72
getNamespace : ( ) => Namespaces . HTML ,
73
73
isVoidTag : NO ,
74
74
isPreTag : NO ,
75
+ isIgnoreNewlineTag : NO ,
75
76
isCustomElement : NO ,
76
77
onError : defaultOnError ,
77
78
onWarn : defaultOnWarn ,
@@ -633,7 +634,7 @@ function onCloseTag(el: ElementNode, end: number, isImplied = false) {
633
634
}
634
635
635
636
// refine element type
636
- const { tag, ns } = el
637
+ const { tag, ns, children } = el
637
638
if ( ! inVPre ) {
638
639
if ( tag === 'slot' ) {
639
640
el . tagType = ElementTypes . SLOT
@@ -646,8 +647,18 @@ function onCloseTag(el: ElementNode, end: number, isImplied = false) {
646
647
647
648
// whitespace management
648
649
if ( ! tokenizer . inRCDATA ) {
649
- el . children = condenseWhitespace ( el . children , el . tag )
650
+ el . children = condenseWhitespace ( children , tag )
650
651
}
652
+
653
+ if ( ns === Namespaces . HTML && currentOptions . isIgnoreNewlineTag ( tag ) ) {
654
+ // remove leading newline for <textarea> and <pre> per html spec
655
+ // https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody
656
+ const first = children [ 0 ]
657
+ if ( first && first . type === NodeTypes . TEXT ) {
658
+ first . content = first . content . replace ( / ^ \r ? \n / , '' )
659
+ }
660
+ }
661
+
651
662
if ( ns === Namespaces . HTML && currentOptions . isPreTag ( tag ) ) {
652
663
inPre --
653
664
}
@@ -869,14 +880,6 @@ function condenseWhitespace(
869
880
}
870
881
}
871
882
}
872
- if ( inPre && tag && currentOptions . isPreTag ( tag ) ) {
873
- // remove leading newline per html spec
874
- // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
875
- const first = nodes [ 0 ]
876
- if ( first && first . type === NodeTypes . TEXT ) {
877
- first . content = first . content . replace ( / ^ \r ? \n / , '' )
878
- }
879
- }
880
883
return removedWhitespace ? nodes . filter ( Boolean ) : nodes
881
884
}
882
885
0 commit comments