mdast-squeeze-paragraphs

mdast utility to remove empty paragraphs from a tree

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mdast-squeeze-paragraphs
606.0.09 months ago9 years agoMinified + gzip package size for mdast-squeeze-paragraphs in KB

Readme

mdast-squeeze-paragraphs
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
mdast utility to remove empty paragraphs.

Contents

*   [`squeezeParagraphs(tree)`](#squeezeparagraphstree)

What is this?

This package is a utility that removes empty paragraphs, left over from other operations, from the tree. Paragraphs are considered empty if they do not contain non-whitespace characters.

When should I use this?

Probably never! You should try to clean your trees yourself.
A plugin, remark-squeeze-paragraphsremark-squeeze-paragraphs, exists that does the same but for remark.

Install

This package is ESM onlyesm. In Node.js (version 16+), install with npm:
npm install mdast-squeeze-paragraphs

In Deno with esm.shesmsh:
import {squeezeParagraphs} from 'https://esm.sh/mdast-squeeze-paragraphs@6'

In browsers with esm.shesmsh:
<script type="module">
  import {squeezeParagraphs} from 'https://esm.sh/mdast-squeeze-paragraphs@6?bundle'
</script>

Use

import {squeezeParagraphs} from 'mdast-squeeze-paragraphs'
import {u} from 'unist-builder'

const 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

This package exports the identifier squeezeParagraphsapi-squeezeparagraphs. There is no default export.

squeezeParagraphs(tree)

Remove empty paragraphs in tree.
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-squeeze-paragraphs@^6, compatible with Node.js 16.

Security

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

Related

— remark plugin
— make a tree compact

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 © Eugene Sharygin