hast-util-to-text is a utility for the unified ecosystem that extracts the plain-text value from a HAST (HTML Abstract Syntax Tree) node. It approximates the DOM's `Node#innerText` algorithm, which is more user-friendly than `Node#textContent` (like `hast-util-to-string`) by converting `<br>` elements into line breaks and using tabs (`\t`) between table cells. The package is currently at version 4.0.2, actively maintained, and primarily releases patch versions for fixes and minor updates for new features, with major versions reserved for breaking changes. Its key differentiator is its adherence to the `innerText`-like behavior, providing a textual representation that reflects how content would be visually rendered, although it cannot account for dynamic CSS properties like `display: none` or `text-transform`.
npm install hast-util-to-textVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `toText` to convert a HAST tree into a plain-text string, showing how it handles line breaks from `<br>` and tabs in table cells.
Upgrade your Node.js environment to version 16 or newer. Use `nvm install 16` or update your CI/CD configuration.
Ensure your build tooling and Node.js version support the `exports` field. Always use `import` statements for ESM modules. Avoid using private APIs if previously done.
Migrate your codebase to use ES Modules (`import ... from '...'`) for this package. If you must use CommonJS, consider transpiling your code or sticking to an older major version (e.g., `<3.0.0`).
Review the changelog for `unist-util-find-after` and `hast-util-to-text` v2.0.0. Update `@types/unist` and related packages to ensure type compatibility.
Be aware of these limitations. If exact DOM `innerText` behavior is required, consider using a headless browser environment (e.g., Puppeteer, JSDOM) to render and extract text, as `hast-util-to-text` cannot interpret CSS.
Change `const { toText } = require('hast-util-to-text')` to `import { toText } from 'hast-util-to-text'`.Ensure you are using named imports: `import { toText } from 'hast-util-to-text'`.Update Node.js to version 16 or newer. Ensure your build tooling (e.g., webpack, Rollup, Parcel) is up-to-date and configured to handle ESM and `exports` maps correctly.
No dependency data recorded yet.