MarkdownViewer

Render Markdown with your theme’s typography: GitHub tables, task lists, highlighted code blocks and heading links.

Status: beta. Category: Viewers.

import { MarkdownViewer } from '@glyphui/viewers/markdown'

Exports: MarkdownViewer, markdownViewerStyles, slugify.

Notes

  • Install the optional peer dependencies first: npm install react-markdown remark-gfm shiki.
  • Safe by default: raw HTML in the Markdown shows as text. If you need HTML, add rehype-raw to rehypePlugins and rehype-sanitize after it.
  • Code blocks render with CodeViewer, so they follow your theme too.

MarkdownViewer props

PropTypeDefaultDescription
classNamestring
componentsComponentsOverride how elements render, as in react-markdown.
contentstringMarkdown text.
headingAnchorsbooleanAdds # links to headings so readers can share them. Default true.
rehypePluginsPluggableList | nullExtra rehype plugins. Raw HTML in the Markdown is never rendered unless you add rehype-raw here, and then you should add rehype-sanitize after it.
sourceViewerSourceA Markdown file to load instead: a URL, a File/Blob, or bytes.

Example: A README

Hover a heading for its link.

import { MarkdownViewer } from '@glyphui/viewers/markdown'
import { fixture } from '../../../lib/fixtures'

export default function Example() {
  return <MarkdownViewer source={fixture('README.md')} className="w-full max-w-2xl" />
}

Live page: https://glyphui.xyz/components/markdown-viewer