Skip to main content

HtmlParseOptions

Struct HtmlParseOptions 

Source
pub struct HtmlParseOptions {
    pub max_element_depth: u32,
    pub max_text_bytes: u64,
    pub scripting_enabled: bool,
    pub discard_bom: bool,
    pub iframe_srcdoc: bool,
    pub recovery_mode: bool,
    pub encoding_override: Option<String>,
    pub encoding_sniff_window: usize,
}
Expand description

Options for the lenient HTML5 parser.

Construct via HtmlParseOptions::default() and override individual fields. Defaults are tuned for the common case (browser-equivalent output, lenient recovery).

HTML parsing differs from XML in that recovery is the normal mode — most real-world HTML is malformed and the WHATWG spec mandates “do something sensible anyway.” recovery_mode therefore defaults to true (inverted from crate::ParseOptions).

Fields§

§max_element_depth: u32

Reject inputs deeper than this — DoS protection. html5ever itself has no built-in depth limit; we enforce it inside the sink. Default: 256.

§max_text_bytes: u64

Maximum total bytes of accumulated text content across the whole document. Caps adversarial inputs that try to blow up memory through repeated entity expansion or massive text nodes. Default: 10 MB.

§scripting_enabled: bool

Treat the parser as if scripting were enabled. Affects how <noscript> content is parsed: when true, <noscript> content is treated as raw text and not parsed as elements (matching what a browser with JS enabled would see). When false, <noscript> content is parsed normally. Default: true — most scrapers want the JS-enabled view.

§discard_bom: bool

Discard a leading byte-order mark if present in the input. Default: true.

§iframe_srcdoc: bool

Treat input as if it came from an iframe srcdoc attribute. Affects quirks-mode determination from DOCTYPE. Default: false.

§recovery_mode: bool

Continue past parse errors instead of returning Err. Recovery is the normal mode for HTML — most callers want this on. Default: true (inverted vs. crate::ParseOptions, which defaults to strict because XML is a strict format).

When false, the first parse error reported by html5ever causes the parser to return Err from finish(). Useful for HTML linters and strict validators.

§encoding_override: Option<String>

Override the WHATWG byte-stream encoding-sniffing result with a caller-supplied label (e.g. from an HTTP Content-Type header). Wins over BOM and meta-charset detection.

Accepts any WHATWG encoding label — "UTF-8", "windows-1252", "Shift_JIS", etc. Unknown labels route through encoding_rs (when the full-encodings feature is on).

Default: None (let the sniffer decide).

§encoding_sniff_window: usize

Maximum bytes the meta-charset prescan looks at when no caller-supplied encoding and no BOM are present. WHATWG recommends 1024. Increase only for documents with very long <head> sections that push the <meta charset> past the default window.

Default: 1024.

Trait Implementations§

Source§

impl Clone for HtmlParseOptions

Source§

fn clone(&self) -> HtmlParseOptions

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 HtmlParseOptions

Source§

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

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

impl Default for HtmlParseOptions

Source§

fn default() -> Self

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.