Expand description
Structure similar to *emphasis*
with configurable markers of fixed length.
There are many structures in various Markdown flavors that can be implemented with this, namely:
*emphasis*
or_emphasis_
-><em>emphasis</em>
**strong**
or__strong__
-><strong>strong</strong>
~~strikethrough~~
-><s>strikethrough</s>
==marked==
-><mark>marked</mark>
++inserted++
-><ins>inserted</ins>
~subscript~
-><sub>subscript</sub>
^superscript^
-><sup>superscript</sup>
You add a custom structure by using add_with function, which takes following arguments:
MARKER
- marker characterLENGTH
- length of the opening/closing marker (can be 1, 2 or 3)CAN_SPLIT_WORD
- whether this structure can be found in the middle of the word (for example, note the difference betweenfoo*bar*baz
andfoo_bar_baz
in CommonMark - first one is an emphasis, second one isn’t)md
- parser instancef
- function that should return your custom Node
Here is an example of implementing superscript in your custom code:
use markdown_that::generics::inline::emph_pair;
use markdown_that::{MarkdownThat, Node, NodeValue, Renderer};
#[derive(Debug)]
struct Superscript;
impl NodeValue for Superscript {
fn render(&self, node: &Node, fmt: &mut dyn Renderer) {
fmt.open("sup", &node.attrs);
fmt.contents(&node.children);
fmt.close("sup");
}
}
let md = &mut MarkdownThat::new();
emph_pair::add_with::<'^', 1, true>(md, || Node::new(Superscript));
let html = md.parse("e^iπ^+1=0").render();
assert_eq!(html.trim(), "e<sup>iπ</sup>+1=0");
Note that these structures have lower priority than the rest of the rules,
e.g. *foo`bar*baz`
is parsed as *foo<code>bar*baz</code>
.