Registry / serialization / mdast-util-to-markdown

mdast-util-to-markdown

JSON →
library2.1.2jsnpmunverified

mdast-util-to-markdown is a low-level utility for serializing an mdast (Markdown Abstract Syntax Tree) syntax tree back into a Markdown string. It is currently at version 2.1.2. The package maintains an active release cadence, frequently publishing patch and minor versions for bug fixes and new features, with major versions reserved for significant breaking changes, such as Node.js version requirement updates or fundamental API shifts. This utility differentiates itself by providing direct, granular control over the Markdown serialization process, contrasting with higher-level solutions like `remark-stringify` which abstract away these internals. It is a core component within the unified `syntax-tree` ecosystem and is designed to be highly extensible through integration with other `mdast-util` packages, enabling support for various Markdown extensions like GFM, MDX, and frontmatter. Developers typically use this package when manual syntax tree manipulation is required, rather than relying on a full-fledged Markdown processor.

npm install mdast-util-to-markdown
INSTALL
IMPORT
SIG · MDAST-UTIL-TO-MARK
M
mdast-util-to-markdown
serializationjavascriptv2.1.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.

toMarkdown
import { toMarkdown } from 'mdast-util-to-markdown'
const toMarkdown = require('mdast-util-to-markdown')
This package is ESM-only in Node.js environments since v2.0.0, so `require()` is not supported.
defaultHandlers
import { defaultHandlers } from 'mdast-util-to-markdown'
const { defaultHandlers } = require('mdast-util-to-markdown')
As an ESM-only package, `defaultHandlers` must be imported using `import` syntax.
Options
import type { Options } from 'mdast-util-to-markdown'
import { Options } from 'mdast-util-to-markdown'
When using TypeScript, always import types with `import type` to avoid bundling issues or runtime errors if the symbol is not an actual value.

Demonstrates how to import and use `toMarkdown` to serialize an mdast syntax tree into a Markdown string, highlighting proper character escaping.

/** * @import {Root} from 'mdast' */ import {toMarkdown} from 'mdast-util-to-markdown' /** @type {Root} */ const tree = { type: 'root', children: [ { type: 'blockquote', children: [ {type: 'thematicBreak'}, { type: 'paragraph', children: [ {type: 'text', value: '- a\nb !'}, { type: 'link', url: 'example.com', children: [{type: 'text', value: 'd'}] } ] } ] } ] } console.log(toMarkdown(tree))
Debug
Known issues
breakingVersion 2.0.0 changed the minimum required Node.js version to 16. Older Node.js environments are no longer supported.
fix
Upgrade your Node.js environment to version 16 or newer. Use nvm or a similar tool to manage Node.js versions.
affects: >=2.0.0
breakingVersion 2.0.0 switched to using `exports` maps. Direct access to internal or private APIs via non-explicit import paths may break.
fix
Ensure you are only importing publicly documented APIs from the package. Avoid deep imports (e.g., `mdast-util-to-markdown/lib/foo`).
affects: >=2.0.0
breakingThe `bulletOrderedOther` option was removed in v2.0.0 as its functionality became the default. Passing this option will have no effect or may cause errors if not handled gracefully by your code.
fix
Remove the `bulletOrderedOther` option from your `toMarkdown` options object if you were previously setting it.
affects: >=2.0.0
breakingThe default value for the `fences` option changed to `true` in v2.0.0. If you relied on the previous default of `false` for fenced code blocks, your output may change.
fix
If you require `fences: false`, explicitly set `fences: false` in the `options` object passed to `toMarkdown`.
affects: >=2.0.0
gotchaEarlier versions (pre-2.1.1) had issues with round-tripping 'attention' (strong/emphasis) by incorrectly encoding surrounding characters, potentially leading to malformed Markdown output.
fix
Update to `mdast-util-to-markdown@2.1.1` or newer to ensure correct encoding of attention. This fix prevents incorrect markdown generation around strong/emphasis characters.
affects: <2.1.1
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require()` to import `mdast-util-to-markdown` in a CommonJS context.
fix
Convert your module to ES Modules or use dynamic `import()` if you cannot switch entirely. For example, replace `const toMarkdown = require('mdast-util-to-markdown')` with `import { toMarkdown } from 'mdast-util-to-markdown'`.
TypeError: Cannot read properties of undefined (reading 'type')
The `tree` argument passed to `toMarkdown` is `undefined`, `null`, or an invalid object that lacks a `type` property.
fix
Ensure that the `tree` variable you are passing to `toMarkdown` is a valid mdast node object, typically a `Root` or other compatible node, as documented by the mdast specification.
Error: Cannot find module 'mdast-util-to-markdown'
The package `mdast-util-to-markdown` has not been installed or the import path is incorrect.
fix
Run `npm install mdast-util-to-markdown` to install the package. Verify that the import statement `import { toMarkdown } from 'mdast-util-to-markdown'` uses the correct package name.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
mdast-util-to-markdown — npm install mdast-util-to-markdown · libregistry