Skip to content

HTML API: Respect newlines setting modifiable HTML#25

Draft
sirreal wants to merge 5 commits intotrunkfrom
html-api/set-mod-html-leading-newlines
Draft

HTML API: Respect newlines setting modifiable HTML#25
sirreal wants to merge 5 commits intotrunkfrom
html-api/set-mod-html-leading-newlines

Conversation

@sirreal
Copy link
Owner

@sirreal sirreal commented Feb 5, 2026


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@sirreal sirreal requested a review from Copilot February 5, 2026 18:46
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 PR ensures that leading newlines in modifiable text are properly preserved for HTML elements that ignore the first newline in their content (TEXTAREA, PRE, and LISTING elements). The changes implement special handling to double the leading newline when setting modifiable text for these elements, preventing the browser from stripping it during parsing.

Changes:

  • Modified set_modifiable_text() to preserve leading newlines for text nodes and TEXTAREA elements
  • Added comprehensive test coverage for TEXTAREA, PRE, and LISTING elements in both WP_HTML_Tag_Processor and WP_HTML_Processor test suites

Reviewed changes

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

File Description
src/wp-includes/html-api/class-wp-html-tag-processor.php Implements logic to double leading newlines for text nodes and TEXTAREA elements to preserve them after HTML parsing
tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php Adds tests for special newline handling in TEXTAREA, PRE, and LISTING elements for WP_HTML_Tag_Processor
tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php Adds comprehensive tests for special newline handling in TEXTAREA, PRE, and LISTING elements for WP_HTML_Processor, including edge cases with existing whitespace

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

/**
* PRE elements ignore the first newline in their content.
* Setting the modifiable text with a leading newline should ensure that the leading newline
* is present in the resulting TEXTAREA.
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Comment incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
HTML,
$processor->get_updated_html(),
'<body>',
'Should have preserved the leading newline in the TEXTAREA content.'
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Assertion message incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
/**
* LISTING elements ignore the first newline in their content.
* Setting the modifiable text with a leading newline should ensure that the leading newline
* is present in the resulting TEXTAREA.
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Comment incorrectly references 'TEXTAREA' when the test is for LISTING elements. Should say 'LISTING content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
HTML,
$processor->get_updated_html(),
'<body>',
'Should have preserved the leading newline in the TEXTAREA content.'
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Assertion message incorrectly references 'TEXTAREA' when the test is for LISTING elements. Should say 'LISTING content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
/**
* PRE elements ignore the first newline in their content.
* Setting the modifiable text with a leading newline should ensure that the leading newline
* is present in the resulting TEXTAREA.
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Comment incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
HTML,
$processor->get_updated_html(),
'<body>',
'Should have preserved the leading newline in the TEXTAREA content.'
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Assertion message incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
HTML,
$processor->get_updated_html(),
'<body>',
'Should have preserved the leading newline in the TEXTAREA content.'
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Assertion message incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
/**
* LISTING elements ignore the first newline in their content.
* Setting the modifiable text with a leading newline should ensure that the leading newline
* is present in the resulting TEXTAREA.
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Comment incorrectly references 'TEXTAREA' when the test is for LISTING elements. Should say 'LISTING content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
HTML,
$processor->get_updated_html(),
'<body>',
'Should have preserved the leading newline in the TEXTAREA content.'
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Assertion message incorrectly references 'TEXTAREA' when the test is for LISTING elements. Should say 'LISTING content' instead of 'TEXTAREA content'.

Copilot uses AI. Check for mistakes.
* Setting the modifiable text with a leading newline should ensure that the leading newline
* is present in the resulting TEXTAREA.
*
* @todo Leading whitespace mage split into multiple text nodes. Add appropriate tests.
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'mage' to 'may be'.

Suggested change
* @todo Leading whitespace mage split into multiple text nodes. Add appropriate tests.
* @todo Leading whitespace may be split into multiple text nodes. Add appropriate tests.

Copilot uses AI. Check for mistakes.
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