pub fn extract_toc(doc: &Document) -> Vec<TocEntry>Expand description
Extract all top-level headings from a document as a flat list of TocEntry items.
- Explicit
{#id}from the ASTidfield is used as-is; otherwise the slug is derived from the heading text viaheading_slug. - Duplicate slugs receive
-1,-2, … suffixes in document order.
Slug parity with the renderer: the renderer increments its own slug counter for
every heading it encounters during the depth-first tree walk — including headings
that live inside blockquotes, admonitions, etc. This function replicates that walk
so that the counters stay in sync. Nested headings are not listed in the output
(callers expect a “structural” TOC), but their slugs are still counted so that the
numbers assigned to top-level headings match the id attributes in the rendered HTML.