mdast-util-compact

mdast utility to make a tree compact

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mdast-util-compact
304.1.0a year ago6 years agoMinified + gzip package size for mdast-util-compact in KB

Readme

mdast-util-compact
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
mdastmdast utility to make trees compact: collapse adjacent text nodes and blockquotes.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
npm install mdast-util-compact
## Use

```js
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 following identifiers: compact. There is no default export.

compact(tree)

Walk the tree and collapse nodes. Combines adjacent texts and collapses blockquotes.
Handles positional informationposition-information properly.
Returns
The given tree.

Security

Use of mdast-util-compact does not involve hasthast or user content so there are no openings for cross-site scripting (XSS)xss attacks.

Related

— remove empty paragraphs

Contribute

See contributing.md in syntax-tree/.githubcontributing for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor