unified

Project: syntax-tree/mdast-util-compact

Package: mdast-util-compact@4.1.0

  1. Dependents: 0
  2. mdast utility to make a tree compact
  1. util 136
  2. utility 132
  3. unist 128
  4. mdast 84
  5. mdast-util 31
  6. tree 31
  7. node 23

mdast-util-compact

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to make trees compact by collapsing adjacent text nodes and blockquotes.

Contents

What is this?

This package is a utility that lets you make a tree, after changes, more similar to how it would be parsed.

When should I use this?

Probably never! You should try and keep your trees clean yourself.

Install

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

npm install mdast-util-compact

In Deno with esm.sh:

import {compact} from 'https://esm.sh/mdast-util-compact@4'

In browsers with esm.sh:

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

Use

import {u} from 'unist-builder'
import {compact} from 'mdast-util-compact'

const 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

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

compact(tree)

Collapse nodes in tree (Node). Combines adjacent texts and collapses blockquotes. Handles positional information properly.

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-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