Home / Companies / LogRocket / Blog / Post Details
Content Deep Dive

How to safely render Markdown using react-markdown

Blog post from LogRocket

Post Details
Company
Date Published
Author
Akash Mittal
Word Count
888
Language
-
Hacker News Points
-
Summary

Markdown is a widely used format in the developer community for creating content across various platforms, and react-markdown is a React component that securely converts Markdown text into HTML without relying on the risky dangerouslySetInnerHTML prop, reducing vulnerability to cross-site scripting (XSS) attacks. By using a syntax tree to build the virtual DOM, react-markdown prevents script injections, making it a safe choice for rendering Markdown, which is designed for simplicity with only basic tags. While react-markdown supports basic Markdown syntax, its functionality can be enhanced using plugins like remark-gfm and rehype-katex, which enable features such as strikethrough, tables, task lists, and mathematical expressions. The tutorial illustrates how to install and use react-markdown, along with these plugins, to render Markdown safely in React applications, offering examples and guidance on implementation.