Back to blog

Test Markdown Format

Huy Ngo avatar
Huy Ngo
2 min read

h1 Heading 8-)

h2 Heading

h3 Heading

h4 Heading

h5 Heading
h6 Heading

A demo of react-markdown

react-markdown is a markdown component for React.

šŸ‘‰ Changes are re-rendered as you type.

šŸ‘ˆ Try writing some markdown on the left.

Overview

  • Follows CommonMark
  • Optionally follows GitHub Flavored Markdown
  • Renders actual React elements instead of using dangerouslySetInnerHTML
  • Lets you define your own components (to render MyHeading instead of 'h1')
  • Has a lot of plugins

Hello

Contents

Here is an example of a plugin in action (remark-toc). This section is replaced by an actual table of contents.

Syntax highlighting

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?

GitHub flavored markdown (GFM)

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.

FeatureSupport
CommonMark100%
GFM100% w/ remark-gfm

strikethrough

  • task list
  • checked item

https://example.com

HTML in markdown

āš ļø 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.

šŸ‘† Use the toggle above to add the plugin.

Components

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')
)

More info?

Much more info is available in the readme on GitHub!


A component by Espen Hovlandsdal

Senior Technical Lead

Huy Ngo

Senior Technical Lead

Related articles

Explore our blog
avatar-blog

The Key Aspect of Problem Framing in Building AI/ML Applications

Tien avatar

by Tien

avatar-blog

Cost-optimized ML on production: Autoscaling GPU Nodes on Kubernetes to Zero using KEDA !!!

Huy Ngo avatar

by Huy Ngo

avatar-blog

AImagine: Pioneering Hyperrealistic AI Image Generation!!!!

Tien avatar

by Tien

Let's discuss your project needs.

We can help you get the details right.

Book a discovery call
background

CodeLink Newsletter

Subscribe to receive the latest news on technology and product development from CodeLink.

CodeLink

CodeLink empowers industry leaders and innovators to build high-impact technology products, leveraging AI and software development expertise.

Contact Us

(+84) 2839 333 143Write us at hello@codelink.io
Contact Us
2025 Ā© CodeLink Limited.
All right reserved.
Privacy Policy