#61255 closed feature request (fixed)
HTML API: Report depth of currently-matched element.
Reported by: | dmsnell | Owned by: | dmsnell |
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | 6.6 |
Component: | HTML API | Keywords: | has-patch has-unit-tests needs-dev-note |
Focuses: | Cc: |
Description (last modified by )
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
.
Change History (6)
This ticket was mentioned in PR #6589 on WordPress/wordpress-develop by @dmsnell.
7 months ago
#1
- Keywords has-patch has-unit-tests added
#3
@
7 months ago
- Owner set to dmsnell
- Resolution set to fixed
- Status changed from new to closed
In 58191:
#6
@
6 months ago
Dev note incorporated into Updates to the HTML API (public preview)
Trac ticket: Core-61255.