#markdown #pulldown-cmark #toc #common-mark #github

pulldown-cmark-toc

Generate a table of contents from a Markdown document

8 releases (breaking)

0.7.0 Feb 24, 2025
0.6.0 Aug 24, 2024
0.5.0 Jun 26, 2024
0.4.0 Mar 31, 2024
0.1.1 Aug 2, 2020

#330 in Text processing

Download history 9/week @ 2024-12-07 2/week @ 2025-01-04 2/week @ 2025-02-01 5/week @ 2025-02-08 128/week @ 2025-02-22 27/week @ 2025-03-01 10/week @ 2025-03-08 1/week @ 2025-03-15

166 downloads per month
Used in 2 crates

MIT/Apache

18KB
300 lines

pulldown-cmark-toc

Crates.io Docs.rs Build Status

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.

Getting started

Add the pulldown-cmark-toc to your Cargo.toml.

cargo add pulldown-cmark-toc

Usage

use pulldown_cmark_toc::TableOfContents;

let text = r#"
# Heading

## Subheading

## Subheading with `code`
"#;

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

License

Licensed under either of

at your option.

Dependencies

~2.9–4MB
~74K SLoC