HAST Link Body OK Checker

3.0.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { h } from 'hastscript';
import { isBodyOkLink } from 'hast-util-is-body-ok-link';

// Example 1: Link with itemProp (Body OK)
const link1 = h('link', { itemProp: 'foo' });
console.log('Link with itemProp:', isBodyOkLink(link1)); // Expected: true

// Example 2: Stylesheet link (Body OK)
const link2 = h('link', { rel: ['stylesheet'], href: 'index.css' });
console.log('Stylesheet link:', isBodyOkLink(link2)); // Expected: true

// Example 3: Author link (Not Body OK)
const link3 = h('link', { rel: ['author'], href: 'index.css' });
console.log('Author link:', isBodyOkLink(link3)); // Expected: false

// Example 4: Pingback link (Body OK)
const link4 = h('link', { rel: ['pingback'], href: 'ping.xml' });
console.log('Pingback link:', isBodyOkLink(link4)); // Expected: true

// Example 5: Non-link element
const div = h('div', 'Hello');
console.log('Non-link element:', isBodyOkLink(div)); // Expected: false (or handles as invalid HAST Node gracefully)

view raw JSON →