| 1 | //! Parser itself + stuff that allows you to extend it. |
| 2 | //! |
| 3 | //! In order to understand how this parser works, you need to understand the concept |
| 4 | //! of Rule Chains. "Rule Chain" is an ordered set of functions that get executed |
| 5 | //! sequentially. This is an example of a Rule Chain: |
| 6 | //! |
| 7 | //! ```rust |
| 8 | //! let rules : Vec<fn(&mut String)> = vec![ |
| 9 | //! |s| { s.push_str("hello"); }, |
| 10 | //! |s| { s.push(','); }, |
| 11 | //! |s| { s.push(' '); }, |
| 12 | //! |s| { s.push_str("world"); }, |
| 13 | //! |s| { s.push('!'); }, |
| 14 | //! ]; |
| 15 | //! dbg!(rules.iter().fold(String::new(), |mut s, f| { f(&mut s); s })); |
| 16 | //! ``` |
| 17 | //! |
| 18 | //! The example above builds a string using 5 independent functions. You can extend |
| 19 | //! it by pushing your own function in that vector that manipulate the state (String) |
| 20 | //! in any way you like. |
| 21 | //! |
| 22 | //! MarkdownIt parser consists of three Rule Chains: |
| 23 | //! - [inline] (where functions get executed on every character) |
| 24 | //! - [block] (where functions get executed on every line) |
| 25 | //! - [core] (where functions get executed once per document) |
| 26 | //! |
| 27 | //! You can extend each one of these chains by using |
| 28 | //! [md.inline.add_rule](inline::InlineParser::add_rule), |
| 29 | //! [md.block.add_rule](block::BlockParser::add_rule) or |
| 30 | //! [md.add_rule](crate::MarkdownIt::add_rule) respectively. |
| 31 | //! |
| 32 | //! These are examples of the rules in each chain (view source to see implementation): |
| 33 | //! - [inline rule](crate::plugins::cmark::inline::autolink) - autolink |
| 34 | //! - [block rule](crate::plugins::cmark::block::hr) - thematic break |
| 35 | //! - [core rule](crate::plugins::sourcepos) - source mapping |
| 36 | //! |
| 37 | pub mod block; |
| 38 | pub mod core; |
| 39 | pub mod extset; |
| 40 | pub mod inline; |
| 41 | pub mod linkfmt; |
| 42 | |
| 43 | pub(super) mod main; |
| 44 | pub(super) mod node; |
| 45 | pub(super) mod renderer; |