Struct maud_pulldown_cmark::Markdown
[−]
[src]
pub struct Markdown<'a, I: 'a + Iterator<Item=Event<'a>>> { // some fields omitted }
The adapter that allows rendering markdown inside a maud
macro.
Examples
let markdown = " 1. A list 2. With some 3. <span>Inline html</span> "; let mut buffer = String::new(); html!(buffer, { div { ^Markdown::from_string(markdown) } }).unwrap(); println!("{}", buffer);
let markdown = " 1. A list 2. With some 3. <span>Inline html</span> "; let events = Parser::new(markdown).map(|ev| match ev { // Escape inline html Event::Html(html) | Event::InlineHtml(html) => Event::Text(html), _ => ev, }); let mut buffer = String::new(); html!(buffer, { div { ^Markdown::from_events(events) } }).unwrap(); println!("{}", buffer);
Methods
impl<'a> Markdown<'a, Parser<'a>>
fn from_string(s: &'a str) -> Markdown<'a, Parser<'a>>
To allow rendering from a string.
impl<'a, I: 'a + Iterator<Item=Event<'a>>> Markdown<'a, I>
fn from_events(events: I) -> Markdown<'a, I>
To allow rendering from a stream of events (useful for modifying the output of the general parser).
fn with_header_ids(self) -> Markdown<'a, I>
Generate ids for all headers, lowercases the text in the header and replaces spaces with -.
Examples
let markdown = "# Header ## A Sub Header "; let mut buffer = String::new(); html!(buffer, { ^Markdown::from_string(markdown).with_header_ids() }).unwrap(); assert_eq!(buffer, "<h1 id=\"header\">Header</h1>\n<h2 id=\"a-sub-header\">A Sub Header</h2>\n");