Crates.io | markdown-it-footnote |
lib.rs | markdown-it-footnote |
version | 0.2.0 |
source | src |
created_at | 2023-06-17 22:43:46.384552 |
updated_at | 2023-08-03 16:55:38.365509 |
description | A markdown-it plugin for parsing footnotes |
homepage | |
repository | https://github.com/chrisjsewell/markdown-it-plugins.rs |
max_upload_size | |
id | 893160 |
size | 51,093 |
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.
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)