Expand description
Flattening a document’s structural tree into an index-ordered list.
Pure and network-free, the way crate::drive::sheets::a1 is: this is the
module where the subtle bugs live, so it must be testable without a
wiremock server. body.content[] is a recursive forest — a table holds
rows, which hold cells, which hold more structural elements, including
more tables — and both drive docs info and drive docs read need it
walked exactly once, the same way.
Two rules govern the walk and both matter:
- A container is emitted before its contents. A table yields one
ElementKind::Tableelement carrying the table’s own[start, end)— which is what addresses the whole table — followed by each cell’s paragraphs. Without the container, a table is invisible in the flat list except as an unexplained index gap. - Text is trimmed of its paragraph terminator; indices never are.
Every Docs paragraph’s final
textRunends in\n, and that newline occupies one index unit. Rendering it would put a blank line after every row; subtracting it fromend_indexwould make the reported indices lie about the document. So exactly one of the two is adjusted.
This module deliberately computes no index of its own — it only
reports what the server sent. Docs indices are UTF-16 code units and Rust
strings are UTF-8, so any index derived here would be wrong for
astral-plane characters in a way that corrupts silently rather than
failing. The write path avoids the problem the same way, by addressing
insertions with endOfSegmentLocation rather than a number.
Structs§
- DocElement
- One structural element, flattened out of the document tree.
- Heading
- A heading paragraph, for the
docs infooutline. - TabOutline
- Aggregate counts and the heading outline for one tab.
Enums§
- Element
Kind - What kind of thing a flattened element is.
Functions§
- flatten
- Walks
body.contentdepth-first, emitting every structural element in document-index order, containers before their contents. - flatten_
content - Like
flatten, but over a bare content slice rather than aBody. - outline
- Counts and outlines one tab.