Onuralp
react-markdownreact-markdown is a markdown component for React.
š Changes are re-rendered as you type.
š Try writing some markdown on the left.
dangerouslySetInnerHTMLMyHeading instead of 'h1')Here is an example of a plugin in action
(remark-toc).
This section is replaced by an actual table of contents.
Here is an example of a plugin to highlight code:
rehype-highlight.
import React from 'react'
import ReactDOM from 'react-dom'
import Markdown from 'react-markdown'
import rehypeHighlight from 'rehype-highlight'
const markdown = `
# Your markdown here
`
ReactDOM.render(
<Markdown rehypePlugins={[rehypeHighlight]}>{markdown}</Markdown>,
document.querySelector('#content')
)
Pretty neat, eh?
For GFM, you can also use a plugin:
remark-gfm.
It adds support for GitHub-specific extensions to the language:
tables, strikethrough, tasklists, and literal URLs.
These features do not work by default. š Use the toggle above to add the plugin.
| Feature | Support |
|---|---|
| CommonMark | 100% |
| GFM | 100% w/ remark-gfm |
strikethrough
ā ļø HTML in markdown is quite unsafe, but if you want to support it, you can
use rehype-raw.
You should probably combine it with
rehype-sanitize.
You can pass components to change things:
import React from 'react'
import ReactDOM from 'react-dom'
import Markdown from 'react-markdown'
import MyFancyRule from './components/my-fancy-rule.js'
const markdown = `
# Your markdown here
`
ReactDOM.render(
<Markdown
components={{
// Use h2s instead of h1s
h1: 'h2',
// Use a component instead of hrs
hr(props) {
const {node, ...rest} = props
return <MyFancyRule {...rest} />
}
}}
>
{markdown}
</Markdown>,
document.querySelector('#content')
)
Much more info is available in the readme on GitHub!
A component by Espen Hovlandsdal