Registry / serialization / mdast-util-phrasing

mdast-util-phrasing

JSON →
library4.1.0jsnpmunverified

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.

npm install mdast-util-phrasing
INSTALL
IMPORT
SIG · MDAST-UTIL-PHRASIN
M
mdast-util-phrasing
serializationjavascriptv4.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

phrasing
import { phrasing } from 'mdast-util-phrasing'
const phrasing = require('mdast-util-phrasing')
Package is ESM-only since v3.0.0; CommonJS `require` is not supported. There is no default export.
phrasing
import { phrasing } from 'mdast-util-phrasing'
import phrasing from 'mdast-util-phrasing'
The package does not have a default export; `phrasing` must be imported as a named export.
Node
import type { Node } from 'mdast'
This package ships its own types but works with `mdast` nodes. For `Node` types, import from the `mdast` package.

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
Debug
Known issues
breakingVersion 4.0.0 changed to require Node.js 16 or newer and utilizes an `export` map. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 16 or later. If using a bundler, ensure it supports `export` maps.
affects: >=4.0.0
breakingVersion 3.0.0 switched the package to be ESM-only. CommonJS `require()` statements will no longer work.
fix
Migrate your codebase to use ECMAScript Modules (ESM) `import` syntax. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions.
affects: >=3.0.0
breakingVersion 2.0.0 updated its dependency on `unist-util-is` which could be a breaking change, particularly for TypeScript users relying on specific type definitions from `unist-util-is`.
fix
Update `mdast-util-phrasing` and its peer dependencies (like `@types/mdast`) to the latest compatible versions to ensure correct type resolution.
affects: >=2.0.0 <3.0.0
gotchaThe `phrasing` function explicitly excludes `html` nodes from its check, returning `false` for them. This is because HTML can represent both phrasing and flow content, and the utility takes a conservative approach.
fix
If you need to classify `html` nodes, you will need to implement a custom check or use `hast-util-phrasing` for hast trees.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require()` to import `mdast-util-phrasing` after version 3.0.0, which is an ESM-only package.
fix
Change your import statement to `import { phrasing } from 'mdast-util-phrasing'` and ensure your environment supports ESM (e.g., `type: "module"` in `package.json` for Node.js).
TypeError: mdast_util_phrasing_1.phrasing is not a function
Incorrectly importing `phrasing` as a default export, when it is a named export.
fix
Use a named import: `import { phrasing } from 'mdast-util-phrasing';`
Module '"mdast-util-phrasing"' has no exported member 'phrasing'.
This TypeScript error often occurs due to mismatched `@types/mdast` versions or using an unsupported Node.js version (pre-16) with `mdast-util-phrasing@4+`.
fix
Ensure your Node.js version is 16 or newer. Update `@types/mdast` and `mdast-util-phrasing` to their latest compatible versions.
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies
unist-util-isrequiredUsed internally for core node type checking functionality.
Agent activity
2 hits · last 30 days
node
2
Resources
mdast-util-phrasing — npm install mdast-util-phrasing · libregistry