unified

Project: syntax-tree/mdast-util-compact

Package: mdast-util-compact@2.0.1

  1. Dependencies: 1·Dependents: 11
  2. mdast utility to make a tree compact
  1. util 118
  2. utility 114
  3. unist 110
  4. mdast 81
  5. tree 42
  6. mdast-util 24
  7. node 21

mdast-util-compact

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to make trees compact: collapse adjacent text nodes and blockquotes.

Install

npm:

npm install mdast-util-compact

Use

var u = require('unist-builder')
var compact = require('mdast-util-compact')

var tree = u('strong', [u('text', 'alpha'), u('text', ' '), u('text', 'bravo')])

compact(tree)

console.log(tree)

Yields:

{ type: 'strong',
  children: [ { type: 'text', value: 'alpha bravo' } ] }

API

compact(tree)

Walk the tree and collapse nodes. Combines adjacent texts and collapses blockquotes.

Handles positional information properly.

Returns

The given tree.

Security

Use of mdast-util-compact 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 © Titus Wormer