mdast-squeeze-paragraphs
!Buildbuild-badgebuild
!Coveragecoverage-badgecoverage
!Downloadsdownloads-badgedownloads
!Sizesize-badgesize
!Sponsorssponsors-badgecollective
!Backersbackers-badgecollective
!Chatchat-badgechatmdast 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-paragraphs
remark-squeeze-paragraphs, exists that
does the same but for remark.Install
This package is ESM onlyesm. In Node.js (version 14.14+ and 16.0+), install with npm:npm install mdast-util-squeeze-paragraphs
In Deno with
esm.sh
esmsh:import {squeezeParagraphs} from 'https://esm.sh/mdast-util-squeeze-paragraphs@5'
In browsers with
esm.sh
esmsh:<script type="module">
import {squeezeParagraphs} from 'https://esm.sh/mdast-util-squeeze-paragraphs@5?bundle'
</script>
Use
import {u} from 'unist-builder'
import {squeezeParagraphs} from 'mdast-squeeze-paragraphs'
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 identifiersqueezeParagraphs
api-squeezeparagraphs.
There is no default export.squeezeParagraphs(tree)
Remove empty paragraphs in tree
.Parameters
— tree to change
Returns
Changedtree
(Node
node), or null
if it was an empty paragraph.Types
This package is fully typed with TypeScript. It exports no additional types..Compatibility
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.Security
Use ofmdast-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
Seecontributing.md
contributing in syntax-tree/.github
health for
ways to get started.
See support.md
support 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.