Crate markdown_it_heading_anchors

Source
Expand description

Add id attribute (slug) to headings.

use markdown_it_heading_anchors::{
    add_with_options, HeadingAnchorOptions, AnchorPosition
};

let md = &mut markdown_it::MarkdownIt::new();
markdown_it::plugins::cmark::add(md);
let mut options = HeadingAnchorOptions::default();
options.position = AnchorPosition::Start;
options.inner_html = String::from("¶");
add_with_options(md, options);

assert_eq!(
    md.parse("# heading\n\n# heading").render(),
    "<h1>\
    <a aria-hidden=\"true\" class=\"anchor\" id=\"heading\" href=\"#heading\">¶</a>\
    heading</h1>\n\
    <h1>\
    <a aria-hidden=\"true\" class=\"anchor\" id=\"heading-1\" href=\"#heading-1\">¶</a>\
    heading</h1>\n",
);

Structs§

HeadingAnchor
AST node for a heading anchor
HeadingAnchorOptions
Options for the heading anchor plugin.

Enums§

AnchorPosition
Where to add the anchor, within the heading children.

Functions§

add
Add the heading anchor plugin to MarkdownIt.
add_with_options
Add the heading anchor plugin to MarkdownIt, with options.