Markdown View
Renders Markdown (CommonMark, GFM tables, tasks and strikethrough, [[wikilinks]] and ![[embeds]]) to React elements with the Lezer parser, fenced code as a highlighted CodeBlock: raw HTML shows as text, only http, https, mailto and tel links become links, leading YAML frontmatter is hidden or shown as properties, and each top-level block is memoised so long notes re-render only what changed. Also extractHeadings for an outline and parseFrontmatter.
Example
Installation
@lezer/common@1.5.5@lezer/markdown@1.8.1Usage
For notes: onWikilinkClick routes wikilinks, renderEmbed draws ![[embeds]], frontmatter hides or lists the YAML block, and extractHeadings feeds an outline.
API reference
MarkdownView
| Prop | Type | Default |
|---|---|---|
markdownrequired | string | – |
resolveWikilink | WikilinkResolver | – |
wikilinkHrefWhere a resolved wikilink points; without it, wikilinks render as styled text. Keep this and `resolveWikilink` stable (module-level or `useCallback`): a new function re-renders every block. | (slug: string) => string | undefined | – |
onWikilinkClickTakes a wikilink's plain clicks, and agents' `follow`, for client routing; modified clicks keep the browser's behaviour. A wikilink with no address becomes a button that calls it. Keep it stable, like `resolveWikilink`. | (target: string, event: Event | undefined) => void | – |
renderEmbedWhat `![[target]]` and `![[target|alias]]` show; without it, a link to the target. Keep it stable. | (target: string, alias: string | undefined) => ReactNode | – |
imageSizeAn image's size, so its box is reserved before it loads and the text below doesn't move. `` (or `|300` for the width alone) sets it in the Markdown, as in Obsidian; this answers for the others. Keep it stable. | (src: string, alt: string) => { width: number; height?: number } | undefined | – |
frontmatterA leading YAML block: hidden (default), a list of its `key: value` properties, or its text. | FrontmatterDisplay | "hide" |
renderFrontmatterRenders the frontmatter yourself, whatever `frontmatter` says. Keep it stable. | (frontmatter: Frontmatter) => ReactNode | – |
frontmatterLabelThe accessible name of the properties list. | string | "Properties" |
taskLabel | string | "Task done" |
codeLabelsNames for fenced code blocks and their copy buttons. Keep it stable, like `resolveWikilink`. | Partial<CodeBlockLabels> | – |
sourcePositionsMarks each table cell with its offset in `markdown` (`data-source-from`). | boolean | – |
Also takes <div> attributes except children.
Other exports
frontmatterBoundsparseFrontmatterparseFrontmatterPropertiesextractHeadingsheadingsOfmarkdownExtensionsmarkdownParserWikilinkwikilinkTextrenderFrontmatterrenderSoleEmbedwikilinkwikilinkPartsmarkdownBlocksrenderMarkdownsafeHreftype Frontmattertype FrontmatterPropertytype MarkdownHeadingtype WikilinkResolutiontype WikilinkResolvertype RenderContexttype FrontmatterDisplaytype MarkdownBlocktype Parsedtype RenderOptionstype MarkdownViewPropsAccessibility
- Renders semantic HTML (headings, lists, tables) without raw HTML; task boxes are labelled.
- Wikilinks are links when they have an address and buttons when only onWikilinkClick handles them; properties are a named description list.
Agent actions
Wikilinks with onWikilinkClick are links agents follow by their text.
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.