3 unstable releases

0.2.0 Aug 3, 2023
0.1.1 Jun 21, 2023
0.1.0 Jun 17, 2023

#2602 in Parser implementations

Download history 6/week @ 2024-01-13 3/week @ 2024-01-27 2/week @ 2024-02-03 19/week @ 2024-02-10 27/week @ 2024-02-17 28/week @ 2024-02-24 4/week @ 2024-03-02 32/week @ 2024-03-09 21/week @ 2024-03-16 27/week @ 2024-03-23 79/week @ 2024-03-30 31/week @ 2024-04-06 28/week @ 2024-04-13 21/week @ 2024-04-20 15/week @ 2024-04-27

96 downloads per month
Used in vitrine

Apache-2.0

30KB
468 lines

markdown-it-footnote.rs

crates.io

A markdown-it.rs plugin to process footnotes.

It is based on the pandoc definition:

Normal footnote:

Here is a footnote reference,[^1] and another.[^longnote]

Here is an inline note.^[my note is here!]

[^1]: Here is the footnote.

[^longnote]: Here's one with multiple blocks.

    Subsequent paragraphs are indented to show that they
belong to the previous footnote.

See the tests for more examples.

Usage

To load the full plugin:

let parser = &mut markdown_it::MarkdownIt::new();
markdown_it::plugins::cmark::add(parser);

markdown_it_footnote::add(parser);

let ast  = parser.parse("Example^[my note]");
let html = ast.render();

Alternatively, you can load the separate components:

let parser = &mut markdown_it::MarkdownIt::new();
markdown_it::plugins::cmark::add(parser);

markdown_it_footnote::definitions::add(md);
markdown_it_footnote::references::add(md);
markdown_it_footnote::inline::add(md);
markdown_it_footnote::collect::add(md);
markdown_it_footnote::back_refs::add(md);

Which have the following roles:

  • definitions: parse footnote definitions, e.g. [^1]: foo
  • references: parse footnote references, e.g. [^1]
  • inline: parse inline footnotes, e.g. ^[foo]
  • collect: collect footnote definitions (removing duplicate/unreferenced ones) and move them to be the last child of the root node.
  • back_refs: add anchor(s) to footnote definitions, with links back to the reference(s)

Dependencies

~8.5MB
~190K SLoC