Skip to main content

MarkdownOptions

Struct MarkdownOptions 

Source
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: bool

Enable or disable processing of custom blocks.

§enable_syntax_highlighting: bool

Enable or disable syntax highlighting for code blocks.

§enable_enhanced_tables: bool

Enable or disable enhanced table formatting.

§syntax_theme: Option<String>

Optional custom theme for syntax highlighting.

§allow_unsafe_html: bool

Allow 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: CustomBlockConfig

Configuration for custom block rendering.

§max_input_size: usize

Maximum 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: bool

Rewrite 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>

Source

pub fn new() -> Self

Creates a new instance with default values.

Source

pub fn with_custom_blocks(self, enable: bool) -> Self

Enables or disables custom blocks.

Source

pub fn with_syntax_highlighting(self, enable: bool) -> Self

Enables or disables syntax highlighting for code blocks.

Source

pub fn with_enhanced_tables(self, enable: bool) -> Self

Enables or disables enhanced table formatting.

Source

pub fn with_custom_theme(self, theme: String) -> Self

Sets a custom theme for syntax highlighting.

Source

pub fn with_comrak_options(self, options: Options<'a>) -> Self

Sets custom Comrak options.

Also syncs allow_unsafe_html from render.unsafe.

Source

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.

Source

pub fn with_custom_block_config(self, config: CustomBlockConfig) -> Self

Sets the custom block configuration.

Source

pub fn with_max_input_size(self, size: usize) -> Self

Sets the maximum input size in bytes. 0 means no limit.

Source

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).

Source

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.

Source

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.

Source

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
  1. enhanced_tables requires comrak.extension.table.
  2. syntax_theme, if set, must name a theme bundled with syntect (feature-gated).
  3. syntax_theme set but enable_syntax_highlighting = false is a silent no-op — rejected so the mistake surfaces.
  4. sanitizer_config set but allow_unsafe_html = true skips sanitization entirely — rejected.
  5. header_ids prefix must not contain whitespace or any of " ' < > & = (would break the emitted id="…").
  6. sanitizer_config.extra_tags / extra_tag_attributes keys must be valid HTML names; attribute lists must contain only valid HTML names.
  7. sanitizer_config.extra_generic_attributes must be valid HTML names.
  8. sanitizer_config.extra_allowed_classes keys must be valid HTML names; class values must be non-empty and free of whitespace / quote characters.
  9. custom_block_config override 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>

Source§

fn clone(&self) -> MarkdownOptions<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MarkdownOptions<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for MarkdownOptions<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MarkdownOptions<'a>

§

impl<'a> RefUnwindSafe for MarkdownOptions<'a>

§

impl<'a> Send for MarkdownOptions<'a>

§

impl<'a> Sync for MarkdownOptions<'a>

§

impl<'a> Unpin for MarkdownOptions<'a>

§

impl<'a> UnsafeUnpin for MarkdownOptions<'a>

§

impl<'a> UnwindSafe for MarkdownOptions<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.