Registry / web-framework / micromark

micromark

JSON →
library4.0.2jsnpmunverified

micromark is a small, CommonMark-compliant markdown parser implemented in JavaScript as a state machine. It is designed to be highly performant and robust, emitting concrete tokens with positional information, which are then compiled directly to HTML. The current stable version is 4.0.2, released as part of an actively maintained monorepo. It maintains a consistent release cadence, with minor updates and patches addressing performance improvements and bug fixes, as seen in recent 4.0.x releases. A key differentiator is its strict adherence to CommonMark and GFM specifications, further validated by thousands of additional tests that align with reference parser behavior. It also supports popular extensions such as MDX, math, and frontmatter, and is built with security in mind, being safe by default. Its design allows for both straightforward markdown-to-HTML conversion and highly complex markdown processing workflows, making it a foundational tool in the `unified` ecosystem.

npm install micromark
INSTALL
IMPORT
SIG · MICROMARK
M
micromark
web-frameworkjavascriptv4.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

micromark
import { micromark } from 'micromark'
const { micromark } = require('micromark')
micromark is ESM-only since v4.0.0. CommonJS `require` will result in an error.
gfm
import { gfm } from 'micromark-extension-gfm'
import gfm from 'micromark-extension-gfm'
Extensions like GFM are typically named exports, not default exports.
gfmHtml
import { gfmHtml } from 'micromark-extension-gfm'
import * as gfmExtensions from 'micromark-extension-gfm'
Most micromark HTML extensions export specific named functions, not a single object. Importing specific functions is recommended.

This example demonstrates parsing a markdown string, including GitHub Flavored Markdown (GFM) extensions like task lists, autolinks, and strikethrough, and outputting the corresponding HTML. It shows how to integrate optional extensions.

import { micromark } from 'micromark' import { gfmHtml, gfm } from 'micromark-extension-gfm' const markdownValue = '* [x] contact@example.com ~~strikethrough~~\n\n# Hello World\n\nThis is a paragraph with some **bold** text.' const result = micromark(markdownValue, { extensions: [gfm()], htmlExtensions: [gfmHtml()] }) console.log(result) /* Yields: <ul> <li><input checked="" disabled="" type="checkbox"> <a href="mailto:contact@example.com">contact@example.com</a> <del>strikethrough</del></li> </ul> <h1>Hello World</h1> <p>This is a paragraph with some <strong>bold</strong> text.</p> */
Debug
Known issues
breaking`micromark` is ESM-only starting from version 4.0.0. Attempting to use CommonJS `require()` will result in an `ERR_REQUIRE_ESM` error.
fix
Migrate your project to use ES modules (`import`) or ensure your build system transpiles CommonJS imports correctly. For Node.js, ensure your package.json `type` field is set to `module` or use `.mjs` file extensions.
affects: >=4.0.0
gotchaWhen using extensions like GFM, you must provide both the `extensions` array (for parsing the markdown syntax) and the `htmlExtensions` array (for compiling to HTML) to the `micromark` options object.
fix
Always include both `extensions: [yourExtension()]` and `htmlExtensions: [yourExtensionHtml()]` when configuring extensions, as shown in the quickstart example.
affects: >=1.0.0
gotcha`micromark` is a low-level parser that directly outputs HTML. If you need an Abstract Syntax Tree (AST) for more complex manipulation (e.g., transformations, linting), you should use higher-level tools from the `unified` ecosystem like `mdast-util-from-markdown`.
fix
For AST generation and manipulation, integrate `mdast-util-from-markdown` and other `mdast` utilities into your workflow, which build upon `micromark`'s token stream.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module .../node_modules/micromark/index.js from ... not supported.
Attempting to import `micromark` using CommonJS `require()` syntax in a non-ESM context.
fix
Update your code to use ES module `import { micromark } from 'micromark'` and ensure your project or file is configured for ESM (e.g., `"type": "module"` in `package.json` or using `.mjs` extension).
GitHub Flavored Markdown features (e.g., task lists, strikethrough) are not rendered correctly.
Only the `extensions` option was provided to `micromark`, but not the `htmlExtensions` for HTML output.
fix
Ensure both `extensions: [gfm()]` and `htmlExtensions: [gfmHtml()]` are passed to the `micromark` function's options, where `gfm` and `gfmHtml` are imported from `micromark-extension-gfm`.
TypeError: micromark is not a function
This error often occurs when trying to call `micromark()` after a CommonJS `require('micromark')` statement, which due to `micromark` being ESM-only, results in the imported value not being the expected function.
fix
Verify that you are using `import { micromark } from 'micromark'` and that your environment supports ES modules, or adjust your build pipeline to handle ESM.
Upgrade
Version history
4.0.2latest on npm
Audit
Dependencies
micromark-extension-gfmoptionalCommonly used extension for GitHub Flavored Markdown, shown in quickstart.
Agent activity
6 hits · last 30 days
node
6
Resources
micromark — npm install micromark · libregistry