HTML API: Respect newlines setting modifiable HTML#25
Conversation
@todo split into data provider
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Comment incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.
| HTML, | ||
| $processor->get_updated_html(), | ||
| '<body>', | ||
| 'Should have preserved the leading newline in the TEXTAREA content.' |
There was a problem hiding this comment.
Assertion message incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.
| /** | ||
| * 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. |
There was a problem hiding this comment.
Comment incorrectly references 'TEXTAREA' when the test is for LISTING elements. Should say 'LISTING content' instead of 'TEXTAREA content'.
| HTML, | ||
| $processor->get_updated_html(), | ||
| '<body>', | ||
| 'Should have preserved the leading newline in the TEXTAREA content.' |
There was a problem hiding this comment.
Assertion message incorrectly references 'TEXTAREA' when the test is for LISTING elements. Should say 'LISTING content' instead of 'TEXTAREA content'.
| /** | ||
| * 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. |
There was a problem hiding this comment.
Comment incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.
| HTML, | ||
| $processor->get_updated_html(), | ||
| '<body>', | ||
| 'Should have preserved the leading newline in the TEXTAREA content.' |
There was a problem hiding this comment.
Assertion message incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.
| HTML, | ||
| $processor->get_updated_html(), | ||
| '<body>', | ||
| 'Should have preserved the leading newline in the TEXTAREA content.' |
There was a problem hiding this comment.
Assertion message incorrectly references 'TEXTAREA' when the test is for PRE elements. Should say 'PRE content' instead of 'TEXTAREA content'.
| /** | ||
| * 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. |
There was a problem hiding this comment.
Comment incorrectly references 'TEXTAREA' when the test is for LISTING elements. Should say 'LISTING content' instead of 'TEXTAREA content'.
| HTML, | ||
| $processor->get_updated_html(), | ||
| '<body>', | ||
| 'Should have preserved the leading newline in the TEXTAREA content.' |
There was a problem hiding this comment.
Assertion message incorrectly references 'TEXTAREA' when the test is for LISTING elements. Should say 'LISTING content' instead of 'TEXTAREA content'.
| * 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. |
There was a problem hiding this comment.
Corrected spelling of 'mage' to 'may be'.
| * @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. |
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.