Struct markdown_it::parser::block::BlockState
source · 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>
impl<'a, 'b> BlockState<'a, 'b>
pub fn new( src: &'b str, md: &'a MarkdownIt, 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 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,
))
}
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> !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, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
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>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
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)
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.