@@ -1358,25 +1358,7 @@ public function serialize_token(): string {
13581358 break ;
13591359
13601360 case '#text ' :
1361- $ text = $ this ->get_modifiable_text ();
1362- if ( WP_HTML_Tag_Processor::TEXT_IS_WHITESPACE === $ this ->text_node_classification ) {
1363- $ parent_node_name = $ this ->state ->stack_of_open_elements ->at ( $ this ->state ->stack_of_open_elements ->count () - 1 )?->node_name;
1364- if ( 'PRE ' === $ parent_node_name || 'LISTING ' === $ parent_node_name ) {
1365- /*
1366- * DO NOT DO THIS
1367- * This case is exceptional and we must peek at processor internals.
1368- */
1369- $ newline_was_erased = Closure::bind (
1370- fn () => $ this ->skip_newline_at === $ this ->token_starts_at ,
1371- $ this ,
1372- WP_HTML_Tag_Processor::class
1373- )();
1374- if ( $ newline_was_erased ) {
1375- $ text = "\n{$ text }" ;
1376- }
1377- }
1378- }
1379- $ html .= htmlspecialchars ( $ text , ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5 , 'UTF-8 ' );
1361+ $ html .= htmlspecialchars ( $ this ->get_modifiable_text (), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5 , 'UTF-8 ' );
13801362 break ;
13811363
13821364 // Unlike the `<>` which is interpreted as plaintext, this is ignored entirely.
@@ -1430,6 +1412,10 @@ public function serialize_token(): string {
14301412
14311413 $ html .= '> ' ;
14321414
1415+ if ( $ tag_name === 'TEXTAREA ' || $ tag_name === 'PRE ' || $ tag_name === 'LISTING ' ) {
1416+ $ html .= "\n" ;
1417+ }
1418+
14331419 // Flush out self-contained elements.
14341420 if ( $ in_html && in_array ( $ tag_name , array ( 'IFRAME ' , 'NOEMBED ' , 'NOFRAMES ' , 'SCRIPT ' , 'STYLE ' , 'TEXTAREA ' , 'TITLE ' , 'XMP ' ), true ) ) {
14351421 $ text = $ this ->get_modifiable_text ();
@@ -1445,19 +1431,6 @@ public function serialize_token(): string {
14451431 case 'STYLE ' :
14461432 break ;
14471433
1448- /*
1449- * Textarea elements ignore a leading newline. It is not present in `get_modifiable_text()`
1450- * because the HTML parser doesn't include it in the text node.
1451- * Serialization can always add a leading newline because it will be ignored by an
1452- * HTML parser.
1453- * This is especially important in case the text starts with a sequence of newlines.
1454- * If normalization removes a single leading newline, it would cause the
1455- * _significant_ following newline to be ignore by any later processing
1456- * or a browser.
1457- */
1458- case 'TEXTAREA ' :
1459- $ text = "\n{$ text }" ;
1460- // Intentional fallthrough, TEXTAREA should have default handling.
14611434 default :
14621435 $ text = htmlspecialchars ( $ text , ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5 , 'UTF-8 ' );
14631436 }
0 commit comments