mdast Phrasing Content Utility

4.1.0 · active · verified Sun Apr 19

mdast-util-phrasing is a specialized utility within the unified (syntax-tree) ecosystem designed to accurately identify if a given mdast (Markdown Abstract Syntax Tree) node constitutes "phrasing content." This includes elements like text, emphasis, strong, links, and code spans, but notably excludes `html` nodes due to their dual nature as both phrasing and flow content. The package is currently stable at version 4.1.0 and is actively maintained by the unified collective, with major releases typically aligning with Node.js LTS version updates or significant architectural shifts, such as the transition to ESM-only in version 3.0.0. Its core functionality relies on `unist-util-is` for robust node testing, making it a foundational tool for building other mdast utilities that need to differentiate between inline and block-level content in Markdown.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `phrasing` function to determine if an mdast node is phrasing content, showing examples for paragraph, strong, and HTML nodes.

import { phrasing } from 'mdast-util-phrasing';
import { paragraph, strong, text } from 'mdast-builder';

// Example 1: A paragraph is not phrasing content
const paragraphNode = paragraph([text('Alpha')]);
console.log(`Is paragraph node phrasing content? ${phrasing(paragraphNode)}`);

// Example 2: A strong node (inline) is phrasing content
const strongNode = strong([text('Delta')]);
console.log(`Is strong node phrasing content? ${phrasing(strongNode)}`);

// Example 3: An HTML node is explicitly excluded and returns false
const htmlNode = { type: 'html', value: '<span>Hello</span>' };
console.log(`Is HTML node phrasing content? ${phrasing(htmlNode)}`);

// Output:
// Is paragraph node phrasing content? false
// Is strong node phrasing content? true
// Is HTML node phrasing content? false

view raw JSON →