Skip to content
Eskais UI

Editor

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

npx shadcn@latest add @eskais/markdown-view
Brings alonglinkcode-block
npm packages@lezer/common@1.5.5@lezer/markdown@1.8.1

Usage

Import
import { frontmatterBounds, parseFrontmatter, parseFrontmatterProperties } from "@/components/ui/markdown-frontmatter"import { extractHeadings, headingsOf } from "@/components/ui/markdown-outline"import { markdownExtensions, markdownParser, Wikilink, wikilinkText } from "@/components/ui/markdown-syntax"import { renderFrontmatter, renderSoleEmbed, wikilink, wikilinkParts } from "@/components/ui/markdown-view-links"import { markdownBlocks, renderMarkdown, safeHref } from "@/components/ui/markdown-view-render"import { extractHeadings, MarkdownView, parseFrontmatter } from "@/components/ui/markdown-view"

For notes: onWikilinkClick routes wikilinks, renderEmbed draws ![[embeds]], frontmatter hides or lists the YAML block, and extractHeadings feeds an outline.

API reference

MarkdownView

PropTypeDefault
markdownrequiredstring–
resolveWikilinkWikilinkResolver–
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. `![alt|300x200](src)` (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"
taskLabelstring"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 MarkdownViewProps

Accessibility

  • 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.