maud_pulldown_cmark

Struct Markdown

Source
pub struct Markdown<'a, I: 'a + Iterator<Item = Event<'a>>> { /* private fields */ }
Expand description

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 buffer = html! {
  div {
    (Markdown::from_string(markdown))
  }
};

println!("{}", buffer.into_string());
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 buffer = html! {
  div {
    (Markdown::from_events(events))
  }
};

println!("{}", buffer.into_string());

Implementations§

Source§

impl<'a> Markdown<'a, Parser<'a>>

Source

pub fn from_string(s: &'a str) -> Markdown<'a, Parser<'a>>

To allow rendering from a string.

Source§

impl<'a, I: 'a + Iterator<Item = Event<'a>>> Markdown<'a, I>

Source

pub 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).

Source

pub 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 buffer = html!(
  (Markdown::from_string(markdown).with_header_ids())
);

assert_eq!(buffer.into_string(), "<h1 id=\"header\">Header</h1>\n<h2 id=\"a-sub-header\">A Sub Header</h2>\n");

Trait Implementations§

Source§

impl<'a, I: 'a + Iterator<Item = Event<'a>>> RenderOnce for Markdown<'a, I>

Source§

fn render_once_to(self, w: &mut String)

Appends a representation of self to the given string, consuming self in the process. Read more
Source§

fn render_once(self) -> PreEscaped<String>

Renders self as a block of Markup, consuming it in the process.

Auto Trait Implementations§

§

impl<'a, I> Freeze for Markdown<'a, I>
where I: Freeze,

§

impl<'a, I> RefUnwindSafe for Markdown<'a, I>
where I: RefUnwindSafe,

§

impl<'a, I> Send for Markdown<'a, I>
where I: Send + Sync,

§

impl<'a, I> Sync for Markdown<'a, I>
where I: Sync,

§

impl<'a, I> Unpin for Markdown<'a, I>
where I: Unpin,

§

impl<'a, I> UnwindSafe for Markdown<'a, I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.