@@ -59,6 +59,10 @@ const decodingMap = {
5959const encodedAttr = / & (?: l t | g t | q u o t | a m p ) ; / g
6060const encodedAttrWithNewLines = / & (?: l t | g t | q u o t | a m p | # 1 0 ) ; / g
6161
62+ // #5992
63+ const isIgnoreNewlineTag = makeMap ( 'pre,textarea' , true )
64+ const shouldIgnoreFirstNewline = ( tag , html ) => tag && isIgnoreNewlineTag ( tag ) && html [ 0 ] === '\n'
65+
6266function decodeAttr ( value , shouldDecodeNewlines ) {
6367 const re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr
6468 return value . replace ( re , match => decodingMap [ match ] )
@@ -75,6 +79,9 @@ export function parseHTML (html, options) {
7579 last = html
7680 // Make sure we're not in a plaintext content element like script/style
7781 if ( ! lastTag || ! isPlainTextElement ( lastTag ) ) {
82+ if ( shouldIgnoreFirstNewline ( lastTag , html ) ) {
83+ advance ( 1 )
84+ }
7885 let textEnd = html . indexOf ( '<' )
7986 if ( textEnd === 0 ) {
8087 // Comment:
@@ -152,16 +159,19 @@ export function parseHTML (html, options) {
152159 options . chars ( text )
153160 }
154161 } else {
155- var stackedTag = lastTag . toLowerCase ( )
156- var reStackedTag = reCache [ stackedTag ] || ( reCache [ stackedTag ] = new RegExp ( '([\\s\\S]*?)(</' + stackedTag + '[^>]*>)' , 'i' ) )
157- var endTagLength = 0
158- var rest = html . replace ( reStackedTag , function ( all , text , endTag ) {
162+ let endTagLength = 0
163+ const stackedTag = lastTag . toLowerCase ( )
164+ const reStackedTag = reCache [ stackedTag ] || ( reCache [ stackedTag ] = new RegExp ( '([\\s\\S]*?)(</' + stackedTag + '[^>]*>)' , 'i' ) )
165+ const rest = html . replace ( reStackedTag , function ( all , text , endTag ) {
159166 endTagLength = endTag . length
160167 if ( ! isPlainTextElement ( stackedTag ) && stackedTag !== 'noscript' ) {
161168 text = text
162169 . replace ( / < ! - - ( [ \s \S ] * ?) - - > / g, '$1' )
163170 . replace ( / < ! \[ C D A T A \[ ( [ \s \S ] * ?) ] ] > / g, '$1' )
164171 }
172+ if ( shouldIgnoreFirstNewline ( stackedTag , text ) ) {
173+ text = text . slice ( 1 )
174+ }
165175 if ( options . chars ) {
166176 options . chars ( text )
167177 }
0 commit comments