| 1 | // Adds three custom plugins and runs them. |
| 2 | mod block_rule; |
| 3 | mod core_rule; |
| 4 | mod inline_rule; |
| 5 | |
| 6 | fn main() { |
| 7 | // create markdown parser |
| 8 | let md = &mut markdown_it::MarkdownIt::new(); |
| 9 | |
| 10 | // add commonmark syntax, you almost always want to do that |
| 11 | markdown_it::plugins::cmark::add(md); |
| 12 | |
| 13 | // add custom three rules described above |
| 14 | inline_rule::add(md); |
| 15 | block_rule::add(md); |
| 16 | core_rule::add(md); |
| 17 | |
| 18 | // and now you can use it |
| 19 | let html = md.parse(r#" |
| 20 | (\/) hello world (\/) |
| 21 | (\/)-------------(\/) |
| 22 | "#).render(); |
| 23 | |
| 24 | print!("{html}"); |
| 25 | |
| 26 | assert_eq!(html.trim(), r#" |
| 27 | <p><span class="ferris-inline">🦀</span> hello world <span class="ferris-inline">🦀</span></p> |
| 28 | <div class="ferris-block"><img src="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"></div> |
| 29 | <footer class="ferris-counter">There are 3 crabs lurking in this document.</footer> |
| 30 | "#.trim()); |
| 31 | } |