Skip to content

HTML API: Preserve leading newlines in PRE, TEXTAREA#24

Draft
sirreal wants to merge 3 commits intotrunkfrom
html-api/normalization-special-newlines
Draft

HTML API: Preserve leading newlines in PRE, TEXTAREA#24
sirreal wants to merge 3 commits intotrunkfrom
html-api/normalization-special-newlines

Conversation

@sirreal
Copy link
Owner

@sirreal sirreal commented Feb 5, 2026

According to the HTML standard, a leading newline will be removed from PRE, TEXTAREA, LISTING elements.

Preserve those newlines.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements HTML standard-compliant handling of leading newlines in PRE, TEXTAREA, and LISTING elements. According to the HTML specification, these elements ignore their first leading newline as an authoring convenience, but subsequent newlines are significant and must be preserved.

Changes:

  • Added serialization logic to restore stripped leading newlines in PRE and LISTING elements when serializing text nodes
  • Added serialization logic to prepend a newline to TEXTAREA content to preserve any subsequent newlines
  • Added comprehensive test coverage for PRE and TEXTAREA elements with single and double leading newlines

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php Adds test cases for leading newline handling in PRE and TEXTAREA elements, including edge cases with multiple text nodes and double leading newlines
src/wp-includes/html-api/class-wp-html-processor.php Implements serialization logic to restore stripped leading newlines in PRE/LISTING text nodes and prepend newlines to TEXTAREA content

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php:3

  • This import statement for 'assertNotEmpty' is added but never used in the file. It should be removed.
 * Unit tests covering WP_HTML_Processor serialization functionality.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add serialize + normalize tests

Add more PRE tests

Fix newlines disappearing inside PRE,TEXTAREA elements

Handline PRE,LISTING

lints

Simpler fix

Remove overly-specific tests

Add LISTING tests

Add explanatory comment

lints

Remove accidental import
@sirreal sirreal force-pushed the html-api/normalization-special-newlines branch from 4e5a7d4 to d130c92 Compare February 5, 2026 16:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant