Struct crowbook::Parser [] [src]

pub struct Parser { /* fields omitted */ }

A parser that reads markdown and convert it to AST (a vector of Tokens)

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());Run
use crowbook::Parser;
let mut parser = Parser::new();
let result = parser.parse("Some footnote pointing to nothing[^1] ");
assert!(result.is_err());Run

Methods

impl Parser
[src]

Creates a parser

Sets a parser's source file

Parse a file and returns an AST or an error

Parse a string and returns an AST, or an Error.

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)