Struct BlockState

Source
pub struct BlockState<'a, 'b>
where 'b: 'a,
{ pub src: &'b str, pub md: &'a MarkdownThat, 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 MarkdownThat

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 the 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 MarkdownThat, 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    fn run(state: &mut BlockState) -> Option<(Node, usize)> {
49        // get contents of a line number `state.line` and check it
50        let line = state.get_line(state.line).trim();
51        if !line.starts_with(CRAB_CLAW) {
52            return None;
53        }
54        if !line.ends_with(CRAB_CLAW) {
55            return None;
56        }
57
58        // require any number of `-` in between, but no less than 4
59        if line.len() < CRAB_CLAW.len() * 2 + 4 {
60            return None;
61        }
62
63        // and make sure no other characters are present there
64        let dashes = &line[CRAB_CLAW.len()..line.len() - CRAB_CLAW.len()];
65        if dashes.chars().any(|c| c != '-') {
66            return None;
67        }
68
69        // return new node and number of lines it occupies
70        Some((Node::new(BlockFerris), 1))
71    }
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> Freeze for BlockState<'a, 'b>

§

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 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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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,