Crate pulldown_cmark_toc

Source
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§

GitHubSlugifier
A slugifier that attempts to mimic GitHub’s behavior.
Heading
Represents a heading.
Options
Configuration options to use when rendering the Table of Contents.
TableOfContents
Represents a Table of Contents.

Enums§

HeadingLevel
ItemSymbol
Which symbol to use when rendering Markdown list items.

Traits§

Slugify
A trait to specify the anchor calculation.