| 1 | use crate::{MarkdownIt, Node}; |
| 2 | |
| 3 | /// Each member of core rule chain must implement this trait |
| 4 | pub trait CoreRule : 'static { |
| 5 | fn run(root: &mut Node, md: &MarkdownIt); |
| 6 | } |
| 7 | |
| 8 | macro_rules! rule_builder { |
| 9 | ($var: ident) => { |
| 10 | /// Adjust positioning of a newly added rule in the chain. |
| 11 | pub struct RuleBuilder<'a, T> { |
| 12 | item: &'a mut crate::common::ruler::RuleItem<crate::common::TypeKey, T> |
| 13 | } |
| 14 | |
| 15 | impl<'a, T> RuleBuilder<'a, T> { |
| 16 | pub(crate) fn new(item: &'a mut crate::common::ruler::RuleItem<crate::common::TypeKey, T>) -> Self { |
| 17 | Self { item } |
| 18 | } |
| 19 | |
| 20 | pub fn before<U: $var>(self) -> Self { |
| 21 | self.item.before(crate::common::TypeKey::of::<U>()); |
| 22 | self |
| 23 | } |
| 24 | |
| 25 | pub fn after<U: $var>(self) -> Self { |
| 26 | self.item.after(crate::common::TypeKey::of::<U>()); |
| 27 | self |
| 28 | } |
| 29 | |
| 30 | pub fn before_all(self) -> Self { |
| 31 | self.item.before_all(); |
| 32 | self |
| 33 | } |
| 34 | |
| 35 | pub fn after_all(self) -> Self { |
| 36 | self.item.after_all(); |
| 37 | self |
| 38 | } |
| 39 | |
| 40 | pub fn alias<U: $var>(self) -> Self { |
| 41 | self.item.alias(crate::common::TypeKey::of::<U>()); |
| 42 | self |
| 43 | } |
| 44 | |
| 45 | pub fn require<U: $var>(self) -> Self { |
| 46 | self.item.require(crate::common::TypeKey::of::<U>()); |
| 47 | self |
| 48 | } |
| 49 | } |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | rule_builder!(CoreRule); |
| 54 | |
| 55 | pub(crate) use rule_builder; |