Project: remarkjs/remark-html

Package: remark-html@14.0.1

  1. Dependents: 190
  2. remark plugin to compile Markdown to HTML
  1. remark 190
  2. unified 174
  3. plugin 137
  4. markdown 131
  5. html 121
  6. mdast 85
  7. remark-plugin 73
  8. stringify 18
  9. compile 13


Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to serialize Markdown as HTML.

⚠️ This package essentially packs remark-rehype and rehype-stringify, and although it does support some customisation, it isn’t very pluggable. It’s probably smarter to use remark-rehype directly and benefit from the rehype ecosystem.


This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.


npm install remark-html


Say we have the following file, example.md:

# Hello & World

> A block quote.

* Some _emphasis_, **importance**, and `code`.

And our module, example.js, looks as follows:

import fs from 'node:fs'
import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkHtml from 'remark-html'

const buf = fs.readFileSync('example.md')

  .then((file) => {

Now, running node example yields:

<h1>Hello &#x26; World</h1>
<p>A block quote.</p>
<li>Some <em>emphasis</em>, <strong>importance</strong>, and <code>code</code>.</li>


This package exports no identifiers. The default export is remarkHtml.

unified().use(remarkHtml[, options])

Serialize Markdown as HTML.


All options except for sanitize and handlers are passed to hast-util-to-html.

The underlying tools allow much more customisation. It is recommended to replace this project with remark-rehype and rehype-stringify ;


Object mapping mdast nodes to functions handling them. This option is passed to mdast-util-to-hast.


How to sanitize the output (Object or boolean, default: true):

Note that raw HTML in Markdown cannot be sanitized, so it’s removed. A schema can still be used to allow certain values from other plugins though. To support HTML in Markdown, use rehype-raw.

For example, to add strict sanitation but allowing classNames, use something like:

// ...
var merge = require('deepmerge')
var github = require('hast-util-sanitize/lib/github')

var schema = merge(github, {attributes: {'*': ['className']}})

  .use(html, {sanitize: schema})
  .processSync(/* … */)


Use of remark-html is unsafe by default and opens you up to a cross-site scripting (XSS) attack. Pass sanitize: true to prevent attacks. Settings sanitize to anything else may be unsafe.


See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer