Skip to content
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: Make non-body fragment creation methods private #7907

Closed

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Nov 28, 2024

See this comment:

Reopening to reconsider the interface and behavior of fragments in the HTML API. I spoke at length with @dmsnell and we decided to make the new methods (from this ticket and #62357) for creating non-body fragments private and consider some changes to the implementations that diverge from the HTML standard on fragment parsing.

A good example is the following:

WP_HTML_Processor::create_fragment( '<p>If this P is considered to be under the context node, that cannot be represented in HTML.', '<p>' );

As in implemented, this produces the following tree ("under" the context node of

):

└─P
  └─#text If this P is considered to be under the context node, that cannot be represented in HTML.

Through the lens of the HTML API, P > P is not something that can ever be represented as HTML and may not make sense to show as a context. The DOM APIs (where fragment parsing comes from) do support this behavior because the DOM supports many arbitrary ways of nesting elements that are unrepresentable in HTML.

This reverts or updates parts of the following changesets:

Follow-up https://core.trac.wordpress.org/changeset/59444
Follow-up https://core.trac.wordpress.org/changeset/59467

Trac ticket: https://core.trac.wordpress.org/ticket/62584


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.

Copy link

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

@sirreal sirreal force-pushed the html-api/disallow-non-body-contexts branch from 0b4bc80 to 77e3f74 Compare November 28, 2024 12:44
@sirreal
Copy link
Member Author

sirreal commented Nov 28, 2024

See #7912 for exploration on how to prevent unrepresentable HTML documents from being created as fragments.

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

Too bad we have to back up on this one, but it makes sense 👍

Code looks good. I'll commit.

@ockham
Copy link
Contributor

ockham commented Nov 28, 2024

Committed to Core in https://core.trac.wordpress.org/changeset/59469.

@ockham ockham closed this Nov 28, 2024
@sirreal sirreal deleted the html-api/disallow-non-body-contexts branch November 28, 2024 16:19
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.

2 participants