#61255 closed feature request (fixed)
HTML API: Report depth of currently-matched element.
| Reported by: | dmsnell | Owned by: | dmsnell |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.6 |
| Component: | HTML API | Version: | 6.6 |
| Severity: | normal | Keywords: | has-patch has-unit-tests needs-dev-note |
| Cc: | Focuses: |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: Core-61255.