MarkdownBlock
Description
Renders Markdown text as sanitized HTML. The component uses the bundled marked and DOMPurify libraries (via the Markdown helper) so untrusted input is safe to display.
Usage
API reference
public class MarkdownBlock : ComponentBase<MarkdownBlock, HTMLElement>, ICanWrapA component that renders Markdown text as sanitized HTML. Uses the bundled marked and DOMPurify libraries via Markdown.
- Namespace
- Tesserae
- Inheritance
- ComponentBase<MarkdownBlock, HTMLElement> → MarkdownBlock
- Implements
- ICanWrap
Constructors
| Name | Description |
|---|---|
| MarkdownBlock | Initializes a new instance of the MarkdownBlock class. |
public MarkdownBlock(string text = "", MarkdownSanitization sanitization = MarkdownSanitization.Default)Initializes a new instance of the MarkdownBlock class.
Parameters
- text
- The Markdown source text to render.
- sanitization
- How strictly to sanitize the rendered HTML. Pass
NoLinksOrEmbeddedContentfor Markdown from a source you don't trust to link or to load a remote URL.
Properties
| Name | Description |
|---|---|
| Text | Gets or sets the Markdown source text. Setting this re-renders the sanitized HTML. |
| HTML | Gets the rendered sanitized HTML (derived from Text). |
| CanWrap | Gets or sets whether the rendered Markdown can wrap. |
public string Text { get ; set ; }Gets or sets the Markdown source text. Setting this re-renders the sanitized HTML.
Methods
| Name | Description |
|---|---|
| Sanitization | Sets how strictly the rendered HTML is sanitized and re-renders the current source with it. |
| OnAfterRender | Registers a callback invoked every time the Markdown source is re-parsed into the inner HTML element. The callback receives the inner element so that callers can post-process the rendered tree (e.g. wrap <code> blocks with custom controls, rewrite links, attach copy buttons, ...). The callback is fired immediately with the current rendered content so the first pass does not require the caller to also trigger an explicit render. Re-registering replaces any previously-attached callback. |
| Render | Renders the component. |
public MarkdownBlock Sanitization(MarkdownSanitization sanitization)Sets how strictly the rendered HTML is sanitized and re-renders the current source with it.
public MarkdownBlock OnAfterRender(Action<HTMLElement> callback)Registers a callback invoked every time the Markdown source is re-parsed into the inner HTML element. The callback receives the inner element so that callers can post-process the rendered tree (e.g. wrap <code> blocks with custom controls, rewrite links, attach copy buttons, ...). The callback is fired immediately with the current rendered content so the first pass does not require the caller to also trigger an explicit render. Re-registering replaces any previously-attached callback.