HAST Phrasing Content Utility

3.0.1 · active · verified Sun Apr 19

hast-util-phrasing is a niche utility within the unified (remark/rehype) ecosystem, specifically designed to determine if a given HAST (Hypertext Abstract Syntax Tree) node represents 'phrasing content' according to HTML specifications. This classification is crucial for advanced HTML manipulation and validation scenarios. The package is currently at version 3.0.1, indicating active maintenance and regular, albeit minor, updates since its major release. It adheres to the unified collective's release cadence, typically aligning major versions with Node.js LTS support lifecycles. Its key differentiator is its precise adherence to HTML phrasing content rules, making it invaluable for tools that need to strictly adhere to HTML parsing and serialization standards, particularly in content transformation pipelines.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `phrasing` utility with various HAST node types to check if they qualify as phrasing content according to HTML specifications, illustrating different outcomes.

import { phrasing } from 'hast-util-phrasing';

// Example 1: A div element, which is typically flow content and not phrasing.
const divNode = {
  type: 'element',
  tagName: 'div',
  children: [{ type: 'text', value: 'Hello' }]
};
console.log('Is <div> phrasing content?', phrasing(divNode));
// Expected: false

// Example 2: A meta element with 'itemProp', which can be phrasing content.
const metaItemPropNode = {
  type: 'element',
  tagName: 'meta',
  properties: { itemProp: 'description' },
  children: []
};
console.log('Is <meta itemprop> phrasing content?', phrasing(metaItemPropNode));
// Expected: true

// Example 3: A meta element with 'charset', which is not phrasing content.
const metaCharsetNode = {
  type: 'element',
  tagName: 'meta',
  properties: { charSet: 'utf8' },
  children: []
};
console.log('Is <meta charset> phrasing content?', phrasing(metaCharsetNode));
// Expected: false

// Example 4: A text node, which is always phrasing content.
const textNode = { type: 'text', value: 'Some text' };
console.log('Is text node phrasing content?', phrasing(textNode));
// Expected: true

view raw JSON →