#[non_exhaustive]pub struct RenderOptions {
pub pretty: bool,
pub xhtml_self_closing: bool,
pub max_depth: Option<usize>,
/* private fields */
}Expand description
How a node tree is turned into markup.
A value passed into the render call, never global state — two threads can render the same tree with different settings at the same time. There is deliberately no process-wide switch.
§Examples
use molt::core::RenderOptions;
let compact = RenderOptions::compact();
let pretty = RenderOptions::pretty();
let four_spaces = RenderOptions::pretty().with_indent(" ");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.pretty: boolWhen true, children go on their own lines and are indented.
xhtml_self_closing: boolWhen true, void elements close with /> instead of >.
max_depth: Option<usize>Elements nested deeper than this are not written. None (the default) writes any
depth. See RenderOptions::with_max_depth.
Implementations§
Source§impl RenderOptions
impl RenderOptions
Sourcepub fn compact() -> Self
pub fn compact() -> Self
Minified output on a single line. The default, and what you should ship.
Sourcepub fn with_indent(self, indent: impl AsRef<str>) -> Self
pub fn with_indent(self, indent: impl AsRef<str>) -> Self
Sets the indentation string.
Only spaces and tabs are kept, and at most 16 of them; anything else is dropped. The
indent is written verbatim at the start of every line, so a string with markup in it
(renderWithIndent(untrusted) from JavaScript, say) would put that markup on every
line of the page. An indent that is not whitespace is not an indent.
§Examples
use molt::core::RenderOptions;
assert_eq!(RenderOptions::pretty().with_indent("\t").indent(), "\t");
assert_eq!(RenderOptions::pretty().with_indent("<script>").indent(), "");
assert_eq!(RenderOptions::pretty().with_indent(" <b> ").indent(), " ");Sourcepub fn with_max_depth(self, max_depth: usize) -> Self
pub fn with_max_depth(self, max_depth: usize) -> Self
Stops writing elements nested deeper than max_depth; the subtree is dropped.
Pretty output grows with the square of the depth (one indent per level on every line), so a tree whose depth comes from untrusted input can ask for gigabytes. This bounds it. Browsers flatten nesting beyond roughly 512 elements, so a limit of 512 or less loses nothing a page could show. Text and fragments do not count as a level.
§Examples
use molt::prelude::*;
let tree = div().child(div().child(div().child(p().text("deep"))));
let shallow = RenderOptions::compact().with_max_depth(2);
assert_eq!(tree.render_with(&shallow), "<div><div></div></div>");Sourcepub fn with_xhtml_self_closing(self, yes: bool) -> Self
pub fn with_xhtml_self_closing(self, yes: bool) -> Self
Closes void elements with /> instead of >.
Trait Implementations§
Source§impl Clone for RenderOptions
impl Clone for RenderOptions
Source§impl Debug for RenderOptions
impl Debug for RenderOptions
Source§impl Default for RenderOptions
impl Default for RenderOptions
impl Eq for RenderOptions
Source§impl PartialEq for RenderOptions
impl PartialEq for RenderOptions
impl StructuralPartialEq for RenderOptions
Auto Trait Implementations§
impl Freeze for RenderOptions
impl RefUnwindSafe for RenderOptions
impl Send for RenderOptions
impl Sync for RenderOptions
impl Unpin for RenderOptions
impl UnsafeUnpin for RenderOptions
impl UnwindSafe for RenderOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more