Struct RenderPlugins

pub struct RenderPlugins<'p> { pub codefence_renderers: HashMap<String, &'p dyn CodefenceRendererAdapter>, pub codefence_syntax_highlighter: Option<&'p dyn SyntaxHighlighterAdapter>, pub heading_adapter: Option<&'p dyn HeadingAdapter> }

Plugins for alternative rendering.

Fields

codefence_renderers: HashMap<String, &'p dyn CodefenceRendererAdapter>

Provide language-specific renderers for codefence blocks.

math codefence blocks are handled separately by Comrak's built-in math renderer, so entries keyed by "math" in this map are not used.

codefence_syntax_highlighter: Option<&'p dyn SyntaxHighlighterAdapter>

Provide a syntax highlighter adapter implementation for syntax highlighting of codefence blocks.

# use comrak::{markdown_to_html, Options, options::Plugins, markdown_to_html_with_plugins};
# use comrak::adapters::SyntaxHighlighterAdapter;
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::{self, Write};
let options = Options::default();
let mut plugins = Plugins::default();
let input = "```rust\nfn main<'a>();\n```";

assert_eq!(markdown_to_html_with_plugins(input, &options, &plugins),
           "<pre><code class=\"language-rust\">fn main&lt;'a&gt;();\n</code></pre>\n");

pub struct MockAdapter {}
impl SyntaxHighlighterAdapter for MockAdapter {
    fn write_highlighted(&self, output: &mut dyn fmt::Write, lang: Option<&str>, code: &str) -> fmt::Result {
        write!(output, "<span class=\"lang-{}\">{}</span>", lang.unwrap(), code)
    }

    fn write_pre_tag<'s>(&self, output: &mut dyn fmt::Write, _attributes: HashMap<&'static str, Cow<'s, str>>) -> fmt::Result {
        output.write_str("<pre lang=\"rust\">")
    }

    fn write_code_tag<'s>(&self, output: &mut dyn fmt::Write, _attributes: HashMap<&'static str, Cow<'s, str>>) -> fmt::Result {
        output.write_str("<code class=\"language-rust\">")
    }
}

let adapter = MockAdapter {};
plugins.render.codefence_syntax_highlighter = Some(&adapter);

assert_eq!(markdown_to_html_with_plugins(input, &options, &plugins),
           "<pre lang=\"rust\"><code class=\"language-rust\"><span class=\"lang-rust\">fn main<'a>();\n</span></code></pre>\n");
heading_adapter: Option<&'p dyn HeadingAdapter>

Optional heading adapter

Trait Implementations

impl Debug for RenderPlugins<'_>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<'p> Clone for RenderPlugins<'p>

fn clone(&self) -> Self

impl<'p> Default for RenderPlugins<'p>

fn default() -> Self

Auto Trait Implementations

impl<'p> !RefUnwindSafe for RenderPlugins<'p>

impl<'p> !UnwindSafe for RenderPlugins<'p>

impl<'p> Freeze for RenderPlugins<'p>

impl<'p> Send for RenderPlugins<'p>

impl<'p> Sync for RenderPlugins<'p>

impl<'p> Unpin for RenderPlugins<'p>

impl<'p> UnsafeUnpin for RenderPlugins<'p>

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for RenderPlugins<'p> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for RenderPlugins<'p> where T: ?Sized,

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

impl<T> CloneToUninit for RenderPlugins<'p> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for RenderPlugins<'p>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for RenderPlugins<'p> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for RenderPlugins<'p> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for RenderPlugins<'p> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for RenderPlugins<'p> where U: TryFrom<T>,

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