Make WordPress Core

Changes between Initial Version and Version 2 of Ticket #61255


Ignore:
Timestamp:
05/23/2024 10:49:39 PM (11 months ago)
Author:
dmsnell
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #61255

    • Property Keywords has-patch has-unit-tests added
  • Ticket #61255 – Description

    initial v2  
    1 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.
     1The 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.
     2
     3In 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.
     4
     5This means that the depth reported for the `DIV` in `<div>` is 3, not 1, because its breadcrumbs path is `HTML > BODY > DIV`.