Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: syntax-tree/mdast-util-compact
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.2
Choose a base ref
...
head repository: syntax-tree/mdast-util-compact
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Nov 11, 2018

  1. Move URLs to HTTPS

    wooorm committed Nov 11, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    panh99 Heng Pan
    Copy the full SHA
    294048b View commit details
  2. Add more badges

    wooorm committed Nov 11, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ef03df1 View commit details
  3. Change MDAST > mdast

    wooorm committed Nov 11, 2018
    Copy the full SHA
    db16069 View commit details
  4. Refactor comments

    wooorm committed Nov 11, 2018
    Copy the full SHA
    7e8864f View commit details
  5. Update dev-dependencies

    wooorm committed Nov 11, 2018
    Copy the full SHA
    c754ee0 View commit details

Commits on May 24, 2019

  1. Fix tests on Windows

    wooorm committed May 24, 2019
    Copy the full SHA
    48405a9 View commit details
  2. Update Travis

    wooorm committed May 24, 2019
    Copy the full SHA
    5fe4d64 View commit details
  3. Update dev-dependencies

    wooorm committed May 24, 2019
    Copy the full SHA
    64f9098 View commit details
  4. Refactor prose

    wooorm committed May 24, 2019
    Copy the full SHA
    68a9a92 View commit details
  5. 1.0.3

    wooorm committed May 24, 2019
    Copy the full SHA
    446660a View commit details

Commits on Jul 18, 2019

  1. Add notes on security

    wooorm authored Jul 18, 2019
    Copy the full SHA
    6cda552 View commit details

Commits on Nov 10, 2019

  1. Update dev-dependencies

    wooorm committed Nov 10, 2019
    Copy the full SHA
    624ef42 View commit details
  2. Add funding to package.json

    wooorm committed Nov 10, 2019
    Copy the full SHA
    b023bd5 View commit details
  3. 1.0.4

    wooorm committed Nov 10, 2019
    Copy the full SHA
    fbe2efb View commit details
  4. Update unist-util-visit

    wooorm committed Nov 10, 2019
    Copy the full SHA
    c371128 View commit details
  5. 2.0.0

    wooorm committed Nov 10, 2019
    Copy the full SHA
    f48eca4 View commit details

Commits on Feb 22, 2020

  1. Update metadata

    wooorm committed Feb 22, 2020
    Copy the full SHA
    8780c9b View commit details
  2. Refactor prose

    wooorm committed Feb 22, 2020
    Copy the full SHA
    9fe54c3 View commit details
  3. Update dev-dependencies

    wooorm committed Feb 22, 2020
    Copy the full SHA
    fa50690 View commit details
  4. 2.0.1

    wooorm committed Feb 22, 2020
    Copy the full SHA
    0f79aa2 View commit details

Commits on Mar 1, 2020

  1. Add list of related projects

    wooorm committed Mar 1, 2020
    Copy the full SHA
    8c2078a View commit details

Commits on Jun 17, 2020

  1. Change master in links to HEAD

    wooorm committed Jun 17, 2020
    Copy the full SHA
    54da09b View commit details
  2. Update dev-dependencies

    wooorm committed Jun 17, 2020
    Copy the full SHA
    b173b45 View commit details

Commits on Aug 21, 2020

  1. Add Discussions

    wooorm authored Aug 21, 2020
    Copy the full SHA
    fda4f93 View commit details

Commits on Oct 3, 2020

  1. Change to match CommonMark, new remark

    * remark is now complies to CommonMark, this means that we can adhere
      too, and merge adjacent block quotes
    * remark no longer has separate text nodes for character references
      (`&`) and character escapes (`\&`), so we can now merge adjacent
      text nodes always
    wooorm committed Oct 3, 2020
    Copy the full SHA
    d8c151b View commit details
  2. 3.0.0

    wooorm committed Oct 3, 2020
    Copy the full SHA
    d040b26 View commit details

Commits on Nov 29, 2020

  1. Update dev-dependencies

    wooorm committed Nov 29, 2020
    Copy the full SHA
    e4844cf View commit details
  2. Use Actions

    wooorm committed Nov 29, 2020
    Copy the full SHA
    10a0f32 View commit details

Commits on Apr 23, 2021

  1. Add bb

    wooorm committed Apr 23, 2021
    Copy the full SHA
    ce5239e View commit details
  2. Update Node in Actions

    wooorm committed Apr 23, 2021
    Copy the full SHA
    52dc4d1 View commit details
  3. Update dev-dependencies

    wooorm committed Apr 23, 2021
    Copy the full SHA
    a7bbefd View commit details
  4. Use ESM

    wooorm committed Apr 23, 2021
    Copy the full SHA
    2d993f8 View commit details
  5. Add JSDoc based types

    wooorm committed Apr 23, 2021
    Copy the full SHA
    583deff View commit details
  6. 4.0.0

    wooorm committed Apr 23, 2021
    Copy the full SHA
    c13fdc9 View commit details

Commits on Jun 1, 2021

  1. Copy the full SHA
    4c29e5d View commit details

Commits on Jul 24, 2021

  1. Copy the full SHA
    2848862 View commit details
  2. Refactor code-style

    wooorm committed Jul 24, 2021
    Copy the full SHA
    49c419a View commit details
  3. Add strict to tsconfig.json

    wooorm committed Jul 24, 2021
    Copy the full SHA
    5911a1f View commit details
  4. Update xo

    wooorm committed Jul 24, 2021
    Copy the full SHA
    bc975bc View commit details

Commits on Jul 30, 2021

  1. Copy the full SHA
    4e6d7af View commit details
  2. 4.1.0

    wooorm committed Jul 30, 2021
    Copy the full SHA
    320cef9 View commit details

Commits on Mar 4, 2022

  1. Copy the full SHA
    7c66917 View commit details

Commits on May 21, 2022

  1. Update dev-dependencies

    wooorm committed May 21, 2022
    Copy the full SHA
    92a834a View commit details
  2. Add improved docs

    wooorm committed May 21, 2022
    Copy the full SHA
    4f54017 View commit details
  3. Fix types

    wooorm committed May 21, 2022
    Copy the full SHA
    cb14568 View commit details
  4. Add table of contents

    wooorm committed May 21, 2022
    Copy the full SHA
    21001db View commit details

Commits on Jan 25, 2023

  1. Update dev-dependencies

    wooorm committed Jan 25, 2023
    Copy the full SHA
    16dc681 View commit details
  2. Update Actions

    wooorm committed Jan 25, 2023
    Copy the full SHA
    9d1dee7 View commit details
  3. Update tsconfig.json

    wooorm committed Jan 25, 2023
    Copy the full SHA
    aac8d47 View commit details
  4. Copy the full SHA
    96288c0 View commit details
Showing with 373 additions and 237 deletions.
  1. +13 −0 .github/workflows/bb.yml
  2. +21 −0 .github/workflows/main.yml
  3. +1 −3 .gitignore
  4. +1 −0 .npmrc
  5. +1 −2 .prettierignore
  6. +0 −15 .travis.yml
  7. +1 −61 index.js
  8. +46 −0 lib/index.js
  9. +49 −39 package.json
  10. +147 −30 readme.md
  11. +78 −87 test.js
  12. +15 −0 tsconfig.json
13 changes: 13 additions & 0 deletions .github/workflows/bb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: bb
on:
issues:
types: [opened, reopened, edited, closed, labeled, unlabeled]
pull_request_target:
types: [opened, reopened, edited, closed, labeled, unlabeled]
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: unifiedjs/beep-boop-beta@main
with:
repo-token: ${{secrets.GITHUB_TOKEN}}
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: main
on:
- pull_request
- push
jobs:
main:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v3
strategy:
matrix:
node:
- lts/gallium
- node
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.DS_Store
*.d.ts
*.log
.nyc_output/
coverage/
node_modules/
mdast-util-compact.js
mdast-util-compact.min.js
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ignore-scripts=true
package-lock=false
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
coverage/
mdast-util-compact.js
mdast-util-compact.min.js
*.md
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

62 changes: 1 addition & 61 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,61 +1 @@
'use strict'

var visit = require('unist-util-visit')

module.exports = compact

/* Make an MDAST tree compact by merging adjacent text nodes. */
function compact(tree, commonmark) {
visit(tree, visitor)

return tree

function visitor(child, index, parent) {
var siblings = parent ? parent.children : []
var prev = index && siblings[index - 1]

if (
prev &&
child.type === prev.type &&
mergeable(prev, commonmark) &&
mergeable(child, commonmark)
) {
if (child.value) {
prev.value += child.value
}

if (child.children) {
prev.children = prev.children.concat(child.children)
}

siblings.splice(index, 1)

if (prev.position && child.position) {
prev.position.end = child.position.end
}

return index
}
}
}

function mergeable(node, commonmark) {
var start
var end

if (node.type === 'text') {
if (!node.position) {
return true
}

start = node.position.start
end = node.position.end

/* Only merge nodes which occupy the same size as their `value`. */
return (
start.line !== end.line || end.column - start.column === node.value.length
)
}

return commonmark && node.type === 'blockquote'
}
export {compact} from './lib/index.js'
46 changes: 46 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @typedef {import('mdast').Nodes} Nodes
*/

import {ok as assert} from 'devlop'
import {visit} from 'unist-util-visit'

/**
* Make an mdast tree compact by merging adjacent text nodes and block quotes.
*
* @param {Nodes} tree
* Tree to change.
* @returns {undefined}
* Nothing.
*/
export function compact(tree) {
visit(tree, function (child, index, parent) {
if (
parent &&
index &&
(child.type === 'text' || child.type === 'blockquote')
) {
const previous = parent.children[index - 1]

if (previous.type === child.type) {
if ('value' in child) {
assert('value' in previous, 'same type')
previous.value += child.value
}

if ('children' in child) {
assert('children' in previous, 'same type')
previous.children = previous.children.concat(child.children)
}

parent.children.splice(index, 1)

if (previous.position && child.position) {
previous.position.end = child.position.end
}

return index
}
}
})
}
88 changes: 49 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,80 @@
{
"name": "mdast-util-compact",
"version": "1.0.2",
"description": "Make an MDAST tree compact",
"version": "5.0.0",
"description": "mdast utility to make a tree compact",
"license": "MIT",
"keywords": [
"unist",
"mdast",
"mdast-util",
"util",
"utility",
"tree",
"compact",
"node"
],
"repository": "syntax-tree/mdast-util-compact",
"bugs": "https://github.com/syntax-tree/mdast-util-compact/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"unist-util-visit": "^1.1.0"
"@types/mdast": "^4.0.0",
"devlop": "^1.0.0",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"nyc": "^12.0.0",
"prettier": "^1.14.2",
"remark-cli": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.0.0",
"tinyify": "^2.4.3",
"unist-builder": "^1.0.2",
"xo": "^0.22.0"
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unist-builder": "^4.0.0",
"xo": "^0.54.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"build-bundle": "browserify . -s mdastUtilCompact > mdast-util-compact.js",
"build-mangle": "browserify . -s mdastUtilCompact -p tinyify > mdast-util-compact.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run build && npm run test-coverage"
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"mdast-util-compact.js"
]
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true
}
}
177 changes: 147 additions & 30 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,71 @@
# mdast-util-compact [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
# mdast-util-compact

Make an [MDAST][] tree compact: collapse text nodes (when possible),
and blockquotes (in commonmark mode).
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

## Installation
[mdast][] utility to make trees compact by collapsing adjacent text nodes and
blockquotes.

[npm][]:
## Contents

```bash
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`compact(tree)`](#compacttree)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)

## 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 only][esm].
In Node.js (version 16+), install with [npm][]:

```sh
npm install mdast-util-compact
```

## Usage
In Deno with [`esm.sh`][esmsh]:

```js
import {compact} from 'https://esm.sh/mdast-util-compact@5'
```

In browsers with [`esm.sh`][esmsh]:

```javascript
var u = require('unist-builder')
var compact = require('mdast-util-compact')
```html
<script type="module">
import {compact} from 'https://esm.sh/mdast-util-compact@5?bundle'
</script>
```

## Use

```js
import {u} from 'unist-builder'
import {compact} from 'mdast-util-compact'

var tree = u('strong', [u('text', 'alpha'), u('text', ' '), u('text', 'bravo')])
const tree = u('strong', [u('text', 'alpha'), u('text', ' '), u('text', 'bravo')])

compact(tree)

@@ -27,54 +75,123 @@ console.log(tree)
Yields:

```js
{ type: 'strong',
children: [ { type: 'text', value: 'alpha bravo' } ] }
{
type: 'strong',
children: [ { type: 'text', value: 'alpha bravo' } ]
}
```

## API

### `compact(tree[, commonmark])`
This package exports the identifier [`compact`][api-compact].
There is no default export.

### `compact(tree)`

Make an mdast tree compact by merging adjacent text nodes and block quotes.

Visit the tree and collapse nodes. Combines adjacent text nodes (but
not when they represent entities or escapes). If `commonmark` is `true`,
collapses `blockquote` nodes.
###### Parameters

Handles positional information properly.
* `tree` ([`Node`][node])
— tree to change

###### Returns

The given `tree`.
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

* [`mdast-squeeze-paragraphs`](https://github.com/syntax-tree/mdast-squeeze-paragraphs)
— remove empty paragraphs

## Contribute

See [`contributing.md` in `syntax-tree/mdast`][contributing] for ways to get
started.
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.

This organisation has a [Code of Conduct][coc]. By interacting with this
repository, organisation, or community you agree to abide by its terms.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.

## License

[MIT][license] © [Titus Wormer][author]

<!-- Definitions -->

[travis-badge]: https://img.shields.io/travis/syntax-tree/mdast-util-compact.svg
[build-badge]: https://github.com/syntax-tree/mdast-util-compact/workflows/main/badge.svg

[build]: https://github.com/syntax-tree/mdast-util-compact/actions

[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-compact.svg

[coverage]: https://codecov.io/github/syntax-tree/mdast-util-compact

[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-compact.svg

[downloads]: https://www.npmjs.com/package/mdast-util-compact

[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-compact

[size]: https://bundlejs.com/?q=mdast-util-compact

[travis]: https://travis-ci.org/syntax-tree/mdast-util-compact
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-compact.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg

[codecov]: https://codecov.io/github/syntax-tree/mdast-util-compact
[collective]: https://opencollective.com/unified

[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg

[chat]: https://github.com/syntax-tree/unist/discussions

[npm]: https://docs.npmjs.com/cli/install

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[esmsh]: https://esm.sh

[typescript]: https://www.typescriptlang.org

[license]: license

[author]: http://wooorm.com
[author]: https://wooorm.com

[health]: https://github.com/syntax-tree/.github

[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md

[support]: https://github.com/syntax-tree/.github/blob/main/support.md

[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md

[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

[mdast]: https://github.com/syntax-tree/mdast

[contributing]: https://github.com/syntax-tree/mdast/blob/master/contributing.md
[node]: https://github.com/syntax-tree/mdast#node

[hast]: https://github.com/syntax-tree/hast

[coc]: https://github.com/syntax-tree/mdast/blob/master/code-of-conduct.md
[api-compact]: #compacttree
165 changes: 78 additions & 87 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,114 +1,105 @@
'use strict'
import assert from 'node:assert/strict'
import test from 'node:test'
import {compact} from 'mdast-util-compact'
import {u} from 'unist-builder'

var test = require('tape')
var u = require('unist-builder')
var compact = require('.')
test('compact', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('mdast-util-compact')).sort(), [
'compact'
])
})

test('compact()', function(t) {
t.same(
compact(
u('paragraph', [u('text', 'alpha'), u('text', ' '), u('text', 'bravo')])
),
u('paragraph', [u('text', 'alpha bravo')]),
'should compact texts'
)
await t.test('should compact texts', async function () {
const tree = u('paragraph', [
u('text', 'alpha'),
u('text', ' '),
u('text', 'bravo')
])

t.same(
compact(
u('paragraph', [
u(
'text',
{
position: {start: {line: 1, column: 1}, end: {line: 1, column: 6}}
},
'alpha'
),
u(
'text',
{
position: {start: {line: 1, column: 6}, end: {line: 1, column: 7}}
},
' '
),
u(
'text',
{
position: {start: {line: 1, column: 7}, end: {line: 1, column: 12}}
},
'bravo'
)
])
),
u('paragraph', [
compact(tree)

assert.deepEqual(tree, u('paragraph', [u('text', 'alpha bravo')]))
})

await t.test('should merge positions', async function () {
const tree = u('paragraph', [
u(
'text',
{position: {start: {line: 1, column: 1}, end: {line: 1, column: 6}}},
'alpha'
),
u(
'text',
{position: {start: {line: 1, column: 6}, end: {line: 1, column: 7}}},
' '
),
u(
'text',
{
position: {start: {line: 1, column: 1}, end: {line: 1, column: 12}}
position: {
start: {line: 1, column: 7},
end: {line: 1, column: 12}
}
},
'alpha bravo'
'bravo'
)
]),
'should merge positions'
)
])

compact(tree)

t.same(
compact(
assert.deepEqual(
tree,
u('paragraph', [
u(
'text',
{position: {start: {line: 1, column: 1}, end: {line: 1, column: 12}}},
'alpha bravo'
)
])
)
})

await t.test(
'should compact texts with incompatible positions',
async function () {
const tree = u('paragraph', [
u('text', 'at'),
u(
'text',
{
position: {start: {line: 1, column: 3}, end: {line: 1, column: 8}}
position: {
start: {line: 1, column: 3},
end: {line: 1, column: 8}
}
},
'&'
),
u('text', 't')
])
),
u('paragraph', [
u('text', 'at'),
u(
'text',
{
position: {start: {line: 1, column: 3}, end: {line: 1, column: 8}}
},
'&'
),
u('text', 't')
]),
'should not compact texts with incompatible positions'

compact(tree)

assert.deepEqual(tree, u('paragraph', [u('text', 'at&t')]))
}
)

t.same(
compact(
u('root', [
u('blockquote', [u('paragraph', [u('text', 'Alpha.')])]),
u('blockquote', [u('paragraph', [u('text', 'Bravo.')])])
])
),
u('root', [
await t.test('should compact blockquotes', async function () {
const tree = u('root', [
u('blockquote', [u('paragraph', [u('text', 'Alpha.')])]),
u('blockquote', [u('paragraph', [u('text', 'Bravo.')])])
]),
'should not compact blockquotes'
)
])

compact(tree)

t.same(
compact(
assert.deepEqual(
tree,
u('root', [
u('blockquote', [u('paragraph', [u('text', 'Alpha.')])]),
u('blockquote', [u('paragraph', [u('text', 'Bravo.')])])
]),
true
),
u('root', [
u('blockquote', [
u('paragraph', [u('text', 'Alpha.')]),
u('paragraph', [u('text', 'Bravo.')])
u('blockquote', [
u('paragraph', [u('text', 'Alpha.')]),
u('paragraph', [u('text', 'Bravo.')])
])
])
]),
'should compact blockquotes in commonmark mode'
)

t.end()
)
})
})
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"checkJs": true,
"customConditions": ["development"],
"declaration": true,
"emitDeclarationOnly": true,
"exactOptionalPropertyTypes": true,
"lib": ["es2022"],
"module": "node16",
"strict": true,
"target": "es2022"
},
"exclude": ["coverage/", "node_modules/"],
"include": ["**/*.js"]
}