MarkdownView Markdown
A read-only view that renders GitHub-flavored Markdown.
Usage
Basic
content is the only input, parsed as GFM.
Loading demo...
Rich Markdown
Loading demo...
Themes
theme pins light or dark; auto follows the document theme.
Loading demo...
Best Practices
- Keep
sanitizeon for user-generated, remote, or plugin-provided content. - Pass normalized Markdown; don't mix in partially escaped HTML unless you rely on Markdown HTML on purpose.
- Set
themeexplicitly on previews and cards that don't follow the document theme. - Use it for display only; pair it with an editor or textarea outside when users edit.
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
content | string | required | Markdown source string. |
sanitize | boolean | true | Cleans the output with DOMPurify; nothing renders until it loads. |
theme | 'auto' | 'light' | 'dark' | 'auto' | auto resolves from the document's data-theme or theme classes, falling back to light. |
Overview
- Parses with
markedusinggfmandbreaks(a single newline breaks the line). - With
sanitize=true, nothing renders before DOMPurify is ready; if its import fails, the body stays empty. - With
sanitize=false, the output goes straight intov-html; use it only for trusted content. theme="auto"reads and observesdata-themeand thelight/darkclasses on bothhtmlandbody.- The wrapper carries the resolved
light/darkclass and a matchingdata-theme.
Technologies
- The bundled
github-markdown.cssis a global import shared withTxStreamMarkdown; every rule is scoped to:where(.tx-markdown-view, .tx-stream-md), so a host's own.markdown-bodyis untouched. Keep the scope when re-vendoring it. - Source:
packages/tuffex/packages/components/src/markdown-view/.
查看源码
packages/tuffex/packages/components/src/markdown-view/index.ts