#markdown #pulldown-cmark #heading-id

markdown-heading-id

Filter for pulldown-cmark which converts headings with custom ID

1 unstable release

0.1.0 Jan 8, 2021

#11 in #pulldown-cmark

Download history 507/week @ 2024-08-30 617/week @ 2024-09-06 616/week @ 2024-09-13 842/week @ 2024-09-20 583/week @ 2024-09-27 900/week @ 2024-10-04 664/week @ 2024-10-11 967/week @ 2024-10-18 928/week @ 2024-10-25 878/week @ 2024-11-01 584/week @ 2024-11-08 757/week @ 2024-11-15 421/week @ 2024-11-22 512/week @ 2024-11-29 403/week @ 2024-12-06 531/week @ 2024-12-13

2,001 downloads per month

MIT license

10KB
135 lines

markdown-heading-id

Filter for the Parser of crate pulldown-cmark

This crate provides a filter of Parser which converts headings with custom ID into HTML. It uses the syntax of headings IDs defined in Extended Syntax of Markdown.

For example, if we have the following fragment of Markdown

## Heading {#heading-id}

then it is converted into a fragment of HTML below:

<h2 id="heading-id">Heading</h2>

Usage

It is easy to use a filter provided by this crate. HeadingId wraps an instance of Parser and it can be passed to push_html or write_html, because HeadingId implements the trait Iterator<Item=Event<'a>>. An example is given below:

use pulldown_cmark::Parser;
use pulldown_cmark::html::push_html;
use markdown_heading_id::HeadingId;

let parser = Parser::new("## Heading {#heading-id}");
let parser = HeadingId::new(parser);
let mut buf = String::new();
push_html(&mut buf, parser);
assert_eq!(buf.trim_end(), r#"<h2 id="heading-id">Heading</h2>"#);

License: MIT

Dependencies

~2.5MB
~41K SLoC