Skip to main content

HtmlConfigBuilder

Struct HtmlConfigBuilder 

Source
pub struct HtmlConfigBuilder { /* private fields */ }
Expand description

Builder for constructing HtmlConfig instances.

Provides a fluent interface for creating and customizing HTML configuration options.

§Examples

use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_language("en-GB")
    .with_full_document(true)
    .build()
    .unwrap();
assert!(cfg.generate_full_document);

Implementations§

Source§

impl HtmlConfigBuilder

Source

pub fn new() -> Self

Creates a new HtmlConfigBuilder with default options.

§Examples
use html_generator::HtmlConfigBuilder;

let _ = HtmlConfigBuilder::new();
Source

pub fn with_syntax_highlighting( self, enable: bool, theme: Option<String>, ) -> Self

Enables or disables syntax highlighting for code blocks.

§Arguments
  • enable - Whether to enable syntax highlighting
  • theme - Optional theme name for syntax highlighting
§Examples
use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_syntax_highlighting(true, Some("monokai".into()))
    .build()
    .unwrap();
assert_eq!(cfg.syntax_theme.as_deref(), Some("monokai"));
Source

pub fn with_language(self, language: impl Into<String>) -> Self

Sets the language for generated content.

§Examples
use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_language("fr-FR")
    .build()
    .unwrap();
assert_eq!(cfg.language, "fr-FR");
Source

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

Enables or disables HTML sanitization via ammonia.

When enabled alongside allow_unsafe_html, dangerous elements are stripped while safe tags are preserved.

§Examples
use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_sanitization(true)
    .build()
    .unwrap();
assert!(cfg.sanitize_html);
Source

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

Enables or disables full HTML5 document wrapping.

When enabled, the output is wrapped in <!DOCTYPE html> with <head> (containing meta/JSON-LD) and <body>.

§Examples
use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_full_document(true)
    .build()
    .unwrap();
assert!(cfg.generate_full_document);
Source

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

Sets the maximum buffer size for file I/O operations.

§Examples
use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_max_buffer_size(8 * 1024 * 1024)
    .build()
    .unwrap();
assert_eq!(cfg.max_buffer_size, 8 * 1024 * 1024);
Source

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

Enables or disables server-side LaTeX → MathML rendering.

When enabled, $..$ and $$..$$ spans in the rendered HTML are replaced with <math>…</math> elements. Browsers render MathML natively, so no client-side JS is needed. Requires the math feature (on by default).

§Examples
use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_math(true)
    .build()
    .unwrap();
assert!(cfg.enable_math);
Source

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

Enables or disables Mermaid diagram passthrough.

When enabled, \u{60}\u{60}\u{60}mermaid fenced code blocks are rewritten from <pre><code class="language-mermaid"> to <pre class="mermaid"> so client-side mermaid.js renders them.

§Examples
use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_diagrams(true)
    .build()
    .unwrap();
assert!(cfg.enable_diagrams);
Source

pub fn build(self) -> Result<HtmlConfig>

Builds the configuration, validating all settings.

§Examples
use html_generator::HtmlConfigBuilder;

let cfg = HtmlConfigBuilder::new()
    .with_language("en-GB")
    .build()
    .unwrap();
assert_eq!(cfg.language, "en-GB");
§Errors

Returns the first crate::error::HtmlError::InvalidInput produced by HtmlConfig::validate (e.g. an unknown language code or a max_input_size below the minimum).

Trait Implementations§

Source§

impl Debug for HtmlConfigBuilder

Source§

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

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

impl Default for HtmlConfigBuilder

Source§

fn default() -> HtmlConfigBuilder

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

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