Skip to main content

collect_headings

Function collect_headings 

Source
pub fn collect_headings<'a>(
    root: Node<'a>,
    prefix: Option<&str>,
) -> Vec<Heading>
Expand description

Walks the AST and returns one Heading per heading node, in document order.

prefix mirrors MarkdownOptions::header_ids:

  • None or Some("") → bare slug ("introduction").
  • Some(p)format!("{p}{slug}") ("user-content-introduction").

Uses comrak’s own Anchorizer so dedup behaviour (-1, -2 suffixes for repeated headings) matches the rendered HTML.