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

source

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());
}
source

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());
}
source

pub fn add_rule<T: CoreRule>( &mut self ) -> RuleBuilder<'_, fn(_: &mut Node, _: &MarkdownIt)>

Examples found in repository?
examples/ferris/core_rule.rs (line 63)
61
62
63
64
pub fn add(md: &mut MarkdownIt) {
    // insert this rule into parser
    md.add_rule::<FerrisCounterRule>();
}
source

pub fn has_rule<T: CoreRule>(&mut self) -> bool

source

pub fn remove_rule<T: CoreRule>(&mut self)

Trait Implementations§

source§

impl Debug for MarkdownIt

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for MarkdownIt

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for Twhere T: Any,

source§

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>

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)

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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T, Global>) -> Arc<dyn Any + Send + Sync, Global>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.