Skip to main content

Module toc

Module toc 

Source
Expand description

Table of Contents extraction and Markdown generation.

§Workflow

  1. Parse the document with core::parse()
  2. Call extract_toc to get a flat list of TocEntry items
  3. Call generate_toc_markdown to produce the fenced TOC block
  4. Call replace_toc_in_text to update or insert the block in the source

Structs§

TocEntry
A single entry in the extracted Table of Contents.

Enums§

TocReplaceResult
Result of attempting to replace an existing TOC block in source text.

Functions§

extract_toc
Extract all top-level headings from a document as a flat list of TocEntry items.
generate_toc_markdown
Generate a Markdown TOC block wrapped in <!-- TOC --> / <!-- /TOC --> markers.
heading_slug
Generate a GitHub-compatible URL slug from heading text.
replace_toc_in_text
Attempt to find and replace an existing <!-- TOC -->...<!-- /TOC --> block in current_text with new_toc.