pub trait Visitor {
// Required methods
fn begin(&mut self, region: &Region) -> Result<(), Error>;
fn end(&mut self, region: &Region) -> Result<(), Error>;
fn text(&mut self, text: &str) -> Result<(), Error>;
fn line_break(&mut self) -> Result<(), Error>;
fn code(&mut self, text: &str) -> Result<(), Error>;
// Provided methods
fn with_visited_str(self, s: &str) -> Result<Self, Error>
where Self: Sized { ... }
fn with_parsed_str(self, parser: &Parser, s: &str) -> Result<Self, Error>
where Self: Sized { ... }
}Required Methods§
fn begin(&mut self, region: &Region) -> Result<(), Error>
fn end(&mut self, region: &Region) -> Result<(), Error>
fn text(&mut self, text: &str) -> Result<(), Error>
fn line_break(&mut self) -> Result<(), Error>
fn code(&mut self, text: &str) -> Result<(), Error>
Provided Methods§
Sourcefn with_visited_str(self, s: &str) -> Result<Self, Error>where
Self: Sized,
fn with_visited_str(self, s: &str) -> Result<Self, Error>where
Self: Sized,
Visit a Matthewdown string.
§Arguments
s- The string of Matthewdown to visit.
§Example
use matthewdown::Visitor;
let result = matthewdown::HtmlVisitor::new()
.with_visited_str(r#"
1. Bullet 1
2. Bullet 2
"#)
.unwrap()
.into_output();
assert_eq!(result, "<ol><li>Bullet 1</li><li>Bullet 2</li></ol>");Sourcefn with_parsed_str(self, parser: &Parser, s: &str) -> Result<Self, Error>where
Self: Sized,
fn with_parsed_str(self, parser: &Parser, s: &str) -> Result<Self, Error>where
Self: Sized,
Visit a Matthewdown string using a particular parser.
§Arguments
parser- The parser to use.s- The string of Matthewdown to visit.
§Example
// Make a normal parser...
let good_parser = matthewdown::Parser::default();
// Make a parser that doesn't understand any parsing rules...
let bad_parser = matthewdown::Parser::blank();
use matthewdown::Visitor;
// Using the good parser works
assert!(matthewdown::HtmlVisitor::new()
.with_parsed_str(&good_parser, "Hello!")
.is_ok());
// Using the bad parser doesn't
assert!(matthewdown::HtmlVisitor::new()
.with_parsed_str(&bad_parser, "Hello!")
.is_err());