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