Remarkable Markdown Parser
Remarkable is a fast, extensible Markdown parser for JavaScript, offering 100% CommonMark specification support, alongside syntax extensions and typographer features. Currently at version 2.0.1, the library provides a robust solution for converting Markdown strings to HTML. Its key differentiators include high performance, a highly configurable parsing engine that allows adding or replacing syntax rules, and a vibrant community plugin ecosystem available via npm. Version 2.0.0 introduced significant changes, including a migration to ES module source code, rollup-based bundling for UMD, CJS, and ESM formats, and a shift to named exports for its public API. The project maintains an active development status, with updates focusing on stability and modern JavaScript practices.
Common errors
-
TypeError: Remarkable is not a constructor
cause Attempting to instantiate `Remarkable` using a default import or incorrect CommonJS require after the v2.0.0 breaking change to named exports.fixFor ESM, use `import { Remarkable } from 'remarkable';`. For CommonJS, use `const { Remarkable } = require('remarkable');`. -
ERR_MODULE_NOT_FOUND: Cannot find module 'remarkable/lib/some-internal-module'
cause Attempting to import from the internal `lib` directory, which is no longer published or supported since v2.0.0.fixOnly import directly from the main `remarkable` package (`import { Remarkable } from 'remarkable';`). Internal modules are not part of the public API.
Warnings
- breaking The default import `import Remarkable from 'remarkable'` was removed in v2.0.0. The library now exclusively uses named exports for its public API.
- breaking The internal `lib` directory is no longer published or considered part of the public API since v2.0.0. Direct imports from `remarkable/lib/...` are unsupported and will break.
- breaking Bower support was officially removed in v2.0.0 due to its deprecation in modern web development workflows.
- gotcha Modifying a `Remarkable` instance on the fly using `md.set()` can negatively impact performance. For optimal speed, it is recommended to create separate instances for different configurations.
Install
-
npm install remarkable -
yarn add remarkable -
pnpm add remarkable
Imports
- Remarkable
import Remarkable from 'remarkable';
import { Remarkable } from 'remarkable'; - Remarkable (CommonJS)
const Remarkable = require('remarkable');const { Remarkable } = require('remarkable'); - RemarkablePresets
const md = new Remarkable('commonmark');
Quickstart
import { Remarkable } from 'remarkable';
// Initialize Remarkable with default settings (similar to GFM, but HTML disabled)
const md = new Remarkable();
// Render a basic Markdown string to HTML
const markdownString = '# Hello, Remarkable!\n\nThis is a *simple* paragraph.';
const htmlOutput = md.render(markdownString);
console.log('--- Default Rendering ---');
console.log(htmlOutput);
// Expected output: <h1>Hello, Remarkable!</h1><p>This is a <em>simple</em> paragraph.</p>
// Demonstrate a common preset: 'commonmark'
const mdCommonMark = new Remarkable('commonmark');
const commonMarkOutput = mdCommonMark.render('1. Ordered list item\n\n- Unordered list item');
console.log('\n--- CommonMark Preset Rendering ---');
console.log(commonMarkOutput);
// Demonstrate setting options via constructor
const mdWithOptions = new Remarkable({
html: true, // Enable HTML tags in source
breaks: true, // Convert '\n' in paragraphs into <br>
typographer: true // Enable smart quotes and other typographic improvements
});
const complexMarkdown = `
# Markdown with Options
<p>This is an HTML paragraph.</p>
Line one.
Line two.
"Smart quotes" should be enabled.
`;
const complexHtmlOutput = mdWithOptions.render(complexMarkdown);
console.log('\n--- Rendering with Custom Options ---');
console.log(complexHtmlOutput);