Doclingdocling 2.127.0 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
26 small wins to finish your pathNext lesson

Seeing what Docling saw

Exported Markdown is what the document looks like. iterate_items is what it is, and it is the tool to reach for every time the output surprises you.

A converted document is a tree of pieces. iterate_items walks that tree in reading order and hands you each piece with how deeply it is nested.

Example
from docling.document_converter import DocumentConverter

document = DocumentConverter().convert("shipping.md").document
for item, depth in document.iterate_items():
    print(depth, item.self_ref, item.label)

Six pieces. Four sit at depth one and two at depth two, because the two list items live inside a list. self_ref is that piece's address inside the document and label is what Docling decided it was; both get a lesson of their own, in 5 and 6.

Adding the text

Example
for item, depth in document.iterate_items():
    print(depth, item.label, "|", item.text[:40])

Now the shape and the words are side by side. Shipping came out as a title and the two lower headings as section headers, which is Docling reading the hash count rather than guessing.

Use it on the file that surprised you

Run the same loop on the HTML file and the table appears as a single piece.

Example
html = DocumentConverter().convert("refunds.html").document
for item, depth in html.iterate_items():
    print(depth, item.self_ref, item.label)

One entry for the whole table, at #/tables/0, and no entry for any of its rows. A table is a piece with a grid inside it rather than a pile of text pieces, which is why lesson 8 can hand it straight to pandas. The depths also differ from the Markdown file: this backend nests everything under the title, so the table sits three levels down.

This is the first thing to run when an export looks wrong. Exported text hides the difference between a heading Docling found and a heading it missed. This loop does not.

Where a piece is not

The loop does not show #/groups/0, the list that holds the two list items. Groups are containers rather than content, so they are skipped here and reached through the tree in lesson 7.

Try it yourself
  • Add a third level of heading to shipping.md and see what label it gets.
  • Run the loop on orders.csv and count the pieces.
  • Replace the dashes in the Markdown list with 1. and 2., then look at the depths again.

This is what real progress feels like.