hast-util-excerpt is a utility within the unified (specifically hast/rehype) ecosystem designed to truncate an HTML (hast) syntax tree based on an explicit comment marker, typically `<!--more-->`. This allows authors to precisely define where a document's 'excerpt' or 'summary' should end, offering more control than character-count-based truncation methods. The current stable version is 2.0.0, which introduced significant breaking changes by moving to ESM-only and requiring Node.js 16 or newer. Releases occur as changes accumulate, rather than on a fixed schedule. Its primary differentiator is the author-defined explicit truncation point, making it suitable for content management systems or static site generators where content creators need fine-grained control over document summaries. It works by traversing the tree and stopping at the specified comment, returning a modified clone of the original tree.
npm install hast-util-excerptVerified import paths — ran on the pinned version, not inferred.
Demonstrates truncating a hast (HTML) tree at a `<!--more-->` comment marker, including an example with a custom comment.
Migrate your project to use ES modules (`import`/`export`) or stick to `hast-util-excerpt@1` if CommonJS is strictly necessary.
Update your Node.js runtime to version 16 or later. If you need to support older Node.js versions, use `hast-util-excerpt@1`.
Ensure you only import and use the officially exported `excerpt` function. Avoid deep imports or relying on internal module structures.
If your excerpt comment is expected to be deep within a very large document, increase `maxSearchSize` in the options: `excerpt(tree, { maxSearchSize: 5000 })`.Change `const { excerpt } = require('hast-util-excerpt');` to `import { excerpt } from 'hast-util-excerpt';` and ensure your project is set up for ES Modules (e.g., `"type": "module"` in `package.json`).Update Node.js to version 16 or higher. Also, ensure your `package.json` correctly specifies `"type": "module"` if you are using ES modules, or stick to `hast-util-excerpt@1` if using an older Node.js or strictly CommonJS.
Ensure you are using named import: `import { excerpt } from 'hast-util-excerpt';`. The `excerpt` function is not a default export.No dependency data recorded yet.