-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML API: Add method to create fragment at node #7348
HTML API: Add method to create fragment at node #7348
Conversation
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. |
7e0e922
to
8ccd0cb
Compare
8ccd0cb
to
9ac142f
Compare
This reverts commit ba9e218.
9f5a895
to
42f3df4
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This behavior can be tested with the playground and the html api debugger plugin. Interesting snippets:
|
Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
How does this relate to It seems like If yes: Should we deprecate |
Those are all good questions and they're not addressed in this PR, but are in #7777. I wanted to keep these two PRs independent because This method serves as an "advanced" way of creating fragments (with a different doctype, node, or in quirks mode), while #7777 changes this so that instead of There's some relevant conversation on #7777 #7777 (review). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving. Thank you for your explanations and inline comments, they've been instrumental in understanding how this works. The increased test coverage by html5lib is pretty impressive 👍
How would you like to land this? Should the commit message say Fixes #62357
and then we re-open the ticket and close it again with #7777, or should we do something else?
Thank you!
I don't feel too strongly, I this can be landed closing #62357, then #7777 could be against another ticket like "allow more fragment context in #7777 supersedes #7141. That PR was associated with #61576, but that was a general "HTAML API in 6.7" ticket. We can sort out #7777 later. |
Committed to Core in https://core.trac.wordpress.org/changeset/59444/. |
$fragment_processor->state->context_node = array( $fragment_processor->context_node->node_name, array() ); | ||
|
||
$attribute_names = $this->get_attribute_names_with_prefix( '' ); | ||
if ( null !== $attribute_names ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs say that get_attribute_names_with_prefix
returns null
when no tag opener is matched.
This got me thinking -- should we disallow create_fragment_at_current_node
from being called when the processor is paused on a tag closer?
(If we do, then we should be able to remove this guard, as it would be guaranteed that we're at a tag opener.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thought! This won't behave as expected on closers, and it seems like a strange thing to do in general.
Trac ticket: https://core.trac.wordpress.org/ticket/62357
Add a
create_fragment_at_current_node( string $html_fragment )
method. This method must be called when the processor is paused at a#tag
with some strict constraints:#tag
.IFRAME
,SCRIPT
,TITLE
, etc.).This supports work on
set_inner_html
in #7326 and #7742.#7777 is a follow-up that leverages this new method
::create_fragment
to make all fragments from a full parser, which is closer to the specification.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.