mdast-util-to-string is a focused utility within the unified ecosystem designed to extract the plain text content from an mdast (Markdown Abstract Syntax Tree) node or a list of nodes. It is currently stable at version 4.0.0. The project maintains compatibility with maintained versions of Node.js, typically releasing new major versions when older Node.js versions become unmaintained, which often includes breaking changes like switching to ESM or dropping specific API support. This package prioritizes text extraction over full markdown serialization, differentiating itself from `mdast-util-to-markdown`. It's particularly useful for scenarios like generating excerpts, search indexing, or displaying a node's textual content without its formatting, similar to `hast-util-to-string` for hast trees. It ships with full TypeScript support.
npm install mdast-util-to-stringVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to parse a markdown string into an mdast tree and then use `toString` to extract the plain text content from the entire tree or specific nodes, including options for handling HTML.
Upgrade your Node.js environment to version 16 or higher. If unable to upgrade, you must remain on mdast-util-to-string v3.x.
Migrate your codebase to use ES Modules (ESM) import syntax: `import { toString } from 'mdast-util-to-string'`. Avoid using internal or private paths.Review your markdown structures and mdast processing logic. If you need to extract titles, ensure they are represented in other supported node properties or structures that `toString` can process.
Use the `includeImageAlt: false` option to ignore image alt text or `includeHtml: false` to ignore HTML node values if you do not want them included in the output string.
Change `const toString = require('mdast-util-to-string')` to `import { toString } from 'mdast-util-to-string'` and ensure your project is configured for ESM.Use `import { toString } from 'mdast-util-to-string'` instead of `require`. Ensure your `package.json` either has `"type": "module"` or uses `.mjs` file extensions for ESM files.Upgrade Node.js to version 16+ and ensure your `package.json` contains `"type": "module"` or explicitly use `.mjs` file extensions for your module files.
No dependency data recorded yet.