pub struct Parser { /* private fields */ }
Expand description
A parser that reads markdown and convert it to AST (a vector of Token
s)
This AST can then be used by various renderes.
As this Parser uses Pulldown-cmark’s one, it should be able to parse most valid CommonMark variant of Markdown.
Compared to other Markdown parser, it might fail more often on invalid code, e.g. footnotes references that are not defined anywhere.
Examples
use crowbook::Parser;
let mut parser = Parser::new();
let result = parser.parse("Some *valid* Markdown[^1]\n\n[^1]: with a valid footnote");
assert!(result.is_ok());
use crowbook::Parser;
let mut parser = Parser::new();
let result = parser.parse("Some footnote pointing to nothing[^1] ");
assert!(result.is_err());
Implementations§
source§impl Parser
impl Parser
sourcepub fn from(book: &Book) -> Parser
pub fn from(book: &Book) -> Parser
Creates a parser with options from a book configuration file
sourcepub fn html_as_text(&mut self, b: bool)
pub fn html_as_text(&mut self, b: bool)
Enable/disable HTML as text
sourcepub fn set_source_file(&mut self, s: &str)
pub fn set_source_file(&mut self, s: &str)
Sets a parser’s source file
sourcepub fn parse_file<P: AsRef<Path>>(
&mut self,
filename: P,
yaml_block: Option<&mut String>
) -> Result<Vec<Token>>
pub fn parse_file<P: AsRef<Path>>( &mut self, filename: P, yaml_block: Option<&mut String> ) -> Result<Vec<Token>>
Parse a file and returns an AST or an error
sourcepub fn parse(
&mut self,
s: &str,
yaml: Option<&mut String>
) -> Result<Vec<Token>>
pub fn parse( &mut self, s: &str, yaml: Option<&mut String> ) -> Result<Vec<Token>>
Parse a string and returns an AST or an Error. If yaml is set to some string, fill it with frontmatter if it is found
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnwindSafe for Parser
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
Mutably borrows from an owned value. Read more