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
    Copy the full SHA
    294048b View commit details
  2. Add more badges

    wooorm committed Nov 11, 2018
    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
}
}
Loading