mdast-zone is a utility within the `syntax-tree` ecosystem designed to manipulate Markdown Abstract Syntax Trees (mdast) by identifying and modifying content sections defined by HTML comments. It provides a `zone` function that takes an mdast tree, a comment name (e.g., 'foo'), and a handler function. This handler receives the `start` comment, the `nodes` between the comments, and the `end` comment, allowing developers to replace or modify the content within these defined zones. The current stable version is 6.1.0, and new releases, including major versions, appear roughly annually, with minor and patch updates in between, demonstrating active maintenance. It differentiates itself from similar utilities like `mdast-util-heading-range` by using hidden HTML comments as markers for sections rather than visible headings, making it suitable for programmatic content generation or manipulation where markers should not be visible in the rendered output. This package is ESM-only and requires Node.js 16+ since v6.0.0.
npm install mdast-zoneVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to define a content zone using HTML comments (`<!--foo start-->` and `<!--foo end-->`) and then replace the content within that zone using the `mdast-zone` utility within a `remark` plugin. It logs the original content found and replaces it with a new paragraph.
Migrate your project to use ES modules (`import`) or ensure you are loading mdast-zone in an ESM context. Update Node.js to v16 or later.
Upgrade your Node.js environment to version 16 or newer.
Update all references to `ZoneInfo` to `Info` in your TypeScript code.
Ensure your module bundler or Node.js environment is configured to correctly resolve `export` maps. Avoid using private or undocumented APIs.
Review your TypeScript code for any direct or indirect usage of `unist-util-visit` types and update accordingly.
Change `const { zone } = require('mdast-zone');` to `import { zone } from 'mdast-zone';` and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).Ensure `unified` is installed (`npm install unified`) and imported if you're using TypeScript annotations like `import('unified').Plugin`.Replace `ZoneInfo` with `Info` in your TypeScript code.