Struct RenderPlugins
#[non_exhaustive]
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.
mathcodefence 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::{SyntaxHighlightMeta, SyntaxHighlighterAdapter}; use std::borrow::Cow; use std::collections::BTreeMap; 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, highlight: &SyntaxHighlightMeta<'_>) -> fmt::Result { write!(output, "<span class=\"lang-{}\">{}</span>", highlight.lang, highlight.code) } fn write_pre_tag<'s>(&self, output: &mut dyn fmt::Write, _highlight: &SyntaxHighlightMeta<'_>, _attributes: BTreeMap<&str, Cow<'s, str>>) -> fmt::Result { output.write_str("<pre lang=\"rust\">") } fn write_code_tag<'s>(&self, output: &mut dyn fmt::Write, _highlight: &SyntaxHighlightMeta<'_>, _attributes: BTreeMap<&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