mdast-util-heading-range is a utility for working with Markdown Abstract Syntax Trees (MDAST) to identify and manipulate content sections defined by headings. It allows developers to find a specific heading, capture all content nodes within its section (up to the next heading of the same or lower depth, or the end of the document), and then apply a handler function to modify or replace that content. The current stable version is 4.0.0, released in a mostly ad-hoc fashion following the syntax-tree ecosystem's release schedule, typically with minor versions for features and patch versions for fixes. Key differentiators include its focus on heading-based content segmentation, offering a programmatic way to update generated sections (like a Table of Contents), and its integration within the broader `unified` and `remark` ecosystem. It is an ESM-only package since version 3.0.0 and requires Node.js 16 or higher as of version 4.0.0.
npm install mdast-util-heading-rangeVerified import paths — ran on the pinned version, not inferred.
Demonstrates finding the 'Foo' heading section and replacing its content with new nodes using the `headingRange` utility.
Upgrade your Node.js environment to version 16 or newer. Use `nvm install 16` or similar.
Ensure you are using the public API entry points. Avoid using private or undocumented internal paths. Modern bundlers and Node.js generally handle `export` maps correctly with standard imports.
Update all type imports and references from `ZoneInfo` to `Info`. For example, `import type { ZoneInfo } from '...'` becomes `import type { Info } from '...'`.Migrate your project to use ES modules (`import`/`export`) or use dynamic `import()` for loading the package. Ensure your `package.json` includes `"type": "module"` or uses `.mjs` file extensions.
Be aware of this option's effect if your sections might contain definitions. If you need to process or retain final definitions within a section, ensure `ignoreFinalDefinitions` is not set to `true` or handle them explicitly outside the `headingRange` call.
Change `const { headingRange } = require('mdast-util-heading-range')` to `import { headingRange } from 'mdast-util-heading-range'` and ensure your project is configured for ES modules (e.g., `"type": "module"` in `package.json`).Ensure the `tree` argument is a valid `mdast.Root` node and that any nodes returned by the handler conform to `mdast.Node` types. Review type definitions, especially after `v4.0.0`'s `@types/mdast` update.
Provide a string for the heading text, an array of strings, a regular expression, a test function, or an options object with a `test` property. Example: `headingRange(tree, 'My Heading', handler)` or `headingRange(tree, { test: 'My Heading' }, handler)`.No dependency data recorded yet.