Struct markdown_it::MarkdownIt
source · pub struct MarkdownIt {
pub block: BlockParser,
pub inline: InlineParser,
pub link_formatter: Box<dyn LinkFormatter>,
pub ext: MarkdownItExtSet,
pub max_indent: i32,
/* private fields */
}
Expand description
Main parser struct, created once and reused for parsing multiple documents.
Fields§
§block: BlockParser
Block-level tokenizer.
inline: InlineParser
Inline-level tokenizer.
link_formatter: Box<dyn LinkFormatter>
Link validator and formatter.
ext: MarkdownItExtSet
Storage for custom data used in plugins.
max_indent: i32
Maximum allowed indentation for syntax blocks default i32::MAX, indented code blocks will set this to 4
Implementations§
source§impl MarkdownIt
impl MarkdownIt
sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/ferris/main.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
fn main() {
// create markdown parser
let md = &mut markdown_it::MarkdownIt::new();
// add commonmark syntax, you almost always want to do that
markdown_it::plugins::cmark::add(md);
// add custom three rules described above
inline_rule::add(md);
block_rule::add(md);
core_rule::add(md);
// and now you can use it
let html = md.parse(r#"
(\/) hello world (\/)
(\/)-------------(\/)
"#).render();
print!("{html}");
assert_eq!(html.trim(), r#"
<p><span class="ferris-inline">🦀</span> hello world <span class="ferris-inline">🦀</span></p>
<div class="ferris-block"><img src="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"></div>
<footer class="ferris-counter">There are 3 crabs lurking in this document.</footer>
"#.trim());
}
sourcepub fn parse(&self, src: &str) -> Node
pub fn parse(&self, src: &str) -> Node
Examples found in repository?
examples/ferris/main.rs (lines 19-22)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
fn main() {
// create markdown parser
let md = &mut markdown_it::MarkdownIt::new();
// add commonmark syntax, you almost always want to do that
markdown_it::plugins::cmark::add(md);
// add custom three rules described above
inline_rule::add(md);
block_rule::add(md);
core_rule::add(md);
// and now you can use it
let html = md.parse(r#"
(\/) hello world (\/)
(\/)-------------(\/)
"#).render();
print!("{html}");
assert_eq!(html.trim(), r#"
<p><span class="ferris-inline">🦀</span> hello world <span class="ferris-inline">🦀</span></p>
<div class="ferris-block"><img src="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"></div>
<footer class="ferris-counter">There are 3 crabs lurking in this document.</footer>
"#.trim());
}
sourcepub fn add_rule<T: CoreRule>(
&mut self
) -> RuleBuilder<'_, fn(_: &mut Node, _: &MarkdownIt)>
pub fn add_rule<T: CoreRule>( &mut self ) -> RuleBuilder<'_, fn(_: &mut Node, _: &MarkdownIt)>
pub fn has_rule<T: CoreRule>(&mut self) -> bool
pub fn remove_rule<T: CoreRule>(&mut self)
Trait Implementations§
source§impl Debug for MarkdownIt
impl Debug for MarkdownIt
Auto Trait Implementations§
impl !RefUnwindSafe for MarkdownIt
impl Send for MarkdownIt
impl Sync for MarkdownIt
impl Unpin for MarkdownIt
impl !UnwindSafe for MarkdownIt
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.