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: boolIndents 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: boolThe 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: " or '.
quote_attr_values: boolQuote 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: boolQuote a value with whichever quote it doesn’t contain, so neither needs escaping.
minimize_boolean_attributes: boolWrite 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: boolEscape the text of script, style and the other raw text
elements as other text is; this changes what a script says.
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: boolCollapse 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: boolA doctype’s public and system identifiers too, as
<!DOCTYPE html PUBLIC "..." "...">; the HTML Standard writes the
name alone.
serializable_shadow_roots: boolWrite 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
impl Clone for SerializeOptions
Source§fn clone(&self) -> SerializeOptions
fn clone(&self) -> SerializeOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more