Expand description

Generate a table of contents from a Markdown document.

By default the heading anchor calculation (aka the “slugification”) is done in a way that attempts to mimic GitHub’s (undocumented) behavior. (Though you can customize this with your own slug::Slugify implementation).

§Examples

use pulldown_cmark_toc::TableOfContents;

let text = "# Heading\n\n## Subheading\n\n## Subheading with `code`\n";

let toc = TableOfContents::new(text);
assert_eq!(
    toc.to_cmark(),
    r#"- [Heading](#heading)
  - [Subheading](#subheading)
  - [Subheading with `code`](#subheading-with-code)
"#
);

Structs§

Enums§

Traits§

  • A trait to specify the anchor calculation.