comrak

Type Alias ComrakRenderPlugins

Source
pub type ComrakRenderPlugins<'a> = RenderPlugins<'a>;
Expand description

Legacy naming of RenderPlugins

Aliased Type§

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

Fields§

§codefence_syntax_highlighter: Option<&'a dyn SyntaxHighlighterAdapter>

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

use std::collections::HashMap;
use std::io::{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 Write, lang: Option<&str>, code: &str) -> io::Result<()> {
        write!(output, "<span class=\"lang-{}\">{}</span>", lang.unwrap(), code)
    }

    fn write_pre_tag(&self, output: &mut dyn Write, _attributes: HashMap<String, String>) -> io::Result<()> {
        output.write_all(b"<pre lang=\"rust\">")
    }

    fn write_code_tag(&self, output: &mut dyn Write, _attributes: HashMap<String, String>) -> io::Result<()> {
        output.write_all(b"<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<&'a dyn HeadingAdapter>

Optional heading adapter