Struct comrak::ComrakRenderPlugins
source · [−]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<'a>();\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
sourceimpl Debug for ComrakRenderPlugins<'_>
impl Debug for ComrakRenderPlugins<'_>
sourceimpl<'a> Default for ComrakRenderPlugins<'a>
impl<'a> Default for ComrakRenderPlugins<'a>
sourcefn default() -> ComrakRenderPlugins<'a>
fn default() -> ComrakRenderPlugins<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl<'a> !RefUnwindSafe for ComrakRenderPlugins<'a>
impl<'a> !Send for ComrakRenderPlugins<'a>
impl<'a> !Sync for ComrakRenderPlugins<'a>
impl<'a> Unpin for ComrakRenderPlugins<'a>
impl<'a> !UnwindSafe for ComrakRenderPlugins<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more