pub struct ComrakRenderPlugins<'a> {
    pub codefence_syntax_highlighter: Option<&'a dyn SyntaxHighlighterAdapter>,
}
Expand description

Plugins for alternative rendering.

Fields

codefence_syntax_highlighter: Option<&'a dyn SyntaxHighlighterAdapter>

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

use std::collections::HashMap;
let options = ComrakOptions::default();
let mut plugins = ComrakPlugins::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 highlight(&self, lang: Option<&str>, code: &str) -> String {
        String::from(format!("<span class=\"lang-{}\">{}</span>", lang.unwrap(), code))
    }

fn build_pre_tag(&self, attributes: &HashMap<String, String>) -> String {
        String::from("<pre lang=\"rust\">")
    }

fn build_code_tag(&self, attributes: &HashMap<String, String>) -> String {
        String::from("<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");

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.