unified

Project: syntax-tree/mdast-squeeze-paragraphs

Package: mdast-squeeze-paragraphs@5.2.0

  1. Dependents: 0
  2. mdast utility to remove empty paragraphs from a tree
  1. util 147
  2. utility 143
  3. unist 133
  4. mdast 88
  5. tree 44
  6. mdast-util 31
  7. remove 10
  8. whitespace 7
  9. transform 7
  10. clean 6
  11. paragraph 4
  12. squeeze 3
  13. empty 3

mdast-squeeze-paragraphs

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to remove empty paragraphs.

Contents

What is this?

This package is a utility that removes empty paragraphs, left over from other operations, from the tree. Paragraphs are considered empty if they do not contain non-whitespace characters.

When should I use this?

Probably never! You should try to clean your trees yourself.

A plugin, remark-squeeze-paragraphs, exists that does the same but for remark.

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install mdast-util-squeeze-paragraphs

In Deno with esm.sh:

import {squeezeParagraphs} from 'https://esm.sh/mdast-util-squeeze-paragraphs@5'

In browsers with esm.sh:

<script type="module">
  import {squeezeParagraphs} from 'https://esm.sh/mdast-util-squeeze-paragraphs@5?bundle'
</script>

Use

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

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

squeezeParagraphs(tree)

console.dir(tree, {depth: null})

Yields:

{ type: 'root',
  children:
   [ { type: 'paragraph',
       children: [ { type: 'text', value: 'Alpha' } ] } ] }

API

This package exports the identifier squeezeParagraphs. There is no default export.

squeezeParagraphs(tree)

Remove empty paragraphs in tree (Node).

Returns

The given tree (Node).

Types

This package is fully typed with TypeScript. There are no additional types exported.

Compatibility

Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.

Security

Use of mdast-squeeze-paragraphs does not involve hast or user content so there are no openings for cross-site scripting (XSS) attacks.

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Eugene Sharygin