{"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,"search_vec":"'16':145 '3.0.1':80 'abstract':28 'adher':43,113 'align':93 'bodi':3,10,46,150 'broader':88 'browser':147 'checker':5 'collect':90 'compat':100 'comprehens':122 'criteria':48 'current':77 'defin':50 'definit':132 'design':22 'determin':37 'develop':140 'differenti':109 'document':67 'ecosystem':20,97 'element':42 'ensur':99 'environ':148 'exist':60 'experi':141 'full':129 'function':34 'given':40 'hast':1,7,26,103,151,153 'hast-util':152 'hast-util-is-body-ok-link':6 'html':27,54,66,155 'integr':119 'javascript':149 'key':108 'link':2,12,41,156 'maintain':83 'major':95 'markdown/html':123 'mean':56 'node':31 'node.js':143 'ok':4,11,47,157 'packag':16 'part':85 'pipelin':125 'plugin':106 'primari':33 'process':124 'provid':133 'rather':68 'rehyp':105 'rehypej':89 'releas':91 'restrict':71 'robust':135 'safe':59,139 'section':63 'ship':127 'specif':21 'standard':55,116 'strict':112 'syntax':29 'tree':30 'type':131,138 'type-saf':137 'typescript':130,160 'typic':92 'unifi':19,96 'unist':158 'updat':98 'util':8,15,75,154,159 'version':79,144 'web':115 'whatwg':53 'within':17,61 'work':24","created_at":"2026-04-19T13:35:44.617373+00:00","updated_at":"2026-04-19T13:35:44.617373+00:00","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","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/rehypejs/rehype-minify.git#main","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/hast-util-is-body-ok-link","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}