{"id":11003,"library":"hast-util-is-body-ok-link","title":"HAST Link Body OK Checker","description":"hast-util-is-body-ok-link is a utility package within the `unified` ecosystem, specifically designed for working with HAST (HTML Abstract Syntax Tree) nodes. Its primary function is to determine if a given `link` element adheres to the “Body OK” criteria as defined by the WHATWG HTML standard, meaning it can safely exist within the `<body>` section of an HTML document rather than being restricted to the `<head>`. This utility is currently at version `3.0.1` and is maintained as part of the broader `rehypejs` collective. Releases typically align with major `unified` ecosystem updates, ensuring compatibility with other `hast` and `rehype` plugins. A key differentiator is its strict adherence to web standards and its integration into a comprehensive Markdown/HTML processing pipeline. It ships with full TypeScript type definitions, providing a robust and type-safe development experience for Node.js (version 16+) and browser environments.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/rehypejs/rehype-minify#main","tags":["javascript","body","hast","hast-util","html","link","ok","unist","util","typescript"],"install":[{"cmd":"npm install hast-util-is-body-ok-link","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-is-body-ok-link","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-is-body-ok-link","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used to create HAST nodes for testing or examples, not a runtime dependency for `isBodyOkLink` itself.","package":"hastscript","optional":true}],"imports":[{"note":"This package is ESM-only since version 3.0.0, and has no default export.","wrong":"const isBodyOkLink = require('hast-util-is-body-ok-link')","symbol":"isBodyOkLink","correct":"import { isBodyOkLink } from 'hast-util-is-body-ok-link'"},{"note":"There is no default export; the function is a named export.","wrong":"import isBodyOkLink from 'hast-util-is-body-ok-link'","symbol":"isBodyOkLink","correct":"import { isBodyOkLink } from 'hast-util-is-body-ok-link'"},{"note":"While not directly from this package, importing `Node` type from `hast` is common for type-checking when working with HAST utilities.","symbol":"Node","correct":"import type { Node } from 'hast'"}],"quickstart":{"code":"import { h } from 'hastscript';\nimport { isBodyOkLink } from 'hast-util-is-body-ok-link';\n\n// Example 1: Link with itemProp (Body OK)\nconst link1 = h('link', { itemProp: 'foo' });\nconsole.log('Link with itemProp:', isBodyOkLink(link1)); // Expected: true\n\n// Example 2: Stylesheet link (Body OK)\nconst link2 = h('link', { rel: ['stylesheet'], href: 'index.css' });\nconsole.log('Stylesheet link:', isBodyOkLink(link2)); // Expected: true\n\n// Example 3: Author link (Not Body OK)\nconst link3 = h('link', { rel: ['author'], href: 'index.css' });\nconsole.log('Author link:', isBodyOkLink(link3)); // Expected: false\n\n// Example 4: Pingback link (Body OK)\nconst link4 = h('link', { rel: ['pingback'], href: 'ping.xml' });\nconsole.log('Pingback link:', isBodyOkLink(link4)); // Expected: true\n\n// Example 5: Non-link element\nconst div = h('div', 'Hello');\nconsole.log('Non-link element:', isBodyOkLink(div)); // Expected: false (or handles as invalid HAST Node gracefully)","lang":"typescript","description":"Demonstrates how to import and use `isBodyOkLink` to check various HAST `link` nodes and a non-link node for 'Body OK' compatibility according to WHATWG HTML specifications."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16 or higher.","message":"Version 3.0.0 and later of `hast-util-is-body-ok-link` (and the `unified` ecosystem it belongs to) require Node.js 16 or newer. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Refactor your import statements to use ES Modules (e.g., `import { isBodyOkLink } from 'hast-util-is-body-ok-link';`).","message":"`hast-util-is-body-ok-link` is an ESM-only package since version 3.0.0. Attempting to use CommonJS `require()` statements will result in an `ERR_REQUIRE_ESM` error.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure all related `unified`, `rehype`, and `hast` packages in your project are updated to their latest compatible major versions.","message":"Version 3.0.0 aligns with major updates across the `unified` and `hast` ecosystems (e.g., `unified` v11, `@types/hast` updates). This may necessitate updating other `hast` utilities and plugins to their latest compatible major versions.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always integrate `rehype-sanitize` into your `rehype` processing pipeline when dealing with HTML from untrusted sources to mitigate XSS risks.","message":"When processing untrusted HTML content, directly using `rehype` and its utilities like this without explicit sanitization can lead to Cross-Site Scripting (XSS) vulnerabilities.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Switch to ES module import syntax: `import { isBodyOkLink } from 'hast-util-is-body-ok-link';`.","cause":"Attempting to use `require('hast-util-is-body-ok-link')` in a CommonJS environment, but the package is ESM-only.","error":"ERR_REQUIRE_ESM"},{"fix":"Use a named import: `import { isBodyOkLink } from 'hast-util-is-body-ok-link';`.","cause":"The `isBodyOkLink` function was imported incorrectly, likely as a default import (`import isBodyOkLink from '...'`) when it is a named export.","error":"TypeError: isBodyOkLink is not a function"},{"fix":"Ensure the `node` argument is a properly constructed HAST `Node` object before passing it to `isBodyOkLink`.","cause":"The `node` argument passed to `isBodyOkLink` is `undefined`, `null`, or an object that does not conform to the expected HAST `Node` structure, preventing access to its `type` property.","error":"TypeError: Cannot read properties of undefined (reading 'type')"}],"ecosystem":"npm"}