[wp-trac] [WordPress Trac] #61255: HTML API: Report depth of currently-matched element.

WordPress Trac noreply at wordpress.org
Thu May 23 22:49:39 UTC 2024


#61255: HTML API: Report depth of currently-matched element.
--------------------------------------+---------------------
 Reporter:  dmsnell                   |       Owner:  (none)
     Type:  feature request           |      Status:  new
 Priority:  normal                    |   Milestone:  6.6
Component:  HTML API                  |     Version:  trunk
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------
Description changed by dmsnell:

Old description:

> The HTML Processor should report on the depth of the currently-matched
> element so that calling code doesn't need to create its own
> interpretation and implementation of such depth.

New description:

 The HTML Processor maintains a stack of open elements, where every
 element, every `#text` node, every HTML comment, and other node is pushed
 and popped while traversing the document. The "depth" of each of these
 nodes represents how deep that stack is where the node appears.
 Unfortunately this information isn't exposed to calling code, which has
 led different projects to attempt to calculate this value externally. This
 isn't always trivial, but the HTML Processor could make it so by exposing
 the internal knowledge in a new method.

 In the attached patch, the `get_current_depth()` method returns just that.
 Since the processor always exists within a context, the depth includes
 nesting from the always-present `html` element and also the `body`, since
 currently the HTML Processor only supports parsing in the IN BODY context.

 This means that the depth reported for the `DIV` in `<div>` is 3, not 1,
 because its breadcrumbs path is `HTML > BODY > DIV`.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61255#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list