matrix_sdk::ruma::html

Struct SanitizerConfig

Source
pub struct SanitizerConfig { /* private fields */ }
Expand description

Configuration to sanitize HTML elements and attributes.

Implementations§

Source§

impl SanitizerConfig

Source

pub fn new() -> SanitizerConfig

Constructs an empty SanitizerConfig that will not filter any element or attribute.

The list of allowed and replaced elements can be changed with Self::allow_elements(), Self::replace_elements(), Self::ignore_elements(), Self::remove_elements(), Self::remove_reply_fallback().

The list of allowed and replaced attributes can be changed with Self::allow_attributes(), Self::replace_attributes(), Self::remove_attributes(), Self::allow_schemes(), Self::deny_schemes(), Self::allow_classes(), Self::remove_classes().

Source

pub fn with_mode(mode: HtmlSanitizerMode) -> SanitizerConfig

Constructs a SanitizerConfig with the given mode for filtering elements and attributes.

The mode defines the basic list of allowed and replaced elements and attributes and the maximum nesting level of elements.

The list of allowed and replaced elements can be changed with Self::allow_elements(), Self::replace_elements(), Self::ignore_elements(), Self::remove_elements(), Self::remove_reply_fallback().

The list of allowed and replaced attributes can be changed with Self::allow_attributes(), Self::replace_attributes(), Self::remove_attributes(), Self::allow_schemes(), Self::deny_schemes(), Self::allow_classes(), Self::remove_classes().

Source

pub fn strict() -> SanitizerConfig

Constructs a SanitizerConfig that will filter elements and attributes not suggested in the Matrix specification.

The list of allowed and replaced elements can be changed with Self::allow_elements(), Self::replace_elements(), Self::ignore_elements(), Self::remove_elements(), Self::remove_reply_fallback().

The list of allowed and replaced attributes can be changed with Self::allow_attributes(), Self::replace_attributes(), Self::remove_attributes(), Self::allow_schemes(), Self::deny_schemes(), Self::allow_classes(), Self::remove_classes().

This is the same as calling SanitizerConfig::with_mode(HtmlSanitizerMode::Strict).

Source

pub fn compat() -> SanitizerConfig

Constructs a SanitizerConfig that will filter elements and attributes not [suggested in the Matrix specification], except a few for improved compatibility:

  • The matrix scheme is allowed in links.

The list of allowed elements can be changed with Self::allow_elements(), Self::replace_elements(), Self::ignore_elements(), Self::remove_elements(), Self::remove_reply_fallback().

The list of allowed attributes can be changed with Self::allow_attributes(), Self::replace_attributes(), Self::remove_attributes(), Self::allow_schemes(), Self::deny_schemes(), Self::allow_classes(), Self::remove_classes().

This is the same as calling SanitizerConfig::with_mode(HtmlSanitizerMode::Compat).

Source

pub fn replace_elements( self, elements: impl IntoIterator<Item = NameReplacement>, behavior: ListBehavior, ) -> SanitizerConfig

Change the list of replaced HTML elements.

The given list is added to or replaces the list of replacements of the current mode, depending on the ListBehavior.

The replacement occurs before the removal, so the replaced element should not be in the allowed list of elements, but the replacement element should.

§Parameters
  • elements: The list of element names replacements.
Source

pub fn remove_elements( self, elements: impl IntoIterator<Item = &'static str>, ) -> SanitizerConfig

Remove the given HTML elements.

When an element is removed, the element and its children are dropped. If you want to remove an element but keep its children, use SanitizerConfig::ignore_elements or SanitizerConfig::allow_elements.

Removing elements has a higher priority than ignoring or allowing. So if an element is in this list, it will always be removed.

§Parameters
  • elements: The list of element names to remove.
Source

pub fn remove_reply_fallback(self) -> SanitizerConfig

Remove the rich reply fallback.

Calling this allows to remove the mx-reply element in addition to the list of elements to remove.

Removing elements has a higher priority than ignoring or allowing. So if this settings is set, mx-reply will always be removed.

Source

pub fn ignore_elements( self, elements: impl IntoIterator<Item = &'static str>, ) -> SanitizerConfig

Ignore the given HTML elements.

When an element is ignored, the element is dropped and replaced by its children. If you want to drop an element and its children, use SanitizerConfig::remove_elements.

Removing elements has a lower priority than removing but a higher priority than allowing.

§Parameters
  • elements: The list of element names to ignore.
Source

pub fn allow_elements( self, elements: impl IntoIterator<Item = &'static str>, behavior: ListBehavior, ) -> SanitizerConfig

Change the list of allowed HTML elements.

The given list is added to or replaces the list of allowed elements of the current mode, depending on the ListBehavior.

If an element is not allowed, it is ignored. If no mode is set and no elements are explicitly allowed, all elements are allowed.

§Parameters
  • elements: The list of element names.
Source

pub fn replace_attributes<'a>( self, attrs: impl IntoIterator<Item = ElementAttributesReplacement<'a>>, behavior: ListBehavior, ) -> SanitizerConfig

Change the list of replaced attributes per HTML element.

The given list is added to or replaces the list of replacements of the current mode, depending on the ListBehavior.

The replacement occurs before the removal, so the replaced attribute should not be in the list of allowed attributes, but the replacement attribute should. Attribute replacement occurs before element replacement, so if you want to replace an attribute on an element that is set to be replaced, you must use the replaced element’s name, not the name of its replacement.

§Parameters
  • attrs: The list of element’s attributes replacements.
Source

pub fn remove_attributes<'a>( self, attrs: impl IntoIterator<Item = PropertiesNames<'a>>, ) -> SanitizerConfig

Remove the given attributes per HTML element.

Removing attributes has a higher priority than allowing. So if an attribute is in this list, it will always be removed.

§Parameters
  • attrs: The list of attributes per element. The value of parent is the element name, and properties contains attribute names.
Source

pub fn allow_attributes<'a>( self, attrs: impl IntoIterator<Item = PropertiesNames<'a>>, behavior: ListBehavior, ) -> SanitizerConfig

Change the list of allowed attributes per HTML element.

The given list is added to or replaces the list of allowed attributes of the current mode, depending on the ListBehavior.

If an attribute is not allowed, it is removed. If no mode is set and no attributes are explicitly allowed, all attributes are allowed.

§Parameters
  • attrs: The list of attributes per element. The value of parent is the element name, and properties contains attribute names.
Source

pub fn deny_schemes<'a>( self, schemes: impl IntoIterator<Item = ElementAttributesSchemes<'a>>, ) -> SanitizerConfig

Deny the given URI schemes per attribute per HTML element.

Denying schemes has a higher priority than allowing. So if a scheme is in this list, it will always be denied.

If a scheme is denied, its element is removed, because it is deemed that the element will not be usable without it URI.

§Parameters
  • schemes: The list of schemes per attribute per element.
Source

pub fn allow_schemes<'a>( self, schemes: impl IntoIterator<Item = ElementAttributesSchemes<'a>>, behavior: ListBehavior, ) -> SanitizerConfig

Change the list of allowed schemes per attribute per HTML element.

The given list is added to or replaces the list of allowed schemes of the current mode, depending on the ListBehavior.

If a scheme is not allowed, it is denied. If a scheme is denied, its element is ignored, because it is deemed that the element will not be usable without it URI. If no mode is set and no schemes are explicitly allowed, all schemes are allowed.

§Parameters
  • schemes: The list of schemes per attribute per element.
Source

pub fn remove_classes<'a>( self, classes: impl IntoIterator<Item = PropertiesNames<'a>>, ) -> SanitizerConfig

Deny the given classes per HTML element.

Removing classes has a higher priority than allowing. So if a class is in this list, it will always be removed.

If all the classes of a class attribute are removed, the whole attribute is removed.

In the list of classes, the names must match the full class name. * can be used as a wildcard for any number of characters. So language will only match a class named language, and language-* will match any class name starting with language-.

§Parameters
  • attrs: The list of classes per element. The value of parent is the element name, and properties contains classes.
Source

pub fn allow_classes<'a>( self, classes: impl IntoIterator<Item = PropertiesNames<'a>>, behavior: ListBehavior, ) -> SanitizerConfig

Change the list of allowed classes per HTML element.

The given list is added, removed or replaces the list of allowed classes of the current mode, depending on the ListBehavior.

If a class is not allowed, it is removed. If all the classes of a class attribute are removed, the whole attribute is removed. If no mode is set and no classes are explicitly allowed, all classes are allowed.

In the list of classes, the names must match the full class name. * can be used as a wildcard for any number of characters. So language will only match a class named language, and language-* will match any class name starting with language-.

§Parameters
  • attrs: The list of classes per element. The value of parent is the element name, and properties contains classes.
Source

pub fn max_depth(self, depth: u32) -> SanitizerConfig

The maximum nesting level of HTML elements.

This overrides the maximum depth set by the mode, if one is set.

All elements that are deeper than the maximum depth will be removed. If no mode is set and no maximum depth is explicitly set, elements are not filtered by their nesting level.

§Parameters
  • depth: The maximum nesting level allowed.

Trait Implementations§

Source§

impl Clone for SanitizerConfig

Source§

fn clone(&self) -> SanitizerConfig

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SanitizerConfig

Source§

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

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

impl Default for SanitizerConfig

Source§

fn default() -> SanitizerConfig

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

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

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§

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>).
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

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,

Source§

impl<T> AsyncTraitDeps for T

Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneAnySend for T
where T: Any + Send + Clone,

Source§

impl<T> CloneAnySendSync for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> CloneAnySync for T
where T: Any + Sync + Clone,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> SendOutsideWasm for T
where T: Send,

Source§

impl<T> SyncOutsideWasm for T
where T: Sync,