pub struct BlockState<'a, 'b>where
    'b: 'a,{
    pub src: &'b str,
    pub md: &'a MarkdownIt,
    pub root_ext: &'b mut RootExtSet,
    pub node: Node,
    pub line_offsets: Vec<LineOffset>,
    pub blk_indent: usize,
    pub line: usize,
    pub line_max: usize,
    pub tight: bool,
    pub list_indent: Option<u32>,
    pub level: u32,
}
Expand description

Sandbox object containing data required to parse block structures.

Fields§

§src: &'b str

Markdown source.

§md: &'a MarkdownIt

Link to parser instance.

§root_ext: &'b mut RootExtSet§node: Node

Current node, your rule is supposed to add children to it.

§line_offsets: Vec<LineOffset>§blk_indent: usize

Current block content indent (for example, if we are inside a list, it would be positioned after list marker).

§line: usize

Current line in src.

§line_max: usize

Maximum allowed line in src.

§tight: bool

True if there are no empty lines between paragraphs, used to toggle loose/tight mode for lists.

§list_indent: Option<u32>

indent of the current list block.

§level: u32

Implementations§

source§

impl<'a, 'b> BlockState<'a, 'b>

source

pub fn new( src: &'b str, md: &'a MarkdownIt, root_ext: &'b mut RootExtSet, node: Node ) -> Self

source

pub fn test_rules_at_line(&mut self) -> bool

source

pub fn is_empty(&self, line: usize) -> bool

source

pub fn skip_empty_lines(&self, from: usize) -> usize

source

pub fn line_indent(&self, line: usize) -> i32

return line indent of specific line, taking into account blockquotes and lists; it may be negative if a text has less indentation than current list item

source

pub fn get_line(&self, line: usize) -> &str

return a single line, trimming initial spaces

Examples found in repository?
examples/ferris/block_rule.rs (line 50)
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    fn run(state: &mut BlockState) -> Option<(Node, usize)> {
        // get contents of a line number `state.line` and check it
        let line = state.get_line(state.line).trim();
        if !line.starts_with(CRAB_CLAW) { return None; }
        if !line.ends_with(CRAB_CLAW)   { return None; }

        // require any number of `-` in between, but no less than 4
        if line.len() < CRAB_CLAW.len() * 2 + 4 { return None; }

        // and make sure no other characters are present there
        let dashes = &line[CRAB_CLAW.len()..line.len()-CRAB_CLAW.len()];
        if dashes.chars().any(|c| c != '-') { return None; }

        // return new node and number of lines it occupies
        Some((
            Node::new(BlockFerris),
            1,
        ))
    }
source

pub fn get_lines( &self, begin: usize, end: usize, indent: usize, keep_last_lf: bool ) -> (String, Vec<(usize, usize)>)

Cut a range of lines begin..end (not including end) from the source without preceding indent. Returns a string (lines) plus a mapping (start of each line in result -> start of each line in source).

source

pub fn get_map(&self, start_line: usize, end_line: usize) -> Option<SourcePos>

source

pub fn get_map_from_offsets( &self, start_pos: usize, end_pos: usize ) -> Option<SourcePos>

Trait Implementations§

source§

impl<'a, 'b> Debug for BlockState<'a, 'b>where 'b: 'a,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, 'b> !RefUnwindSafe for BlockState<'a, 'b>

§

impl<'a, 'b> !Send for BlockState<'a, 'b>

§

impl<'a, 'b> !Sync for BlockState<'a, 'b>

§

impl<'a, 'b> Unpin for BlockState<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for BlockState<'a, 'b>

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