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
impl HtmlConfigBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new HtmlConfigBuilder with default options.
§Examples
use html_generator::HtmlConfigBuilder;
let _ = HtmlConfigBuilder::new();Sourcepub fn with_syntax_highlighting(
self,
enable: bool,
theme: Option<String>,
) -> Self
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 highlightingtheme- 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"));Sourcepub fn with_language(self, language: impl Into<String>) -> Self
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");Sourcepub fn with_sanitization(self, enable: bool) -> Self
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);Sourcepub fn with_full_document(self, enable: bool) -> Self
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);Sourcepub fn with_max_buffer_size(self, size: usize) -> Self
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);Sourcepub fn with_math(self, enable: bool) -> Self
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);Sourcepub fn with_diagrams(self, enable: bool) -> Self
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);Sourcepub fn build(self) -> Result<HtmlConfig>
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).