7 releases (breaking)

0.6.0 Aug 24, 2024
0.5.0 Jun 26, 2024
0.4.0 Mar 31, 2024
0.3.0 Aug 11, 2023
0.1.1 Aug 2, 2020

#241 in Text processing

Download history 6/week @ 2024-07-23 7/week @ 2024-07-30 1/week @ 2024-08-13 130/week @ 2024-08-20 12/week @ 2024-08-27 8/week @ 2024-09-10 7/week @ 2024-09-17 25/week @ 2024-09-24 3/week @ 2024-10-01

440 downloads per month
Used in 2 crates

MIT/Apache

18KB
301 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

~3–4MB
~75K SLoC