pub type RenderPlugins<'p> = RenderPlugins<'p>;👎Deprecated since 0.45.0: use
comrak::options::RenderPlugins instead of comrak::RenderPluginsExpand description
Deprecated alias: use options::RenderPlugins instead of RenderPlugins.
Aliased Type§
pub struct RenderPlugins<'p> {
pub codefence_syntax_highlighter: Option<&'p dyn SyntaxHighlighterAdapter>,
pub heading_adapter: Option<&'p dyn HeadingAdapter>,
}Fields§
§codefence_syntax_highlighter: Option<&'p dyn SyntaxHighlighterAdapter>Provide a syntax highlighter adapter implementation for syntax highlighting of codefence blocks.
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<'a>();\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