Skip to main content

HtmlConfig

Struct HtmlConfig 

Source
pub struct HtmlConfig {
Show 15 fields pub enable_syntax_highlighting: bool, pub syntax_theme: Option<String>, pub minify_output: bool, pub add_aria_attributes: bool, pub generate_structured_data: bool, pub max_input_size: usize, pub language: String, pub generate_toc: bool, pub allow_unsafe_html: bool, pub sanitize_html: bool, pub generate_full_document: bool, pub max_buffer_size: usize, pub encoding: String, pub enable_math: bool, pub enable_diagrams: bool,
}
Expand description

Configuration options for HTML generation.

Controls various aspects of the HTML generation process including syntax highlighting, accessibility features, and output formatting.

§Examples

use html_generator::HtmlConfig;

let cfg = HtmlConfig::default();
assert!(cfg.add_aria_attributes);
assert_eq!(cfg.language, "en-GB");

Fields§

§enable_syntax_highlighting: bool

Enable syntax highlighting for code blocks

§syntax_theme: Option<String>

Theme to use for syntax highlighting

§minify_output: bool

Minify the generated HTML output

§add_aria_attributes: bool

Automatically add ARIA attributes for accessibility

§generate_structured_data: bool

Generate structured data (JSON-LD) based on content

§max_input_size: usize

Maximum size (in bytes) for input content

§language: String

Language for generated content

§generate_toc: bool

Enable table of contents generation

§allow_unsafe_html: bool

Allow raw HTML passthrough in Markdown conversion.

When false (the default), raw HTML tags in Markdown input are stripped from the output, preventing XSS when processing untrusted content. Set to true only when the Markdown source is fully trusted.

§sanitize_html: bool

Sanitize raw HTML using ammonia instead of stripping it.

When true and allow_unsafe_html is also true, the library runs ammonia over the final output to strip dangerous elements (<script>, onclick, etc.) while preserving safe tags like <div>, <span>, and <img>. This provides a secure middle-ground for user-authored HTML.

Has no effect when allow_unsafe_html is false (HTML is already stripped by the Markdown renderer).

§generate_full_document: bool

Wrap output in a full HTML5 document.

When true, the pipeline wraps the generated body in:

<!DOCTYPE html>
<html lang="{language}">
<head><meta charset="utf-8"><title>…</title>{meta}{json-ld}</head>
<body>{content}</body>
</html>

SEO meta tags and JSON-LD are placed in <head>, and the language field is injected as the lang attribute. When false (the default), only an HTML fragment is returned.

§max_buffer_size: usize

Maximum buffer size for file I/O operations (default: 16MB).

Controls the upper bound on buffer allocation when reading input files. Adjust this if you need to process unusually large documents or want to constrain memory usage.

§encoding: String

The encoding for file I/O (defaults to “utf-8”).

This field is used by markdown_file_to_html when reading or writing files. In-memory functions ignore it.

§enable_math: bool

Render $..$ and $$..$$ LaTeX math spans to inline MathML.

Pure server-side: no client-side JavaScript bundle required, browsers render MathML natively. Powered by pulldown-latex behind the math feature (on by default). When false, math spans are passed through as-is.

§enable_diagrams: bool

Rewrite \u{60}\u{60}\u{60}mermaid fenced code blocks for client-side mermaid.js.

The CommonMark engine emits these as <pre><code class="language-mermaid">…</code></pre>. With this flag on, the post-processing step rewrites them to <pre class="mermaid">…</pre> so the standard mermaid.js loader picks them up. The page must still include <script type="module">…mermaid.initialize…</script> for the diagrams to actually render.

Implementations§

Source§

impl HtmlConfig

Source

pub fn builder() -> HtmlConfigBuilder

Creates a new HtmlConfig using the builder pattern.

§Examples
use html_generator::HtmlConfig;

let config = HtmlConfig::builder()
    .with_syntax_highlighting(true, Some("monokai".to_string()))
    .with_language("en-GB")
    .build()
    .unwrap();
Source

pub fn validate(&self) -> Result<()>

Validates the configuration settings.

Checks that all configuration values are within acceptable ranges and conform to required formats.

§Returns

Returns Ok(()) if the configuration is valid, or an appropriate error if validation fails.

§Examples
use html_generator::HtmlConfig;

let cfg = HtmlConfig::default();
cfg.validate().unwrap();
§Errors

Returns crate::error::HtmlError::InvalidInput if language is not a valid BCP 47 code or max_input_size is below constants::MIN_INPUT_SIZE.

Trait Implementations§

Source§

impl Clone for HtmlConfig

Source§

fn clone(&self) -> HtmlConfig

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 HtmlConfig

Source§

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

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

impl Default for HtmlConfig

Source§

fn default() -> Self

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

impl Eq for HtmlConfig

Source§

impl From<MarkdownConfig> for HtmlConfig

Source§

fn from(mc: MarkdownConfig) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for HtmlConfig

Source§

fn eq(&self, other: &HtmlConfig) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HtmlConfig

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more