HTML API: Update Processing Instruction handling - #12424
Conversation
…essing-instruction-parse
…oken fixtures Claude-Session: https://claude.ai/code/session_019T4FGdVaBpVbMRcBbQPehd
…essing-instruction-parse
The HTML standard has added Processing Instruction parsing. The HTML API needs updates to handle PI.
…essing-instruction-parse
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| case '#comment': | ||
| case '#funky-comment': | ||
| case '#presumptuous-tag': | ||
| case '#processing-instruction': |
There was a problem hiding this comment.
We'll assume this is the intention. This entire insertion mode is gone from the current version of the spec: #9298
|
This adds PI handling to all the relevant insertion modes. PI handling is notably missing from two places: This change currently follows the spec for in head noscript but inserts the token in template. It's unclear whether these are an oversight or not. I've asked and will follow-up. |
PI nodes exist and are parsed. Bogus comments are just bugos comments.
Anchor the pending data update at the end of the target and always write the same fixed form: a separating space, the data, and the `?>` closer. Reading a pending update reverses these fixed rules: skip the leading whitespace and drop the two bytes of the closer. This removes the conditional separator when setting and the conditional `?` handling when reading. Editing now collapses any whitespace run following the target to a single space and rewrites bare `>` closers as `?>`. Claude-Session: https://claude.ai/code/session_019T4FGdVaBpVbMRcBbQPehd
Every path in `set_modifiable_text()` that returns `false` now calls `_doing_it_wrong()` naming the specific reason: a comment closer in comment text, a `>` or leading whitespace in processing instruction data, a SCRIPT tag in the text of a SCRIPT element whose content type has no known escaping rules, a token that holds no settable text, and an HTML tag outside SCRIPT, STYLE, TEXTAREA, and TITLE. `wp_get_inline_script_tag()` emitted its own `_doing_it_wrong()` when the update was rejected. Drop it so the path reports once, through the message that explains the cause rather than restating the symptom. Claude-Session: https://claude.ai/code/session_01QHbzNnnDZ5p6GCFUcraKwp
| _doing_it_wrong( | ||
| __FUNCTION__, | ||
| __( 'Unable to set inline script data.' ), | ||
| '7.0.0' | ||
| ); |
There was a problem hiding this comment.
This moves to WP_HTML_Tag_Processor::set_modifiable_text().
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Co-authored-by: Weston Ruter <westonruter@gmail.com> Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
westonruter
left a comment
There was a problem hiding this comment.
Looks great.
Just leaving some suggestions for connecting data providers with the tests they're for.
| } | ||
|
|
||
| /** | ||
| * Data provider. |
There was a problem hiding this comment.
I've started doing this to add a bidirectional linkage.
| * Data provider. | |
| * Data provider for {@see self::test_no_processing_instruction_in_raw_text()}. |
There was a problem hiding this comment.
How helpful are you finding this? There's no reason for a data provider to be tightly coupled to a specific test or tests (even if they often are), but listing these out specifically on the data provider seems like another thing to maintain that can go stale. It's simple to search for tests using a given data provider since the data provider name will appear in any associated tests.
There was a problem hiding this comment.
A simple search works, but this is a tighter coupling for easier navigation. It's a marginal improvement. Feel free to dismiss.
| } | ||
|
|
||
| /** | ||
| * Data provider. |
There was a problem hiding this comment.
| * Data provider. | |
| * Data provider for {@see self::test_processing_instruction_placement()}. |
| } | ||
|
|
||
| /** | ||
| * Data provider. |
There was a problem hiding this comment.
| * Data provider. | |
| * Data provider for {@see self::test_sets_processing_instruction_data()}. |
| } | ||
|
|
||
| /** | ||
| * Data provider. |
There was a problem hiding this comment.
| * Data provider. | |
| * Data provider for {@see self::test_invalid_targets_become_comments()}. |
| } | ||
|
|
||
| /** | ||
| * Data provider. |
There was a problem hiding this comment.
| * Data provider. | |
| * Data provider for {@see self::test_processing_instructions()}. |
|
|
||
| /** | ||
| * Data provider. | ||
| * |
There was a problem hiding this comment.
| * | |
| * | |
| * @see self::test_serializes_processing_instructions() | |
| * @see self::test_processing_instruction_normalization_is_idempotent() | |
| * |
The HTML specification was updated to include _processing instructions_ like `<?wp-processing-instruction ...data?>`. Implement processing instruction support in the HTML API. Developed in #12424. Props jonsurrell, dmsnell, westonruter. Fixes #65582. See #65581. git-svn-id: https://develop.svn.wordpress.org/trunk@62687 602fd350-edb4-49c9-b593-d223f7449a82
The HTML specification was updated to include _processing instructions_ like `<?wp-processing-instruction ...data?>`. Implement processing instruction support in the HTML API. Developed in WordPress/wordpress-develop#12424. Props jonsurrell, dmsnell, westonruter. Fixes #65582. See #65581. Built from https://develop.svn.wordpress.org/trunk@62687 git-svn-id: http://core.svn.wordpress.org/trunk@61971 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Handle Processing Instructions in the HTML API.
Some doubts about parsing PI in some insertions modes came up while implementing this change. I've raised them with the standards:
See #12423 (merged here) for the test addition.(landed in r62655)Trac ticket: https://core.trac.wordpress.org/ticket/65582
Test diff vs. trunk (
./vendor/bin/phpunit --group html-api-web-platform-tests)(A completely new test file is enabled which accounts for both tests and skipped test numbers increasing.)
Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Fable 5
Used for: Initial implementation.
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.