Struct matrix_sdk::ruma::html::Html

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§

§

impl 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!.

pub fn sanitize(&mut 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().

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

Sanitize this HTML according to the given configuration.

pub fn has_children(&self) -> bool

Whether the root node of the HTML has children.

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.

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.

pub fn children(&self) -> Children<'_>

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

Trait Implementations§

§

impl Debug for Html

§

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

Formats the value using the given formatter. Read more
§

impl Default for Html

§

fn default() -> Html

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

impl Display for Html

§

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

Formats the value using the given formatter. Read more
§

impl Serialize for Html

§

fn serialize<S>( &self, serializer: &mut S, traversal_scope: TraversalScope ) -> Result<(), Error>
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.
§

impl TreeSink for Html

§

type Handle = usize

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 Output = Html

The overall result of parsing. Read more
§

fn finish(self) -> <Html as TreeSink>::Output

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

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

Signal a parse error.
§

fn get_document(&mut self) -> <Html as TreeSink>::Handle

Get a handle to the Document node.
§

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

What is the name of this element? Read more
§

fn create_element( &mut self, name: QualName, attrs: Vec<Attribute>, _flags: ElementFlags ) -> <Html as TreeSink>::Handle

Create an element. Read more
§

fn create_comment(&mut self, _text: Tendril<UTF8>) -> <Html as TreeSink>::Handle

Create a comment node.
§

fn create_pi( &mut self, _target: Tendril<UTF8>, _data: Tendril<UTF8> ) -> <Html as TreeSink>::Handle

Create a Processing Instruction node.
§

fn append( &mut self, parent: &<Html as TreeSink>::Handle, child: NodeOrText<<Html as TreeSink>::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
§

fn append_based_on_parent_node( &mut self, element: &<Html as TreeSink>::Handle, prev_element: &<Html as TreeSink>::Handle, child: NodeOrText<<Html as TreeSink>::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.
§

fn append_doctype_to_document( &mut self, _name: Tendril<UTF8>, _public_id: Tendril<UTF8>, _system_id: Tendril<UTF8> )

Append a DOCTYPE element to the Document node.
§

fn get_template_contents( &mut self, target: &<Html as TreeSink>::Handle ) -> <Html as TreeSink>::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.
§

fn same_node( &self, x: &<Html as TreeSink>::Handle, y: &<Html as TreeSink>::Handle ) -> bool

Do two handles refer to the same node?
§

fn set_quirks_mode(&mut self, _mode: QuirksMode)

Set the document’s quirks mode.
§

fn append_before_sibling( &mut self, sibling: &<Html as TreeSink>::Handle, new_node: NodeOrText<<Html as TreeSink>::Handle> )

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

fn add_attrs_if_missing( &mut self, target: &<Html as TreeSink>::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.
§

fn remove_from_parent(&mut self, target: &<Html as TreeSink>::Handle)

Detach the given node from its parent.
§

fn reparent_children( &mut self, node: &<Html as TreeSink>::Handle, new_parent: &<Html as TreeSink>::Handle )

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

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

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

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

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

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

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

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

fn set_current_line(&mut self, _line_number: u64)

Called whenever the line number changes.
§

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

Indicate that a script element is complete.

Auto Trait Implementations§

§

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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

impl<T> Identity for T
where T: ?Sized,

§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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>,

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

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
source§

impl<T> Any for T
where T: Any,