mdast-util-compact

mdast utility to make a tree compact

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mdast-util-compact
605.0.010 months ago8 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
mdast utility to make trees compact by collapsing adjacent text nodes and blockquotes.

Contents

*   [`compact(tree)`](#compacttree)

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 onlyesm. In Node.js (version 16+), install with npm:
npm install mdast-util-compact

In Deno with esm.shesmsh:
import {compact} from 'https://esm.sh/mdast-util-compact@5'

In browsers with esm.shesmsh:
<script type="module">
  import {compact} from 'https://esm.sh/mdast-util-compact@5?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 compactapi-compact. There is no default export.

compact(tree)

Make an mdast tree compact by merging adjacent text nodes and block quotes.
Parameters
— tree to change
Returns
Nothing (undefined).

Types

This package is fully typed with TypeScript. It exports no additional types.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, mdast-util-compact@^5, compatible with Node.js 16.

Security

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

Related

— remove empty paragraphs

Contribute

See contributing.mdcontributing in syntax-tree/.githubhealth 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