mdast-util-find-and-replace is a utility within the unifiedjs ecosystem designed to find patterns (strings or regular expressions) within the text nodes of an mdast (Markdown Abstract Syntax Tree) and replace them with new mdast nodes. The current stable version is 3.0.2. It typically receives updates for bug fixes and minor enhancements, with major versions introducing breaking changes less frequently, as seen with the transition to v3.0.0. Key differentiators include its tight integration with the mdast specification, its ability to produce complex node structures as replacements, and its focus on efficient, preorder traversal. It's particularly useful for transforming markdown content programmatically, such as converting specific text patterns into links, mentions, or other AST elements.
npm install mdast-util-find-and-replaceVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to import `findAndReplace`, construct an mdast tree using `unist-builder`, and then apply multiple find-and-replace operations, including string, regex, and function-based replacements, before inspecting the modified tree.
Update your `list` argument: `find, replace` becomes `[find, replace]`, and `{find: replace, …}` becomes `[[find, replace], …]`.Ensure your Node.js environment is at least version 16.0.0. Update your runtime if necessary.
Remove any code that expects a return value from `findAndReplace`. The `tree` object passed as the first argument is modified directly.
Migrate your project to use ES modules (`import`/`export`) or use dynamic `import()` if you must `require` ESM packages from CommonJS. Alternatively, stick to `mdast-util-find-and-replace` v2 for CommonJS compatibility.
Change `const { findAndReplace } = require('mdast-util-find-and-replace')` to `import { findAndReplace } from 'mdast-util-find-and-replace'` and ensure your project is configured for ES modules (e.g., `"type": "module"` in `package.json`).Convert your replacement object to an array of tuples: `[[/pattern/g, 'replacement'], ['string', function(){...}]]`.No dependency data recorded yet.