https://github.com/rossmacarthur/pulldown-cmark-toc
Generate a table of contents from a Markdown document
https://github.com/rossmacarthur/pulldown-cmark-toc
cmark markdown rust table-of-contents
Last synced: over 1 year ago
JSON representation
Generate a table of contents from a Markdown document
- Host: GitHub
- URL: https://github.com/rossmacarthur/pulldown-cmark-toc
- Owner: rossmacarthur
- License: apache-2.0
- Created: 2020-08-02T12:52:52.000Z (about 6 years ago)
- Default Branch: trunk
- Last Pushed: 2025-02-24T07:04:35.000Z (over 1 year ago)
- Last Synced: 2025-04-13T16:08:55.300Z (over 1 year ago)
- Topics: cmark, markdown, rust, table-of-contents
- Language: Rust
- Homepage:
- Size: 46.9 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# pulldown-cmark-toc
[](https://crates.io/crates/pulldown-cmark-toc)
[](https://docs.rs/pulldown-cmark-toc)
[](https://github.com/rossmacarthur/pulldown-cmark-toc/actions/workflows/build.yaml?branch=trunk)
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
```rust
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
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.