mdast Paragraph Squeezer

6.0.0 · active · verified Sun Apr 19

mdast-squeeze-paragraphs is a focused utility within the unified ecosystem, specifically designed to remove empty paragraphs from an mdast (Markdown Abstract Syntax Tree) tree. It identifies and eliminates paragraphs that contain no non-whitespace characters, often a result of previous tree transformations. The current stable version is 6.0.0. Releases are typically tied to Node.js LTS cycles, with new major versions dropping support for unmaintained Node.js versions. A key differentiator and notable recommendation from its maintainers is that developers should 'probably never!' use this package directly, encouraging users to clean their trees themselves or use the higher-level `remark-squeeze-paragraphs` plugin instead. This package is primarily intended for authors of other mdast utilities or plugins who need fine-grained control over tree sanitation at a low level.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use `squeezeParagraphs` to remove empty paragraphs from an mdast tree created with `unist-builder`.

import {squeezeParagraphs} from 'mdast-squeeze-paragraphs';
import {u} from 'unist-builder';

const tree = u('root', [
  u('paragraph', []),
  u('paragraph', [u('text', 'Alpha')]),
  u('paragraph', [u('text', ' ')])
]);

squeezeParagraphs(tree);

console.dir(tree, {depth: null});
// Expected output:
// { type: 'root',
//   children:
//    [ { type: 'paragraph',
//        children: [ { type: 'text', value: 'Alpha' } ] } ] }

view raw JSON →