Skip to main content

SerializeOptions

Struct SerializeOptions 

Source
pub struct SerializeOptions {
Show 14 fields pub pretty: bool, pub html5test: bool, pub quote_char: char, pub quote_attr_values: bool, pub use_best_quote_char: bool, pub minimize_boolean_attributes: bool, pub use_trailing_solidus: bool, pub escape_rcdata: bool, pub omit_optional_tags: bool, pub strip_whitespace: bool, pub inject_meta_charset: Option<String>, pub full_doctype: bool, pub serializable_shadow_roots: bool, pub shadow_roots: Vec<u32>,
}
Expand description

How Document::serialize_with writes a node. The default is the HTML Standard’s serialization, byte for byte what Document::outer_html gives. Most fields are html5lib’s serializer options, under html5lib’s names.

Fields§

§pretty: bool

Indents the markup, two spaces a level, without changing what it means as the browser’s default styles render it. An element’s children go one to a line only when every child is a block (div, p, li, table, tr, td and the like), something that’s never rendered (head, meta, script, template…), a comment, a doctype, or whitespace-only text, which is dropped for the new line; and the element is itself a block, never rendered, the document, or has at least one block child. Whitespace next to a block collapses away, so adding it there changes nothing. Anything else (text, an inline element such as span, a, img or a custom element, foreign content) is written as it is, and so is everything inside it, and inside pre, textarea, listing, plaintext, xmp, title, script, style, iframe, noembed, noframes and noscript. Nothing after </body> or </html> starts a new line: the parser moves whitespace there to the end of the body, where it could join text. omit_optional_tags is ignored: every tag is kept, so no new whitespace ends up inside an element whose end tag was left out. Author CSS that sets white-space or display can make any whitespace matter, which no pretty-printer can know.

§html5test: bool

The tree dump of html5lib-tests’ tree-construction .dat files: | <html>, | <head>, each child two spaces in, attributes sorted, foreign elements and namespaced attributes prefixed, template contents under content. A shadow root, which the suite has no line for, goes first under its host as #shadow-root (open) or (closed), with delegatesfocus, clonable, serializable and manual after the mode when they’re set. Every other option is ignored.

§quote_char: char

" or ' around attribute values; anything else is taken as ". The one chosen is escaped inside: &quot; or &#39;.

§quote_attr_values: bool

Quote every attribute value. Off, a value goes unquoted when the HTML syntax allows it: not empty, and no whitespace, quotes, =, > or `.

§use_best_quote_char: bool

Quote a value with whichever quote it doesn’t contain, so neither needs escaping.

§minimize_boolean_attributes: bool

Write an attribute without a value when its value is empty, or when it’s a boolean attribute (disabled, checked…) whose value is its own name.

§use_trailing_solidus: bool

<br /> rather than <br> for void elements.

§escape_rcdata: bool

Escape the text of script, style and the other raw text elements as other text is; this changes what a script says.

§omit_optional_tags: bool

Leave out the start and end tags the HTML Standard lets a document leave out (section 13.1.2.4), where the parser puts back the same tree: </p> before another p, </li>, </td>, <tbody>.

§strip_whitespace: bool

Collapse each run of whitespace in text to one space, except inside the elements pretty writes as they are.

§inject_meta_charset: Option<String>

Rewrite every <meta charset>, and the content of every <meta http-equiv=content-type>, to name this encoding, and add a <meta charset> first in a head that has neither.

§full_doctype: bool

A doctype’s public and system identifiers too, as <!DOCTYPE html PUBLIC "..." "...">; the HTML Standard writes the name alone.

§serializable_shadow_roots: bool

Write each shadow root marked serializable as the declarative <template shadowrootmode> that makes it again, first inside its host, as getHTML({serializableShadowRoots: true}) does.

§shadow_roots: Vec<u32>

Write these shadow roots that way too, serializable or not, as getHTML({shadowRoots}) does.

Trait Implementations§

Source§

impl Clone for SerializeOptions

Source§

fn clone(&self) -> SerializeOptions

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 SerializeOptions

Source§

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

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

impl Default for SerializeOptions

Source§

fn default() -> SerializeOptions

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

impl Eq for SerializeOptions

Source§

impl PartialEq for SerializeOptions

Source§

fn eq(&self, other: &SerializeOptions) -> 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 SerializeOptions

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.