Skip to content

Markdown Viewer

The MarkdownViewer component renders markdown content with syntax highlighting, interactive task lists, code suggestions, and customizable image handling. It’s suited to documentation, comments, READMEs, and code-review content. It renders standard markdown syntax including headings, lists, links, images, tables, blockquotes, and code blocks.

Variations

With border

Add a bordered container around the markdown content using the withBorder prop.

Max height

Control the maximum height of the markdown container to create scrollable content.

Code blocks with syntax highlighting

Code blocks receive syntax highlighting based on the language specified in the fence.

Code blocks with line numbers

Enable line numbers for code blocks using the showLineNumbers prop. This is especially useful for code reviews and documentation. Line numbers appear only when a code block has more than one line.

Interactive task lists

The MarkdownViewer supports interactive checkboxes in task lists. Use the onCheckboxChange prop to handle state updates — it receives the full updated markdown source.

Variant sizes

The MarkdownViewer supports two variants: default and sm for different typography scales.

Muted text

Use the muted prop to render markdown content with the subdued text-cn-3 foreground color. It defaults to false.

Code suggestions

The MarkdownViewer can render special code suggestion blocks with custom headers and footers. Use the suggestionBlock, suggestionTitle, and suggestionFooter props.

Image URL transform

Transform image URLs before rendering using the imageUrlTransform prop. Useful for handling relative paths or proxying images.

Tables and blockquotes

The MarkdownViewer fully supports markdown tables and blockquotes.

External links automatically open in a new tab with security attributes (nofollow, noreferrer, noopener).

Video embeds

The MarkdownViewer supports video file embeds for common video formats.

Loading state

Display a loading state to disable interactive elements while content is being updated.

Comment system example

A practical example combining multiple features for a comment/discussion system.

Installation

import { MarkdownViewer } from '@harnessio/ui/components'
//...
return (
<MarkdownViewer
source="# Hello World\n\nThis is **markdown** content."
/>
)