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>
impl<'a, 'b> BlockState<'a, 'b>
pub fn new( src: &'b str, md: &'a MarkdownThat, root_ext: &'b mut RootExtSet, node: Node, ) -> Self
pub fn test_rules_at_line(&mut self) -> bool
pub fn is_empty(&self, line: usize) -> bool
pub fn skip_empty_lines(&self, from: usize) -> usize
Sourcepub fn line_indent(&self, line: usize) -> i32
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
Sourcepub fn get_line(&self, line: usize) -> &str
pub fn get_line(&self, line: usize) -> &str
return a single line, trimming initial spaces
Examples found in repository?
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 }
Sourcepub fn get_lines(
&self,
begin: usize,
end: usize,
indent: usize,
keep_last_lf: bool,
) -> (String, Vec<(usize, usize)>)
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).
pub fn get_map(&self, start_line: usize, end_line: usize) -> Option<SourcePos>
pub fn get_map_from_offsets( &self, start_pos: usize, end_pos: usize, ) -> Option<SourcePos>
Trait Implementations§
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> 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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.