unified processes content with syntax trees and transforms between different formats. remark and rehype are its markdown and HTML ecosystems. We use this because its performant and has a large collection of plugins. Primarily, unlike some other node markdown parsers that provide syntax highlighting capabilities, unified does not have any native C++ dependencies. This makes it easier to install and reduces the likelihood of system-dependent installation failures.
- remark-parse parses markdown
- remark-gemoji-to-emoji transforms gemoji shortcodes to emoji
- remark-rehype transforms markdown to HTML
- rehype-slug adds DOM ids to headings
- rehype-autolink-headings turns headings into links
- rehype-highlight.js applies syntax highlighting to code blocks using highlight.js
- rehype-stringify stringifies HTML
npm install hubdown --save
hubdown exports a single function that returns a promise:
const hubdown =
The resolved promise yields an object with a
containing the parsed HTML:
content: '<p>I am markdown</p>'
Usage with Cache
remark markdown parser is pretty fast, but things can start to slow
down when you're processing hundreds or thousands of files. To make life easier
in these situations you can use hubdown's optional cache, which stores
preprocessed markdown for fast retrieval on subsequent runs.
To use the cache, bring your own level instance and supply it as an option to hubdown. This helps keep hubdown lean on (native) dependencies for users who don't need the cache.
const hubdown =const cache = './my-hubdown-cache'
markdownStringString - (required)
optionsObject - (optional)
runBeforeArray of remark plugins - Custom plugins to be run before the commonly used plugins listed above.
frontmatterBoolean - Whether or not to try to parse YML frontmatter in the file. Defaults to
cacheLevelDB - An optional
levelinstance in which to store preprocessed content. See Usage with Cache.
Returns a promise. The resolved object looks like this:
content: 'HTML goes here'
If YML frontmatter is parsed, those properties will be present on the object too:
title: 'The Feminine Mystique'author: 'Betty Friedan'content: '<p>The Feminine Mystique is a book written by Betty Friedan which is widely credited with sparking the beginning of second-wave feminism in the United States.</p>'
npm installnpm test