ruma_html

Struct Html

Source
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

Source

pub fn parse(string: &str) -> Self

Construct a new Html by parsing the given string.

This is infallible, any error encountered while parsing the HTML is logged with tracing::debug!.

Source

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().

Source

pub fn sanitize_with(&self, config: &SanitizerConfig)

Sanitize this HTML according to the given configuration.

Source

pub fn has_children(&self) -> bool

Whether the root node of the HTML has children.

Source

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.

Source

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.

Source

pub fn children(&self) -> Children

Iterate through the children of the root node of the HTML.

Trait Implementations§

Source§

impl Debug for Html

Source§

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

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

impl Default for Html

Source§

fn default() -> Self

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

impl Display for Html

Source§

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

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

impl Serialize for Html

Source§

fn serialize<S>( &self, serializer: &mut S, traversal_scope: TraversalScope, ) -> Result<()>
where S: Serializer,

Take the serializer and call its methods to serialize this type. The type will dictate which methods are called and with what parameters.
Source§

impl TreeSink for Html

Source§

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.
Source§

type Output = Html

The overall result of parsing. Read more
Source§

type ElemName<'a> = ExpandedName<'a>

Source§

fn finish(self) -> Self::Output

Consume this sink and return the overall result of parsing. Read more
Source§

fn parse_error(&self, msg: Cow<'static, str>)

Signal a parse error.
Source§

fn get_document(&self) -> Self::Handle

Get a handle to the Document node.
Source§

fn elem_name<'a>(&'a self, target: &'a Self::Handle) -> ExpandedName<'a>

What is the name of this element? Read more
Source§

fn create_element( &self, name: QualName, attrs: Vec<Attribute>, _flags: ElementFlags, ) -> Self::Handle

Create an element. Read more
Source§

fn create_comment(&self, _text: StrTendril) -> Self::Handle

Create a comment node.
Source§

fn create_pi(&self, _target: StrTendril, _data: StrTendril) -> Self::Handle

Create a Processing Instruction node.
Source§

fn append(&self, parent: &Self::Handle, child: NodeOrText<Self::Handle>)

Append a node as the last child of the given node. If this would produce adjacent sibling text nodes, it should concatenate the text instead. Read more
Source§

fn append_based_on_parent_node( &self, element: &Self::Handle, prev_element: &Self::Handle, child: NodeOrText<Self::Handle>, )

When the insertion point is decided by the existence of a parent node of the element, we consider both possibilities and send the element which will be used if a parent node exists, along with the element to be used if there isn’t one.
Source§

fn append_doctype_to_document( &self, _name: StrTendril, _public_id: StrTendril, _system_id: StrTendril, )

Append a DOCTYPE element to the Document node.
Source§

fn get_template_contents(&self, target: &Self::Handle) -> Self::Handle

Get a handle to a template’s template contents. The tree builder promises this will never be called with something else than a template element.
Source§

fn same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool

Do two handles refer to the same node?
Source§

fn set_quirks_mode(&self, _mode: QuirksMode)

Set the document’s quirks mode.
Source§

fn append_before_sibling( &self, sibling: &Self::Handle, new_node: NodeOrText<Self::Handle>, )

Append a node as the sibling immediately before the given node. Read more
Source§

fn add_attrs_if_missing(&self, target: &Self::Handle, attrs: Vec<Attribute>)

Add each attribute to the given element, if no attribute with that name already exists. The tree builder promises this will never be called with something else than an element.
Source§

fn remove_from_parent(&self, target: &Self::Handle)

Detach the given node from its parent.
Source§

fn reparent_children(&self, node: &Self::Handle, new_parent: &Self::Handle)

Remove all the children from node and append them to new_parent.
Source§

fn mark_script_already_started(&self, _node: &Self::Handle)

Mark a HTML <script> as “already started”.
Source§

fn pop(&self, _node: &Self::Handle)

Indicate that a node was popped off the stack of open elements.
Source§

fn associate_with_form( &self, _target: &Self::Handle, _form: &Self::Handle, _nodes: (&Self::Handle, Option<&Self::Handle>), )

Associate the given form-associatable element with the form element
Source§

fn is_mathml_annotation_xml_integration_point( &self, _handle: &Self::Handle, ) -> bool

Returns true if the adjusted current node is an HTML integration point and the token is a start tag.
Source§

fn set_current_line(&self, _line_number: u64)

Called whenever the line number changes.
Source§

fn complete_script(&self, _node: &Self::Handle) -> NextParserState

Indicate that a 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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more