pub struct MarkdownOptions<'a> {
pub comrak_options: Options<'a>,
pub enable_custom_blocks: bool,
pub enable_syntax_highlighting: bool,
pub enable_enhanced_tables: bool,
pub syntax_theme: Option<String>,
pub allow_unsafe_html: bool,
pub custom_block_config: CustomBlockConfig,
pub max_input_size: usize,
pub header_ids: Option<String>,
pub sanitizer_config: Option<SanitizerConfig>,
pub enable_diagrams: bool,
}Expand description
Options for configuring Markdown processing behavior.
Fields§
§comrak_options: Options<'a>Options for the underlying Comrak Markdown parser.
enable_custom_blocks: boolEnable or disable processing of custom blocks.
enable_syntax_highlighting: boolEnable or disable syntax highlighting for code blocks.
enable_enhanced_tables: boolEnable or disable enhanced table formatting.
syntax_theme: Option<String>Optional custom theme for syntax highlighting.
allow_unsafe_html: boolAllow raw HTML pass-through in Markdown output.
When true, raw HTML in the Markdown source is passed through
unchanged. When false (the default), output is sanitized with
ammonia to strip dangerous tags while preserving safe
structural HTML (our generated alert divs, tables, code
blocks, etc.).
custom_block_config: CustomBlockConfigConfiguration for custom block rendering.
max_input_size: usizeMaximum input size in bytes. 0 means no limit.
header_ids: Option<String>Enable automatic id attributes on headings for anchor links.
When Some(prefix), headings get id="prefix-slug" attributes.
Use Some("") for bare id="slug" without a prefix.
None disables header IDs (default).
sanitizer_config: Option<SanitizerConfig>Optional extensions to the default HTML sanitizer allow-list.
When None, the cached default sanitizer is used — the hot
path. When Some, a fresh ammonia::Builder is constructed
per call that merges the defaults with the extras declared in
SanitizerConfig.
enable_diagrams: boolRewrite fenced code blocks tagged mermaid, geojson,
topojson, or stl into sanitizer-safe containers that a
client-side JS hydrator (see
crate::hydration_script_html) replaces with inline SVG.
Off by default so existing users with plain mermaid code
blocks continue to see syntax-highlighted source. Opt in via
MarkdownOptions::with_diagrams.
Implementations§
Source§impl<'a> MarkdownOptions<'a>
impl<'a> MarkdownOptions<'a>
Sourcepub fn with_custom_blocks(self, enable: bool) -> Self
pub fn with_custom_blocks(self, enable: bool) -> Self
Enables or disables custom blocks.
Sourcepub fn with_syntax_highlighting(self, enable: bool) -> Self
pub fn with_syntax_highlighting(self, enable: bool) -> Self
Enables or disables syntax highlighting for code blocks.
Sourcepub fn with_enhanced_tables(self, enable: bool) -> Self
pub fn with_enhanced_tables(self, enable: bool) -> Self
Enables or disables enhanced table formatting.
Sourcepub fn with_custom_theme(self, theme: String) -> Self
pub fn with_custom_theme(self, theme: String) -> Self
Sets a custom theme for syntax highlighting.
Sourcepub fn with_comrak_options(self, options: Options<'a>) -> Self
pub fn with_comrak_options(self, options: Options<'a>) -> Self
Sets custom Comrak options.
Also syncs allow_unsafe_html from render.unsafe.
Sourcepub fn with_unsafe_html(self, enable: bool) -> Self
pub fn with_unsafe_html(self, enable: bool) -> Self
Enables or disables raw HTML pass-through.
This is the authoritative control. Call after
with_comrak_options if you need to override.
Sourcepub fn with_custom_block_config(self, config: CustomBlockConfig) -> Self
pub fn with_custom_block_config(self, config: CustomBlockConfig) -> Self
Sets the custom block configuration.
Sourcepub fn with_max_input_size(self, size: usize) -> Self
pub fn with_max_input_size(self, size: usize) -> Self
Sets the maximum input size in bytes. 0 means no limit.
Sourcepub fn with_header_ids(self, prefix: impl Into<String>) -> Self
pub fn with_header_ids(self, prefix: impl Into<String>) -> Self
Enables automatic id attributes on headings.
Pass "" for bare slugs, or a prefix like "user-content-"
to namespace them (GitHub-style).
Sourcepub fn with_sanitizer_config(self, config: SanitizerConfig) -> Self
pub fn with_sanitizer_config(self, config: SanitizerConfig) -> Self
Extends the HTML sanitizer allow-list.
Setting this disables the cached default sanitizer for calls
made with these options — a fresh ammonia::Builder is
constructed per call that merges the defaults with the extras.
Only used when allow_unsafe_html is false.
Sourcepub fn with_diagrams(self, enable: bool) -> Self
pub fn with_diagrams(self, enable: bool) -> Self
Enables or disables diagram code-block rendering (mermaid,
geojson, topojson, stl). See crate::diagrams for the
supported info strings and the client-side hydration
contract.
Sourcepub fn validate(&self) -> Result<(), Vec<(String, ValidationError)>>
pub fn validate(&self) -> Result<(), Vec<(String, ValidationError)>>
Validates that options are internally consistent and that every string the pipeline will splice into HTML is well- formed.
Uses crate::validation::Validator so every failing
check is reported in one pass — callers get the full list
of problems, not just the first. Each entry in the returned
Vec is (field_name, ValidationError).
§Checks
enhanced_tablesrequirescomrak.extension.table.syntax_theme, if set, must name a theme bundled with syntect (feature-gated).syntax_themeset butenable_syntax_highlighting = falseis a silent no-op — rejected so the mistake surfaces.sanitizer_configset butallow_unsafe_html = trueskips sanitization entirely — rejected.header_idsprefix must not contain whitespace or any of" ' < > & =(would break the emittedid="…").sanitizer_config.extra_tags/extra_tag_attributeskeys must be valid HTML names; attribute lists must contain only valid HTML names.sanitizer_config.extra_generic_attributesmust be valid HTML names.sanitizer_config.extra_allowed_classeskeys must be valid HTML names; class values must be non-empty and free of whitespace / quote characters.custom_block_configoverride values must be non-empty and free of whitespace / quote characters (class overrides) or non-empty (title overrides).
§Errors
Returns Err(errors) when any check fails. The pipeline
converts the list into a single
MarkdownError::InvalidOptionsError via the From impl
in crate::error.
Trait Implementations§
Source§impl<'a> Clone for MarkdownOptions<'a>
impl<'a> Clone for MarkdownOptions<'a>
Source§fn clone(&self) -> MarkdownOptions<'a>
fn clone(&self) -> MarkdownOptions<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more