Struct comrak::RenderPluginsBuilder
source · pub struct RenderPluginsBuilder<'p> { /* private fields */ }
Expand description
Builder for RenderPlugins
.
Implementations§
source§impl<'p> RenderPluginsBuilder<'p>
impl<'p> RenderPluginsBuilder<'p>
sourcepub fn codefence_syntax_highlighter(
&mut self,
value: Option<&'p dyn SyntaxHighlighterAdapter>
) -> &mut Self
pub fn codefence_syntax_highlighter( &mut self, value: Option<&'p dyn SyntaxHighlighterAdapter> ) -> &mut Self
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<'a>();\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");
sourcepub fn heading_adapter(
&mut self,
value: Option<&'p dyn HeadingAdapter>
) -> &mut Self
pub fn heading_adapter( &mut self, value: Option<&'p dyn HeadingAdapter> ) -> &mut Self
Optional heading adapter
sourcepub fn build(&self) -> Result<RenderPlugins<'p>, RenderPluginsBuilderError>
pub fn build(&self) -> Result<RenderPlugins<'p>, RenderPluginsBuilderError>
Trait Implementations§
source§impl<'p> Clone for RenderPluginsBuilder<'p>
impl<'p> Clone for RenderPluginsBuilder<'p>
source§fn clone(&self) -> RenderPluginsBuilder<'p>
fn clone(&self) -> RenderPluginsBuilder<'p>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<'p> !RefUnwindSafe for RenderPluginsBuilder<'p>
impl<'p> Send for RenderPluginsBuilder<'p>
impl<'p> Sync for RenderPluginsBuilder<'p>
impl<'p> Unpin for RenderPluginsBuilder<'p>
impl<'p> !UnwindSafe for RenderPluginsBuilder<'p>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more