pub struct Markup(/* private fields */);Expand description
A string of HTML that the sink writes unchanged, without escaping.
What it is for. The HTML this library writes is escaped at the point of
writing: document text goes through HtmlSink::text
and an attribute value through
TagBuilder::attr, each of which rewrites the
characters that would otherwise be read as markup. A Markup value carries
bytes that are already HTML and must not be rewritten — the output of a
tool that produces markup, such as a formula typeset as inline
<svg> — and HtmlSink::markup writes them
through unchanged.
What its creator must ensure. Whoever calls trusted
accepts the requirement that the string is well-formed HTML that is safe to
place in the page: it closes every element it opens, and it holds no
script, no event handler attribute and no address a browser would execute,
unless the caller put them there intentionally and is responsible for them.
The library checks nothing about the string. If the bytes come from a
document, from a network resource or from any other input the caller does
not control, the caller sanitizes them first; this library’s own features
never pass document text to this constructor.
Outside this crate, unescaped bytes reach an HTML page in two ways only:
through trusted, and through
HtmlSink::raw_text_element, which
writes the content of a <style> or a <script> and refuses content that
holds that element’s closing tag. A review of what an extension can put into
a page is therefore a review of its calls to these two.
There is no other constructor from a string (the crate-private
from_library serves the library’s own code), and the text inside is
private:
use flm_core::stdlib::backends::html::Markup;
let markup = Markup(String::from("<b>bold</b>"));§Examples
use flm_core::stdlib::backends::html::{HtmlSink, Markup};
let mut sink = HtmlSink::new();
sink.text("2 < 3");
sink.markup(&Markup::trusted("<br>"));
assert_eq!(sink.finish(), "2 < 3<br>");Implementations§
Source§impl Markup
impl Markup
Sourcepub fn trusted(html: impl Into<String>) -> Markup
pub fn trusted(html: impl Into<String>) -> Markup
Returns a markup value holding html, on the caller’s assurance that
the bytes are HTML that is safe to place in a page (the type’s
documentation states what that assurance covers).
It is the only way, outside this crate, to put unescaped bytes anywhere
in an HTML page other than inside a <style> or a <script> (see
HtmlSink::raw_text_element).
§Examples
use flm_core::stdlib::backends::html::Markup;
let markup = Markup::trusted("<svg viewBox=\"0 0 1 1\"></svg>");
assert_eq!(markup.as_str(), "<svg viewBox=\"0 0 1 1\"></svg>");Trait Implementations§
impl Eq for Markup
impl StructuralPartialEq for Markup
Auto Trait Implementations§
impl Forget for Markup
impl Freeze for Markup
impl Move for Markup
impl RefUnwindSafe for Markup
impl Send for Markup
impl Sync for Markup
impl Unpin for Markup
impl UnsafeUnpin for Markup
impl UnwindSafe for Markup
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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