Struct crowbook::Parser
[−]
[src]
pub struct Parser { /* fields omitted */ }
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());
Methods
impl Parser
[src]
pub fn new() -> Parser
[src]
Creates a parser
pub fn from(book: &Book) -> Parser
[src]
Creates a parser with options from a book configuration file
pub fn html_as_text(&mut self, b: bool)
[src]
Enable/disable HTML as text
pub fn set_source_file(&mut self, s: &str)
[src]
Sets a parser's source file
pub fn parse_file<P: AsRef<Path>>(&mut self, filename: P) -> Result<Vec<Token>>
[src]
Parse a file and returns an AST or an error
pub fn parse(&mut self, s: &str) -> Result<Vec<Token>>
[src]
Parse a string and returns an AST an Error.
pub fn parse_inline(&mut self, s: &str) -> Result<Vec<Token>>
[src]
Parse an inline string and returns a list of Token
.
This function removes the outermost Paragraph
in most of the
cases, as it is meant to be used for an inline string (e.g. metadata)
pub fn features(&self) -> Features
[src]
Returns the list of features used by this parser