Skip to main content

Use remark to covert markdown into HTML

I’ve used remark in a few different projects, and each time I found it difficult to get started. For such a popular project, the documentation is quite terse.

To save myself the trouble of looking up how to do it in the future, here are the basic steps you need to get started converting markdown to HTML with remark.

First, install remark dependencies:

npm i remark remark-html

We will need the core library and a plugin for generating HTML. Then, import your dependencies and use them like so:

import remark from "remark";
import remarkHTML from "remark-html";

const html = remark().use(remarkHTML).processSync("Some **markdown** text");

That’s all you need to get going. To help jump-start your progress, checkout this working repl in Node.js or sandbox in React.

Hope this guide helps you get up and running too!

Happy coding!

About the author

Sean McPherson is a software engineer for Khan Academy who specializes in web and mobile app development. He lives with his wife, sons, and dog in Pittsburgh, PA.