Markie is a demonstration of react-markdown
, a versatile markdown component designed for React applications. Below are some key features of react-markdown
:
dangerouslySetInnerHTML
, it renders actual React elements.react-markdown
is highly extensible with a wide range of plugins available.Landing-Page
John-Paul
The content below showcases the usage of various plugins:
remark-toc
plugin.rehype-highlight
.Here's an example of syntax highlighting using 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') );
For GFM support, you can use the remark-gfm
plugin. It adds support for GitHub-specific extensions such as tables, strikethrough, task lists, and literal URLs.
HTML in markdown can be risky, but if you need to support it, you can use rehype-raw
combined with rehype-sanitize
for security.
Custom components can be utilized to modify the rendering behavior:
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={{ h1: 'h2', // Render h1 as h2 hr(props) { const { node, ...rest } = props; return <MyFancyRule {...rest} />; } }} > {markdown} </Markdown>, document.querySelector('#content') );
For more detailed information, check out the GitHub repository.