Skip to content

HTML API: Update Processing Instruction handling - #12424

Closed
sirreal wants to merge 61 commits into
WordPress:trunkfrom
sirreal:html-api/update-processing-instruction-parse
Closed

HTML API: Update Processing Instruction handling#12424
sirreal wants to merge 61 commits into
WordPress:trunkfrom
sirreal:html-api/update-processing-instruction-parse

Conversation

@sirreal

@sirreal sirreal commented Jul 6, 2026

Copy link
Copy Markdown
Member

Handle Processing Instructions in the HTML API.

Processing instruction parsing has been updated in the HTML standard. <?processing instructions ?> were transformed into comments, but are now preserved.

See the processing instruction states in the standard.

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)

-Tests: 1513, Assertions: 1091, Skipped: 422.
+Tests: 1637, Assertions: 1206, Skipped: 431.

(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.

sirreal added 18 commits July 3, 2026 14:55
The HTML standard has added Processing Instruction parsing. The HTML API needs updates to handle PI.
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

case '#comment':
case '#funky-comment':
case '#presumptuous-tag':
case '#processing-instruction':

@sirreal sirreal Jul 6, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We'll assume this is the intention. This entire insertion mode is gone from the current version of the spec: #9298

@sirreal

sirreal commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

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.

Comment thread tests/phpunit/tests/html-api/wpHtmlTagProcessor.php Outdated
Comment thread tests/phpunit/tests/html-api/wpHtmlProcessor.php Outdated
Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php Outdated
sirreal added 4 commits July 9, 2026 14:29
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
Comment thread src/wp-includes/script-loader.php Outdated
Comment on lines -3051 to -3055
_doing_it_wrong(
__FUNCTION__,
__( 'Unable to set inline script data.' ),
'7.0.0'
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This moves to WP_HTML_Tag_Processor::set_modifiable_text().

@sirreal
sirreal requested a review from westonruter July 9, 2026 14:03
Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php Outdated
Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php Outdated
Comment thread tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php
Comment thread src/wp-includes/html-api/class-wp-html-processor.php Outdated
Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php Outdated
Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php Outdated
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php Outdated
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great.

Just leaving some suggestions for connecting data providers with the tests they're for.

}

/**
* Data provider.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've started doing this to add a bidirectional linkage.

Suggested change
* Data provider.
* Data provider for {@see self::test_no_processing_instruction_in_raw_text()}.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A simple search works, but this is a tighter coupling for easier navigation. It's a marginal improvement. Feel free to dismiss.

}

/**
* Data provider.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* Data provider.
* Data provider for {@see self::test_processing_instruction_placement()}.

}

/**
* Data provider.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* Data provider.
* Data provider for {@see self::test_sets_processing_instruction_data()}.

}

/**
* Data provider.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* Data provider.
* Data provider for {@see self::test_invalid_targets_become_comments()}.

}

/**
* Data provider.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* Data provider.
* Data provider for {@see self::test_processing_instructions()}.


/**
* Data provider.
*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
*
*
* @see self::test_serializes_processing_instructions()
* @see self::test_processing_instruction_normalization_is_idempotent()
*

pento pushed a commit that referenced this pull request Jul 10, 2026
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
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62687
GitHub commit: ca99fef

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Jul 10, 2026
@sirreal
sirreal deleted the html-api/update-processing-instruction-parse branch July 10, 2026 16:46
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jul 10, 2026
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
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.

3 participants