unified

Project: syntax-tree/mdast-squeeze-paragraphs

Package: mdast-squeeze-paragraphs@4.0.0

  1. Dependencies: 1·Dependents: 9
  2. mdast utility to remove empty paragraphs from a tree
  1. util 118
  2. utility 114
  3. unist 110
  4. mdast 81
  5. tree 42
  6. mdast-util 24
  7. remove 10
  8. whitespace 6
  9. transform 6
  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 from a tree.

Paragraphs are considered empty if they do not contain non-whitespace characters.

Install

npm:

npm install mdast-squeeze-paragraphs

Use

var u = require('unist-builder')
var squeezeParagraphs = require('mdast-squeeze-paragraphs')

var 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

squeezeParagraphs(tree)

Modifies tree in-place. Returns tree.

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