Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

RichText

Since 0.1.0-alpha.22
Displays HTML from an editor or a CMS safely in the page.

Shows saved rich text, such as a rich text editor's value or HTML from a CMS: sanitized, then styled as Prose.

Saved content

RichText shows HTML people wrote, such as a rich text editor's value or a CMS field, styled as Prose. Set Html to the saved HTML. Under the page's own title, set TopHeading to 2, as on the editor that wrote it.

Static

Preview

Resetting your password

If you can't sign in, reset your password from the sign-in page. The link we email you works for one hour.

  1. Select Forgot password under the password field.
  2. Enter the email address on your account.
  3. Open the email and choose a new password.
We never ask for your password by email or phone.

Still stuck? Email support.

Code

Usage.razor
@* A support article's body, as a rich text editor saved it. *@
<RichText Html="@body" TopHeading="2" MaxWidth="Length.Prose" Grow />

Add this example to a page with the izzy CLI:

bash
izzy add component RichText --at <file>:<line>

What it removes

RichText sanitizes the HTML every time it renders: scripts, event handlers, styles and javascript: links go, and other markup becomes the elements a rich text editor makes. HTML saved before you sanitized it can't run script on the page. To clean HTML yourself, call RichTextSanitizer.Sanitize.

Static

Preview

Great kettle

Boils in under two minutes and the lid doesn't drip.

See my other reviews.

Code

Sanitized.razor
@* A product review as it was posted, with a script, an event handler, inline styles and a
   javascript: link in it. Only the text and its formatting are shown. *@
<RichText Html="@review" MaxWidth="Length.Prose" Grow />

Details

It runs RichTextSanitizer on Html every time it renders, so HTML saved before you sanitized it, or written by another system, can't run script on the page. What's kept is listed on RichTextSanitizer. A code block with a language (<code class="language-csharp">, as the editor writes it) is highlighted on the server, as Code is, by the same highlighter; the saved HTML keeps only the class. For Markdown, use Markdown. For HTML you wrote yourself and trust, use Prose.

Mode support

What works in each mode, RichText
FeatureStaticInteractive
EverythingYesYes

Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.

Accessibility

  • Heading levels, alt text and link text come from the HTML. When the page has its own heading 1 above the text, set TopHeading to 2 so the text's headings sit under it.
  • Links are underlined, not marked by color alone.

Parameters

RichText parameters
PropTypeDefault
HtmlThe HTML to show.string?
FontsThe fonts the text may use, as the editor's Fonts: others are dropped.IReadOnlyList<string>?
FontSizesThe fixed text sizes the text may use, as the editor's FontSizes: others are dropped.IReadOnlyList<string>?
CustomColorsKeep the editor's custom colors: a text color or highlight as six hex digits, as the editor's CustomColors.boolfalse
TopHeadingThe highest heading level shown, 1 to 6: higher headings move down to it.int1
AllowDataImagesKeep images whose source is a data: URL of a PNG, JPEG, GIF, WebP or AVIF image.boolfalse
SizeText size.ProseSizeProseSize.Md
AsThe element to render: div on a Box; components built on it set their own (List a ul, Section a section).string"div"
ChildContentThe content.RenderFragment?

See also

  • Markdown: shows Markdown as HTML, sanitized and styled as Prose.
  • Prose: styles plain HTML, such as rendered Markdown.
  • RichTextSanitizer

Connection lost

Rejoining the server…