| 1 | //! Code spans |
| 2 | //! |
| 3 | //! `` `looks like this` `` |
| 4 | //! |
| 5 | //! <https://spec.commonmark.org/0.30/#code-span> |
| 6 | use crate::generics::inline::code_pair; |
| 7 | use crate::{MarkdownIt, Node, NodeValue, Renderer}; |
| 8 | |
| 9 | #[derive(Debug)] |
| 10 | pub struct CodeInline { |
| 11 | pub marker: char, |
| 12 | pub marker_len: usize, |
| 13 | } |
| 14 | |
| 15 | impl NodeValue for CodeInline { |
| 16 | fn render(&self, node: &Node, fmt: &mut dyn Renderer) { |
| 17 | fmt.open("code", &node.attrs); |
| 18 | fmt.contents(&node.children); |
| 19 | fmt.close("code"); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | pub fn add(md: &mut MarkdownIt) { |
| 24 | code_pair::add_with::<'`'>(md, |len| Node::new(CodeInline { |
| 25 | marker: '`', |
| 26 | marker_len: len, |
| 27 | })); |
| 28 | } |