Skip to content

Commit 746ea7a

Browse files
committed
Add explanatory comment
1 parent 3043937 commit 746ea7a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,28 @@ public function serialize_token(): string {
14121412

14131413
$html .= '>';
14141414

1415+
/*
1416+
* The HTML parser strips a leading newline immediately after the start
1417+
* tag of TEXTAREA, PRE, and LISTING elements. When serializing, prepend
1418+
* a leading newline to ensure the semantic HTML content is preserved.
1419+
*
1420+
* For example, `<pre>\n\nX</pre>` must not become `<pre>\nX</pre>` because its content
1421+
* has changed. However, `<pre>X</pre>` and `<pre>\nX</pre>` are _equivalent_.
1422+
*
1423+
* > A start tag whose tag name is "textarea"
1424+
* > …
1425+
* > If the next token is a U+000A LINE FEED (LF) character token, then ignore
1426+
* > that token and move on to the next one. (Newlines at the start of textarea
1427+
* > elements are ignored as an authoring convenience.)
1428+
*
1429+
* > A start tag whose tag name is one of: "pre", "listing"
1430+
* > …
1431+
* > If the next token is a U+000A LINE FEED (LF) character token, then ignore
1432+
* > that token and move on to the next one. (Newlines at the start of pre blocks
1433+
* > are ignored as an authoring convenience.)
1434+
*
1435+
* @see https://html.spec.whatwg.org/multipage/parsing.html
1436+
*/
14151437
if ( $tag_name === 'TEXTAREA' || $tag_name === 'PRE' || $tag_name === 'LISTING' ) {
14161438
$html .= "\n";
14171439
}

0 commit comments

Comments
 (0)