Struct MarkdownThat

Source
pub struct MarkdownThat {
    pub block: BlockParser,
    pub inline: InlineParser,
    pub link_formatter: Box<dyn LinkFormatter>,
    pub ext: MarkdownThatExtSet,
    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: MarkdownThatExtSet

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 MarkdownThat

Source

pub fn new() -> Self

Examples found in repository?
examples/ferris/main.rs (line 8)
6fn main() {
7    // create markdown parser
8    let md = &mut markdown_that::MarkdownThat::new();
9
10    // add commonmark syntax, you almost always want to do that
11    markdown_that::plugins::cmark::add(md);
12
13    // add custom three rules described above
14    inline_rule::add(md);
15    block_rule::add(md);
16    core_rule::add(md);
17
18    // and now you can use it
19    let html = md
20        .parse(
21            r#"
22(\/) hello world (\/)
23(\/)-------------(\/)
24    "#,
25        )
26        .render();
27
28    print!("{html}");
29
30    assert_eq!(html.trim(), r#"
31<p><span class="ferris-inline">🦀</span> hello world <span class="ferris-inline">🦀</span></p>
32<div class="ferris-block"><img src="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"></div>
33<footer class="ferris-counter">There are 3 crabs lurking in this document.</footer>
34    "#.trim());
35}
Source

pub fn parse(&self, src: &str) -> Node

Examples found in repository?
examples/ferris/main.rs (lines 20-25)
6fn main() {
7    // create markdown parser
8    let md = &mut markdown_that::MarkdownThat::new();
9
10    // add commonmark syntax, you almost always want to do that
11    markdown_that::plugins::cmark::add(md);
12
13    // add custom three rules described above
14    inline_rule::add(md);
15    block_rule::add(md);
16    core_rule::add(md);
17
18    // and now you can use it
19    let html = md
20        .parse(
21            r#"
22(\/) hello world (\/)
23(\/)-------------(\/)
24    "#,
25        )
26        .render();
27
28    print!("{html}");
29
30    assert_eq!(html.trim(), r#"
31<p><span class="ferris-inline">🦀</span> hello world <span class="ferris-inline">🦀</span></p>
32<div class="ferris-block"><img src="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg"></div>
33<footer class="ferris-counter">There are 3 crabs lurking in this document.</footer>
34    "#.trim());
35}
Source

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

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

Source§

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

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

impl Default for MarkdownThat

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &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)

Converts &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> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

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

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,