Make WordPress Core

Opened 8 months ago

Closed 8 months ago

Last modified 7 months 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: 6.6
Component: HTML API Keywords: has-patch needs-dev-note
Focuses: Cc:

Description

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

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


8 months ago
#1

  • Keywords has-patch added

Trac ticket: Core-61257

WIP

@jonsurrell commented on PR #6600:


8 months ago
#2

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

@dmsnell commented on PR #6600:


8 months ago
#3

@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
8 months 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 https://github.com/WordPress/wordpress-develop/pull/6600
Discussed in https://core.trac.wordpress.org/ticket/61257

Fixes #61257.
Props dmsnell, jonsurrell.

#6 @dmsnell
7 months ago

  • Keywords needs-dev-note added
Note: See TracTickets for help on using tickets.