Make WordPress Core

Opened 4 weeks ago

Closed 4 weeks ago

Last modified 4 weeks ago

#61257 closed feature request (fixed)

HTML API: Indicate if a matched element expects a closing tag/token.

Reported by: dmsnell's profile dmsnell Owned by: dmsnell's profile dmsnell
Milestone: 6.6 Priority: normal
Severity: normal Version: trunk
Component: HTML API Keywords: has-patch
Focuses: Cc:


Some tags open an element that could contain other tags. Some tags and tokens appear only transiently on the stack and are immediately popped off.

Previously this has all been occurring through a custom logical check inside the HTML Processor's step() function, but it would be helpful to have a way to check on this generally and reuse the logic.

Change History (5)

This ticket was mentioned in PR #6600 on WordPress/wordpress-develop by @dmsnell.

4 weeks ago

  • Keywords has-patch added

Trac ticket: Core-61257


@jonsurrell commented on PR #6600:

4 weeks ago

I pushed some tests for this, I'd like to get this in. What's missing to land this?

@dmsnell commented on PR #6600:

4 weeks ago

@sirreal I combined your negative-assertion tests into one since they all behaved in the same way. I think it helps keep the tests organized but I'm happy to bring yours back if you disagree.

#4 @dmsnell
4 weeks ago

  • Owner set to dmsnell
  • Resolution set to fixed
  • Status changed from new to closed

In 58192:

HTML API: Add expects_closer() method to HTML Processor

This patch adds a new method, WP_HTML_Processor->expects_closer() to indicate
if the currently-matched node expects to find a closing token. For example, a
DIV element expects a closing </div> tag, but an <img> expects none, because
it's a void element. Similarly, #text nodes and HTML comments only appear as
unitary nodes on the stack of open elements. Once proceeding further in the
document they are immediately removed without any closing tag.

This new method serves as a helper to indicate whether or not to expect the
closer, as this can be more complicated than it seems, and calling code
shouldn't have to build custom interpretations and implementations. Instead,
the HTML Processor ought to export its internal knowledge to make it easy for
consuming code and projects.

Developed in
Discussed in

Fixes #61257.
Props dmsnell, jonsurrell.

Note: See TracTickets for help on using tickets.