| 1 | //! Emphasis and strong emphasis |
| 2 | //! |
| 3 | //! looks like `*this*` or `__that__` |
| 4 | //! |
| 5 | //! <https://spec.commonmark.org/0.30/#emphasis-and-strong-emphasis> |
| 6 | use crate::generics::inline::emph_pair; |
| 7 | use crate::{MarkdownIt, Node, NodeValue, Renderer}; |
| 8 | |
| 9 | #[derive(Debug)] |
| 10 | pub struct Em { |
| 11 | pub marker: char |
| 12 | } |
| 13 | |
| 14 | impl NodeValue for Em { |
| 15 | fn render(&self, node: &Node, fmt: &mut dyn Renderer) { |
| 16 | fmt.open("em", &node.attrs); |
| 17 | fmt.contents(&node.children); |
| 18 | fmt.close("em"); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | #[derive(Debug)] |
| 23 | pub struct Strong { |
| 24 | pub marker: char |
| 25 | } |
| 26 | |
| 27 | impl NodeValue for Strong { |
| 28 | fn render(&self, node: &Node, fmt: &mut dyn Renderer) { |
| 29 | fmt.open("strong", &node.attrs); |
| 30 | fmt.contents(&node.children); |
| 31 | fmt.close("strong"); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | pub fn add(md: &mut MarkdownIt) { |
| 36 | emph_pair::add_with::<'*', 1, true> (md, || Node::new(Em { marker: '*' })); |
| 37 | emph_pair::add_with::<'_', 1, false> (md, || Node::new(Em { marker: '_' })); |
| 38 | emph_pair::add_with::<'*', 2, true> (md, || Node::new(Strong { marker: '*' })); |
| 39 | emph_pair::add_with::<'_', 2, false> (md, || Node::new(Strong { marker: '_' })); |
| 40 | } |