Loading...
Skip to main content

Markdown view

MarkdownView synchronously parses a Markdown string with marked and renders the HTML inside an <article>. It adds markdown-body to the root element for use with GitHub Markdown CSS.

Load the stylesheet from unpkg.com with a <link /> in your page's <head>, alongside Bootstrap:

<link rel="stylesheet" href="https://unpkg.com/github-markdown-css@5.9.0/github-markdown.css" />

The component does not import or bundle this stylesheet.

Example

Hello, Markdown!

Write formatted text, links, and lists:

  • React
  • Bootstrap
<MarkdownView className="border rounded p-4">
## Hello, Markdown!

Write **formatted text**, [links](https://getbootstrap.com/), and lists:

- React
- Bootstrap
</MarkdownView>

Usage

import { MarkdownView } from 'idea-react';

<MarkdownView aria-label="Article">{markdownSource}</MarkdownView>;

Pass Markdown as the string children. Native article attributes, className, and refs pass through. Use as to select another root element.

Parsing is synchronous, including during server rendering. Asynchronous marked extensions are not supported. Changing children immediately replaces the rendered HTML.

Trusted content

Neither marked nor MarkdownView sanitizes HTML. Embedded HTML is rendered as-is, so only pass trusted Markdown. Sanitize untrusted input before rendering it; see marked's security guidance.

The previous EditorHTML component and its Editor.js data/parser API have been removed. Pass Markdown text instead of block data. Rich-text HTML from React Bootstrap Editor (see the Ecosystem) is a different format and must not be passed as Markdown.

Documentation navigation
On this page
On this page