Moves through links in the stored HTML, as any link
API
RichText
Prop
Type
Required
Does
html
string | null | undefined
Yes
HTML the server already sanitized for this origin (a stored abstract, a bio, a statement). Never a visitor's raw input.
as
RichTextTag
The element it is rendered into. A div by default; a span for a title inside a line.
measure
boolean
Keeps running text to the reading measure (--measure), in place of an inline max-width.
fallback
ReactNode
Shown in place of the element when html is empty: "Untitled", "No description yet".
And every attribute of <element>.
Functions
Function
Signature
Does
trustedHtml
(html: string): string
html as TrustedHTML under the capsomer policy where the browser has Trusted Types, else the string.
setStaticHtml
(el: Element, html: string): void
Sets el's children from a constant markup string in our own source (an icon).
copyChildren
(dst: Element, src: Element): void
Replaces dst's children with copies of src's: DOM to DOM, no markup string involved.
markup
(html: string): { __html: string; }
For React's dangerouslySetInnerHTML: { __html } holding html as TrustedHTML. The same object comes back for the same string, because React sets the markup again (and drops what a script attached to it) whenever the object changes.
inertDocument
(html: string): Document
Parses html into an inert document: DOMParser's documents run no script and load no image or stylesheet. For HTML a person pasted into their own editor, which a schema then reads node by node; never move its nodes into the page as they are.