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: Add spawn fragment parser method #7348

Draft
wants to merge 21 commits into
base: trunk
Choose a base branch
from

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Sep 13, 2024

Work in progress

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

The HTML API has two ways of creating HTML processors, create_fragment and
create_full_parser.

create_fragment is a static method that creates a fragment parser from a very reasonable default context node, a BODY element.

However, it may be necessary to create a fragment parser with a different context node, for example when working with HTML inside of an SVG or TABLE tag may be parsed very differently.

One strong motivation for this is the implementation of a set_inner_html method which requires parsing an HTML fragment with the appropriate context node in order to change its contents.

Add a spawn_fragment_parser( string $html_fragment ) method. This method must be called when the processor is paused at a #tag with some strict constraints:

  • Must be paused on a #tag.
  • The opening and closing tags must appear in the HTML input (no virtual tokens).
  • No "self-contained" elements are allowed ( IFRAME, SCRIPT, TITLE, etc.).
 OK, but incomplete, skipped, or risky tests!
-Tests: 1500, Assertions: 1079, Skipped: 421.
+Tests: 1686, Assertions: 1222, Skipped: 464.

This supports work on set_inner_html in #7326 and #7742.


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

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/add-spawn-fragment-parser-method branch from 7e0e922 to 8ccd0cb Compare October 10, 2024 15:09
Squashed commit of the following:

commit 1cde425
Merge: 05ca2a4 8ad5281
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 20:40:05 2024 +0100

    Merge branch 'trunk' into html-api/fix-63390-seek

commit 05ca2a4
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 20:29:36 2024 +0100

    Remove context-node cases from open elements

    The context node is not pushed to the stack of open elements, and
    therefore does not need special handling.

commit 75ab9c2
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 20:27:57 2024 +0100

    Break at root-node when popping elements on seek

    The context node is not pushed to the stack of open elements,
    this code was either doing nothing or incorrect.

commit 90eb6e2
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 13:53:15 2024 +0100

    Use a temporary bookmark to avoid modifying tag processor internal state

commit b95e402
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 13:45:13 2024 +0100

    Restore private stack properties to private

commit d5a7d5c
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 13:40:18 2024 +0100

    Rework with tests for fragment and full processors

    Use a dataprovider to get a factory function for processors

commit f7af6e3
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 13:19:58 2024 +0100

    Add test seeking from SVG namespace

commit 388bf19
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 13:05:34 2024 +0100

    Add and improve HTML processor bookmark tests

commit d5bf14c
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 12:17:47 2024 +0100

    Add and improve comments

commit d181938
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 12:13:48 2024 +0100

    Fix fragment state reset for different context nodes

commit 9a0c017
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 12:05:43 2024 +0100

    Set parsing namespace correctly when seeking

commit 660dc85
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 11:49:21 2024 +0100

    Remove condition that may not be necessary

    This seems related to virutal tokens and it likely covered by the virtual token condition

commit 9af204c
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 11:47:56 2024 +0100

    Assert setting bookmark two

    This is consisten with the assertion on bookmark one

commit 851df38
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 11:47:17 2024 +0100

    Fix fragment parser bug that should reset breadcrumbs before seeking

commit 6106a56
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 11:46:49 2024 +0100

    Use do-while loop to iterate after first check

commit 744cf01
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Wed Nov 6 11:42:42 2024 +0100

    Add commentary around state resetting in seek

commit cb63bbc
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Tue Nov 5 19:51:29 2024 +0100

    Lint: remove empty line

commit 737bf92
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Tue Nov 5 19:49:01 2024 +0100

    Restore original bookmark matching

commit 89aa01b
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Tue Nov 5 19:47:16 2024 +0100

    Fix the issue

commit dc3f1e6
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Tue Nov 5 19:06:23 2024 +0100

    try fixes

commit 541b4f6
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Fri Oct 25 23:19:19 2024 +0200

    wip

commit 5d75bb7
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Fri Oct 25 23:15:51 2024 +0200

    Work on fix

commit f9777aa
Author: Jon Surrell <sirreal@users.noreply.github.com>
Date:   Fri Oct 25 22:51:44 2024 +0200

    Add failing test case
@sirreal sirreal force-pushed the html-api/add-spawn-fragment-parser-method branch from 9f5a895 to 42f3df4 Compare November 8, 2024 18:58
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.

1 participant