pub struct Html { /* private fields */ }
Expand description
An HTML fragment.
To get the serialized HTML, use its Display
implementation. Due to the fact that the HTML is
parsed, note that malformed HTML and comments will be stripped from the output.
Implementations§
Source§impl Html
impl Html
Sourcepub fn parse(string: &str) -> Html
pub fn parse(string: &str) -> Html
Construct a new Html
by parsing the given string.
This is infallible, any error encountered while parsing the HTML is logged with
tracing::debug!
.
Sourcepub fn sanitize(&self)
pub fn sanitize(&self)
Sanitize this HTML according to the Matrix specification.
This is equivalent to calling Self::sanitize_with()
with a config
value of
SanitizerConfig::compat().remove_reply_fallback()
.
Sourcepub fn sanitize_with(&self, config: &SanitizerConfig)
pub fn sanitize_with(&self, config: &SanitizerConfig)
Sanitize this HTML according to the given configuration.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Whether the root node of the HTML has children.
Sourcepub fn first_child(&self) -> Option<NodeRef>
pub fn first_child(&self) -> Option<NodeRef>
The first child node of the root node of the HTML.
Returns None
if the root node has no children.
Sourcepub fn last_child(&self) -> Option<NodeRef>
pub fn last_child(&self) -> Option<NodeRef>
The last child node of the root node of the HTML .
Returns None
if the root node has no children.
Trait Implementations§
Source§impl Serialize for Html
impl Serialize for Html
Source§fn serialize<S>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope,
) -> Result<(), Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope,
) -> Result<(), Error>where
S: Serializer,
Source§impl TreeSink for Html
impl TreeSink for Html
Source§type Handle = NodeRef
type Handle = NodeRef
Handle
is a reference to a DOM node. The tree builder requires
that a Handle
implements Clone
to get another reference to
the same node.type ElemName<'a> = ExpandedName<'a>
Source§fn finish(self) -> <Html as TreeSink>::Output
fn finish(self) -> <Html as TreeSink>::Output
Source§fn parse_error(&self, msg: Cow<'static, str>)
fn parse_error(&self, msg: Cow<'static, str>)
Source§fn elem_name<'a>(
&'a self,
target: &'a <Html as TreeSink>::Handle,
) -> ExpandedName<'a>
fn elem_name<'a>( &'a self, target: &'a <Html as TreeSink>::Handle, ) -> ExpandedName<'a>
Source§fn create_element(
&self,
name: QualName,
attrs: Vec<Attribute>,
_flags: ElementFlags,
) -> <Html as TreeSink>::Handle
fn create_element( &self, name: QualName, attrs: Vec<Attribute>, _flags: ElementFlags, ) -> <Html as TreeSink>::Handle
Source§fn create_comment(&self, _text: Tendril<UTF8>) -> <Html as TreeSink>::Handle
fn create_comment(&self, _text: Tendril<UTF8>) -> <Html as TreeSink>::Handle
Source§fn create_pi(
&self,
_target: Tendril<UTF8>,
_data: Tendril<UTF8>,
) -> <Html as TreeSink>::Handle
fn create_pi( &self, _target: Tendril<UTF8>, _data: Tendril<UTF8>, ) -> <Html as TreeSink>::Handle
Source§fn append(
&self,
parent: &<Html as TreeSink>::Handle,
child: NodeOrText<<Html as TreeSink>::Handle>,
)
fn append( &self, parent: &<Html as TreeSink>::Handle, child: NodeOrText<<Html as TreeSink>::Handle>, )
Source§fn append_based_on_parent_node(
&self,
element: &<Html as TreeSink>::Handle,
prev_element: &<Html as TreeSink>::Handle,
child: NodeOrText<<Html as TreeSink>::Handle>,
)
fn append_based_on_parent_node( &self, element: &<Html as TreeSink>::Handle, prev_element: &<Html as TreeSink>::Handle, child: NodeOrText<<Html as TreeSink>::Handle>, )
Source§fn append_doctype_to_document(
&self,
_name: Tendril<UTF8>,
_public_id: Tendril<UTF8>,
_system_id: Tendril<UTF8>,
)
fn append_doctype_to_document( &self, _name: Tendril<UTF8>, _public_id: Tendril<UTF8>, _system_id: Tendril<UTF8>, )
DOCTYPE
element to the Document
node.Source§fn get_template_contents(
&self,
target: &<Html as TreeSink>::Handle,
) -> <Html as TreeSink>::Handle
fn get_template_contents( &self, target: &<Html as TreeSink>::Handle, ) -> <Html as TreeSink>::Handle
Source§fn same_node(
&self,
x: &<Html as TreeSink>::Handle,
y: &<Html as TreeSink>::Handle,
) -> bool
fn same_node( &self, x: &<Html as TreeSink>::Handle, y: &<Html as TreeSink>::Handle, ) -> bool
Source§fn set_quirks_mode(&self, _mode: QuirksMode)
fn set_quirks_mode(&self, _mode: QuirksMode)
Source§fn append_before_sibling(
&self,
sibling: &<Html as TreeSink>::Handle,
new_node: NodeOrText<<Html as TreeSink>::Handle>,
)
fn append_before_sibling( &self, sibling: &<Html as TreeSink>::Handle, new_node: NodeOrText<<Html as TreeSink>::Handle>, )
Source§fn add_attrs_if_missing(
&self,
target: &<Html as TreeSink>::Handle,
attrs: Vec<Attribute>,
)
fn add_attrs_if_missing( &self, target: &<Html as TreeSink>::Handle, attrs: Vec<Attribute>, )
Source§fn remove_from_parent(&self, target: &<Html as TreeSink>::Handle)
fn remove_from_parent(&self, target: &<Html as TreeSink>::Handle)
Source§fn reparent_children(
&self,
node: &<Html as TreeSink>::Handle,
new_parent: &<Html as TreeSink>::Handle,
)
fn reparent_children( &self, node: &<Html as TreeSink>::Handle, new_parent: &<Html as TreeSink>::Handle, )
Source§fn mark_script_already_started(&self, _node: &Self::Handle)
fn mark_script_already_started(&self, _node: &Self::Handle)
<script>
as “already started”.Source§fn pop(&self, _node: &Self::Handle)
fn pop(&self, _node: &Self::Handle)
Source§fn associate_with_form(
&self,
_target: &Self::Handle,
_form: &Self::Handle,
_nodes: (&Self::Handle, Option<&Self::Handle>),
)
fn associate_with_form( &self, _target: &Self::Handle, _form: &Self::Handle, _nodes: (&Self::Handle, Option<&Self::Handle>), )
Source§fn is_mathml_annotation_xml_integration_point(
&self,
_handle: &Self::Handle,
) -> bool
fn is_mathml_annotation_xml_integration_point( &self, _handle: &Self::Handle, ) -> bool
Source§fn set_current_line(&self, _line_number: u64)
fn set_current_line(&self, _line_number: u64)
Source§fn complete_script(&self, _node: &Self::Handle) -> NextParserState
fn complete_script(&self, _node: &Self::Handle) -> NextParserState
script
element is complete.Auto Trait Implementations§
impl Freeze for Html
impl !RefUnwindSafe for Html
impl !Send for Html
impl !Sync for Html
impl Unpin for Html
impl !UnwindSafe for Html
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
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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