3 [![Build][build-badge]][build]
4 [![Coverage][coverage-badge]][coverage]
5 [![Downloads][downloads-badge]][downloads]
6 [![Size][size-badge]][size]
7 [![Sponsors][sponsors-badge]][collective]
8 [![Backers][backers-badge]][collective]
9 [![Chat][chat-badge]][chat]
11 [**mdast**][mdast] utility to make trees compact: collapse text nodes (when
12 possible) and blockquotes (in commonmark mode).
19 npm install mdast-util-compact
25 var u = require('unist-builder')
26 var compact = require('mdast-util-compact')
28 var tree = u('strong', [u('text', 'alpha'), u('text', ' '), u('text', 'bravo')])
39 children: [ { type: 'text', value: 'alpha bravo' } ] }
44 ### `compact(tree[, commonmark])`
46 Walk the [tree][] and collapse nodes.
47 Combines adjacent [text][]s (but not when they represent entities or escapes).
48 If `commonmark` is `true`, collapses [blockquote][]s.
50 Handles [positional information][position-information] properly.
58 Use of `mdast-util-compact` does not involve [**hast**][hast] or user content
59 so there are no openings for [cross-site scripting (XSS)][xss] attacks.
63 See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
65 See [`support.md`][support] for ways to get help.
67 This project has a [Code of Conduct][coc].
68 By interacting with this repository, organisation, or community you agree to
73 [MIT][license] © [Titus Wormer][author]
77 [build-badge]: https://img.shields.io/travis/syntax-tree/mdast-util-compact.svg
79 [build]: https://travis-ci.org/syntax-tree/mdast-util-compact
81 [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-compact.svg
83 [coverage]: https://codecov.io/github/syntax-tree/mdast-util-compact
85 [downloads-badge]: https://img.shields.io/npm/dm/mdast-util-compact.svg
87 [downloads]: https://www.npmjs.com/package/mdast-util-compact
89 [size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-compact.svg
91 [size]: https://bundlephobia.com/result?p=mdast-util-compact
93 [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
95 [backers-badge]: https://opencollective.com/unified/backers/badge.svg
97 [collective]: https://opencollective.com/unified
99 [chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
101 [chat]: https://spectrum.chat/unified/syntax-tree
103 [npm]: https://docs.npmjs.com/cli/install
107 [author]: https://wooorm.com
109 [contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
111 [support]: https://github.com/syntax-tree/.github/blob/master/support.md
113 [coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
115 [mdast]: https://github.com/syntax-tree/mdast
117 [tree]: https://github.com/syntax-tree/unist#tree
119 [position-information]: https://github.com/syntax-tree/unist#positional-information
121 [text]: https://github.com/syntax-tree/mdast#text
123 [blockquote]: https://github.com/syntax-tree/mdast#blockquote
125 [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
127 [hast]: https://github.com/syntax-tree/hast