This commit is contained in:
180
node_modules/mdast-util-find-and-replace/index.js
generated
vendored
Normal file
180
node_modules/mdast-util-find-and-replace/index.js
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = findAndReplace
|
||||
|
||||
var visit = require('unist-util-visit-parents')
|
||||
var convert = require('unist-util-is/convert')
|
||||
var escape = require('escape-string-regexp')
|
||||
|
||||
var splice = [].splice
|
||||
|
||||
function findAndReplace(tree, find, replace, options) {
|
||||
var settings
|
||||
var schema
|
||||
|
||||
if (typeof find === 'string' || (find && typeof find.exec === 'function')) {
|
||||
schema = [[find, replace]]
|
||||
} else {
|
||||
schema = find
|
||||
options = replace
|
||||
}
|
||||
|
||||
settings = options || {}
|
||||
|
||||
search(tree, settings, handlerFactory(toPairs(schema)))
|
||||
|
||||
return tree
|
||||
|
||||
function handlerFactory(pairs) {
|
||||
var pair = pairs[0]
|
||||
|
||||
return handler
|
||||
|
||||
function handler(node, parent) {
|
||||
var find = pair[0]
|
||||
var replace = pair[1]
|
||||
var nodes = []
|
||||
var start = 0
|
||||
var index = parent.children.indexOf(node)
|
||||
var position
|
||||
var match
|
||||
var subhandler
|
||||
var value
|
||||
|
||||
find.lastIndex = 0
|
||||
|
||||
match = find.exec(node.value)
|
||||
|
||||
while (match) {
|
||||
position = match.index
|
||||
value = replace.apply(
|
||||
null,
|
||||
[].concat(match, {index: match.index, input: match.input})
|
||||
)
|
||||
|
||||
if (value !== false) {
|
||||
if (start !== position) {
|
||||
nodes.push({type: 'text', value: node.value.slice(start, position)})
|
||||
}
|
||||
|
||||
if (typeof value === 'string' && value.length > 0) {
|
||||
value = {type: 'text', value: value}
|
||||
}
|
||||
|
||||
if (value) {
|
||||
nodes = [].concat(nodes, value)
|
||||
}
|
||||
|
||||
start = position + match[0].length
|
||||
}
|
||||
|
||||
if (!find.global) {
|
||||
break
|
||||
}
|
||||
|
||||
match = find.exec(node.value)
|
||||
}
|
||||
|
||||
if (position === undefined) {
|
||||
nodes = [node]
|
||||
index--
|
||||
} else {
|
||||
if (start < node.value.length) {
|
||||
nodes.push({type: 'text', value: node.value.slice(start)})
|
||||
}
|
||||
|
||||
nodes.unshift(index, 1)
|
||||
splice.apply(parent.children, nodes)
|
||||
}
|
||||
|
||||
if (pairs.length > 1) {
|
||||
subhandler = handlerFactory(pairs.slice(1))
|
||||
position = -1
|
||||
|
||||
while (++position < nodes.length) {
|
||||
node = nodes[position]
|
||||
|
||||
if (node.type === 'text') {
|
||||
subhandler(node, parent)
|
||||
} else {
|
||||
search(node, settings, subhandler)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return index + nodes.length + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function search(tree, settings, handler) {
|
||||
var ignored = convert(settings.ignore || [])
|
||||
var result = []
|
||||
|
||||
visit(tree, 'text', visitor)
|
||||
|
||||
return result
|
||||
|
||||
function visitor(node, parents) {
|
||||
var index = -1
|
||||
var parent
|
||||
var grandparent
|
||||
|
||||
while (++index < parents.length) {
|
||||
parent = parents[index]
|
||||
|
||||
if (
|
||||
ignored(
|
||||
parent,
|
||||
grandparent ? grandparent.children.indexOf(parent) : undefined,
|
||||
grandparent
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
grandparent = parent
|
||||
}
|
||||
|
||||
return handler(node, grandparent)
|
||||
}
|
||||
}
|
||||
|
||||
function toPairs(schema) {
|
||||
var result = []
|
||||
var key
|
||||
var index
|
||||
|
||||
if (typeof schema !== 'object') {
|
||||
throw new Error('Expected array or object as schema')
|
||||
}
|
||||
|
||||
if ('length' in schema) {
|
||||
index = -1
|
||||
|
||||
while (++index < schema.length) {
|
||||
result.push([
|
||||
toExpression(schema[index][0]),
|
||||
toFunction(schema[index][1])
|
||||
])
|
||||
}
|
||||
} else {
|
||||
for (key in schema) {
|
||||
result.push([toExpression(key), toFunction(schema[key])])
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function toExpression(find) {
|
||||
return typeof find === 'string' ? new RegExp(escape(find), 'g') : find
|
||||
}
|
||||
|
||||
function toFunction(replace) {
|
||||
return typeof replace === 'function' ? replace : returner
|
||||
|
||||
function returner() {
|
||||
return replace
|
||||
}
|
||||
}
|
||||
22
node_modules/mdast-util-find-and-replace/license
generated
vendored
Normal file
22
node_modules/mdast-util-find-and-replace/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
4
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/color.browser.js
generated
vendored
Normal file
4
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/color.browser.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = identity
|
||||
function identity(d) {
|
||||
return d
|
||||
}
|
||||
4
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/color.js
generated
vendored
Normal file
4
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/color.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = color
|
||||
function color(d) {
|
||||
return '\u001B[33m' + d + '\u001B[39m'
|
||||
}
|
||||
93
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/index.js
generated
vendored
Normal file
93
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/index.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = visitParents
|
||||
|
||||
var convert = require('unist-util-is/convert')
|
||||
var color = require('./color')
|
||||
|
||||
var CONTINUE = true
|
||||
var SKIP = 'skip'
|
||||
var EXIT = false
|
||||
|
||||
visitParents.CONTINUE = CONTINUE
|
||||
visitParents.SKIP = SKIP
|
||||
visitParents.EXIT = EXIT
|
||||
|
||||
function visitParents(tree, test, visitor, reverse) {
|
||||
var step
|
||||
var is
|
||||
|
||||
if (typeof test === 'function' && typeof visitor !== 'function') {
|
||||
reverse = visitor
|
||||
visitor = test
|
||||
test = null
|
||||
}
|
||||
|
||||
is = convert(test)
|
||||
step = reverse ? -1 : 1
|
||||
|
||||
factory(tree, null, [])()
|
||||
|
||||
function factory(node, index, parents) {
|
||||
var value = typeof node === 'object' && node !== null ? node : {}
|
||||
var name
|
||||
|
||||
if (typeof value.type === 'string') {
|
||||
name =
|
||||
typeof value.tagName === 'string'
|
||||
? value.tagName
|
||||
: typeof value.name === 'string'
|
||||
? value.name
|
||||
: undefined
|
||||
|
||||
visit.displayName =
|
||||
'node (' + color(value.type + (name ? '<' + name + '>' : '')) + ')'
|
||||
}
|
||||
|
||||
return visit
|
||||
|
||||
function visit() {
|
||||
var grandparents = parents.concat(node)
|
||||
var result = []
|
||||
var subresult
|
||||
var offset
|
||||
|
||||
if (!test || is(node, index, parents[parents.length - 1] || null)) {
|
||||
result = toResult(visitor(node, parents))
|
||||
|
||||
if (result[0] === EXIT) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
if (node.children && result[0] !== SKIP) {
|
||||
offset = (reverse ? node.children.length : -1) + step
|
||||
|
||||
while (offset > -1 && offset < node.children.length) {
|
||||
subresult = factory(node.children[offset], offset, grandparents)()
|
||||
|
||||
if (subresult[0] === EXIT) {
|
||||
return subresult
|
||||
}
|
||||
|
||||
offset =
|
||||
typeof subresult[1] === 'number' ? subresult[1] : offset + step
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toResult(value) {
|
||||
if (value !== null && typeof value === 'object' && 'length' in value) {
|
||||
return value
|
||||
}
|
||||
|
||||
if (typeof value === 'number') {
|
||||
return [CONTINUE, value]
|
||||
}
|
||||
|
||||
return [value]
|
||||
}
|
||||
22
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/license
generated
vendored
Normal file
22
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
104
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/package.json
generated
vendored
Normal file
104
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/package.json
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
{
|
||||
"name": "unist-util-visit-parents",
|
||||
"version": "3.1.1",
|
||||
"description": "unist utility to recursively walk over nodes, with ancestral information",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"unist-util",
|
||||
"util",
|
||||
"utility",
|
||||
"tree",
|
||||
"ast",
|
||||
"visit",
|
||||
"traverse",
|
||||
"walk",
|
||||
"check",
|
||||
"parent",
|
||||
"parents"
|
||||
],
|
||||
"repository": "syntax-tree/unist-util-visit-parents",
|
||||
"bugs": "https://github.com/syntax-tree/unist-util-visit-parents/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"browser": {
|
||||
"./color.js": "./color.browser.js"
|
||||
},
|
||||
"react-native": {
|
||||
"./color.js": "./color.browser.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"color.js",
|
||||
"color.browser.js",
|
||||
"types/index.d.ts"
|
||||
],
|
||||
"types": "types/index.d.ts",
|
||||
"dependencies": {
|
||||
"@types/unist": "^2.0.0",
|
||||
"unist-util-is": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^17.0.0",
|
||||
"dtslint": "^4.0.0",
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark": "^13.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-gfm": "^1.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"strip-ansi": "^6.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"tinyify": "^3.0.0",
|
||||
"typescript": "^4.0.0",
|
||||
"unified": "^9.0.0",
|
||||
"xo": "^0.34.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier . --write && xo --fix",
|
||||
"build-bundle": "browserify index.js -s unistUtilVisitParents > unist-util-visit-parents.js",
|
||||
"build-mangle": "browserify index.js -s unistUtilVisitParents -p tinyify > unist-util-visit-parents.min.js",
|
||||
"build": "npm run build-bundle && npm run build-mangle",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test.js",
|
||||
"test-types": "dtslint types",
|
||||
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"rules": {
|
||||
"unicorn/prefer-set-has": "off",
|
||||
"unicorn/prefer-reflect-apply": "off"
|
||||
},
|
||||
"ignores": [
|
||||
"types/",
|
||||
"unist-util-visit-parents.js"
|
||||
]
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
233
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/readme.md
generated
vendored
Normal file
233
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/readme.md
generated
vendored
Normal file
@@ -0,0 +1,233 @@
|
||||
# unist-util-visit-parents
|
||||
|
||||
[![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]
|
||||
|
||||
[**unist**][unist] utility to visit nodes, with ancestral information.
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install unist-util-visit-parents
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
var remark = require('remark')
|
||||
var visit = require('unist-util-visit-parents')
|
||||
|
||||
var tree = remark.parse('Some _emphasis_, **importance**, and `code`.')
|
||||
|
||||
visit(tree, 'strong', visitor)
|
||||
|
||||
function visitor(node, ancestors) {
|
||||
console.log(ancestors)
|
||||
}
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```js
|
||||
[ { type: 'root', children: [ [Object] ] },
|
||||
{ type: 'paragraph',
|
||||
children:
|
||||
[ [Object],
|
||||
[Object],
|
||||
[Object],
|
||||
[Object],
|
||||
[Object],
|
||||
[Object],
|
||||
[Object] ] } ]
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `visit(tree[, test], visitor[, reverse])`
|
||||
|
||||
Visit nodes ([*inclusive descendants*][descendant] of [`tree`][tree]), with
|
||||
ancestral information.
|
||||
Optionally filtering nodes.
|
||||
Optionally in reverse.
|
||||
|
||||
This algorithm performs [*depth-first*][depth-first]
|
||||
[*tree traversal*][tree-traversal] in [*preorder*][preorder] (**NLR**), or
|
||||
if `reverse` is given, in *reverse preorder* (**NRL**).
|
||||
|
||||
Walking the tree is an intensive task.
|
||||
Make use of the return values of the visitor when possible.
|
||||
Instead of walking a tree multiple times with different `test`s, walk it once
|
||||
without a test, and use [`unist-util-is`][is] to check if a node matches a test,
|
||||
and then perform different operations.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `tree` ([`Node`][node]) — [Tree][] to traverse
|
||||
* `test` ([`Test`][is], optional) — [`is`][is]-compatible test (such as a
|
||||
[type][])
|
||||
* `visitor` ([Function][visitor]) — Function invoked when a node is found
|
||||
that passes `test`
|
||||
* `reverse` (`boolean`, default: `false`) — The tree is traversed in
|
||||
[preorder][] (NLR), visiting the node itself, then its [head][], etc.
|
||||
When `reverse` is passed, the tree is traversed in reverse preorder (NRL):
|
||||
the node itself is visited, then its [tail][], etc.
|
||||
|
||||
#### `next? = visitor(node, ancestors)`
|
||||
|
||||
Invoked when a node (matching `test`, if given) is found.
|
||||
|
||||
Visitors are free to transform `node`.
|
||||
They can also transform the [parent][] of node (the last of `ancestors`).
|
||||
Replacing `node` itself, if `visit.SKIP` is not returned, still causes its
|
||||
[descendant][]s to be visited.
|
||||
If adding or removing previous [sibling][]s (or next siblings, in case of
|
||||
`reverse`) of `node`, `visitor` should return a new [`index`][index] (`number`)
|
||||
to specify the sibling to traverse after `node` is traversed.
|
||||
Adding or removing next siblings of `node` (or previous siblings, in case of
|
||||
reverse) is handled as expected without needing to return a new `index`.
|
||||
Removing the `children` property of an ancestor still results in them being
|
||||
traversed.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` ([`Node`][node]) — Found node
|
||||
* `ancestors` (`Array.<Node>`) — [Ancestor][]s of `node`
|
||||
|
||||
##### Returns
|
||||
|
||||
The return value can have the following forms:
|
||||
|
||||
* [`index`][index] (`number`) — Treated as a tuple of `[CONTINUE, index]`
|
||||
* `action` (`*`) — Treated as a tuple of `[action]`
|
||||
* `tuple` (`Array.<*>`) — List with one or two values, the first an `action`,
|
||||
the second and `index`.
|
||||
Note that passing a tuple only makes sense if the `action` is `SKIP`.
|
||||
If the `action` is `EXIT`, that action can be returned.
|
||||
If the `action` is `CONTINUE`, `index` can be returned.
|
||||
|
||||
###### `action`
|
||||
|
||||
An action can have the following values:
|
||||
|
||||
* `visit.EXIT` (`false`) — Stop traversing immediately
|
||||
* `visit.CONTINUE` (`true`) — Continue traversing as normal (same behaviour
|
||||
as not returning anything)
|
||||
* `visit.SKIP` (`'skip'`) — Do not traverse this node’s children; continue
|
||||
with the specified index
|
||||
|
||||
###### `index`
|
||||
|
||||
[`index`][index] (`number`) — Move to the sibling at `index` next (after `node`
|
||||
itself is completely traversed).
|
||||
Useful if mutating the tree, such as removing the node the visitor is currently
|
||||
on, or any of its previous siblings (or next siblings, in case of `reverse`)
|
||||
Results less than `0` or greater than or equal to `children.length` stop
|
||||
traversing the parent
|
||||
|
||||
## Related
|
||||
|
||||
* [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)
|
||||
— Like `visit-parents`, but with one parent
|
||||
* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)
|
||||
— Create a new tree with all nodes that pass a test
|
||||
* [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)
|
||||
— Create a new tree with all nodes mapped by a given function
|
||||
* [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)
|
||||
— Create a new tree by mapping (to an array) with the given function
|
||||
* [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)
|
||||
— Remove nodes from a tree that pass a test
|
||||
* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
|
||||
— Select nodes with CSS-like selectors
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
|
||||
started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
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]
|
||||
|
||||
<!-- Definition -->
|
||||
|
||||
[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-visit-parents.svg
|
||||
|
||||
[build]: https://travis-ci.org/syntax-tree/unist-util-visit-parents
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-visit-parents.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/unist-util-visit-parents
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-visit-parents.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/unist-util-visit-parents
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-visit-parents.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=unist-util-visit-parents
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[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
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[unist]: https://github.com/syntax-tree/unist
|
||||
|
||||
[node]: https://github.com/syntax-tree/unist#node
|
||||
|
||||
[visitor]: #next--visitornode-ancestors
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[is]: https://github.com/syntax-tree/unist-util-is
|
||||
|
||||
[depth-first]: https://github.com/syntax-tree/unist#depth-first-traversal
|
||||
|
||||
[tree-traversal]: https://github.com/syntax-tree/unist#tree-traversal
|
||||
|
||||
[preorder]: https://github.com/syntax-tree/unist#preorder
|
||||
|
||||
[descendant]: https://github.com/syntax-tree/unist#descendant
|
||||
|
||||
[head]: https://github.com/syntax-tree/unist#head
|
||||
|
||||
[tail]: https://github.com/syntax-tree/unist#tail
|
||||
|
||||
[parent]: https://github.com/syntax-tree/unist#parent-1
|
||||
|
||||
[sibling]: https://github.com/syntax-tree/unist#sibling
|
||||
|
||||
[index]: https://github.com/syntax-tree/unist#index
|
||||
|
||||
[ancestor]: https://github.com/syntax-tree/unist#ancestor
|
||||
|
||||
[tree]: https://github.com/syntax-tree/unist#tree
|
||||
|
||||
[type]: https://github.com/syntax-tree/unist#type
|
||||
111
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/types/index.d.ts
generated
vendored
Normal file
111
node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
// TypeScript Version: 3.5
|
||||
|
||||
import {Node, Parent} from 'unist'
|
||||
import {Test} from 'unist-util-is'
|
||||
|
||||
declare namespace visitParents {
|
||||
/**
|
||||
* Continue traversing as normal
|
||||
*/
|
||||
type Continue = true
|
||||
|
||||
/**
|
||||
* Do not traverse this node’s children
|
||||
*/
|
||||
type Skip = 'skip'
|
||||
|
||||
/**
|
||||
* Stop traversing immediately
|
||||
*/
|
||||
type Exit = false
|
||||
|
||||
/**
|
||||
* Union of the action types
|
||||
*/
|
||||
type Action = Continue | Skip | Exit
|
||||
|
||||
/**
|
||||
* List with one or two values, the first an action, the second an index.
|
||||
*/
|
||||
type ActionTuple = [Action, Index]
|
||||
|
||||
/**
|
||||
* Move to the sibling at index next (after node itself is completely traversed).
|
||||
* Useful if mutating the tree, such as removing the node the visitor is currently on,
|
||||
* or any of its previous siblings (or next siblings, in case of reverse)
|
||||
* Results less than 0 or greater than or equal to children.length stop traversing the parent
|
||||
*/
|
||||
type Index = number
|
||||
|
||||
/**
|
||||
* Invoked when a node (matching test, if given) is found.
|
||||
* Visitors are free to transform node.
|
||||
* They can also transform the parent of node (the last of ancestors).
|
||||
* Replacing node itself, if visit.SKIP is not returned, still causes its descendants to be visited.
|
||||
* If adding or removing previous siblings (or next siblings, in case of reverse) of node,
|
||||
* visitor should return a new index (number) to specify the sibling to traverse after node is traversed.
|
||||
* Adding or removing next siblings of node (or previous siblings, in case of reverse)
|
||||
* is handled as expected without needing to return a new index.
|
||||
* Removing the children property of an ancestor still results in them being traversed.
|
||||
*
|
||||
* @param node Found node
|
||||
* @param ancestors Ancestors of node
|
||||
* @paramType V node type found
|
||||
* @returns
|
||||
* When Action is passed, treated as a tuple of [Action]
|
||||
* When Index is passed, treated as a tuple of [CONTINUE, Index]
|
||||
* When ActionTuple is passed,
|
||||
* Note that passing a tuple only makes sense if the action is SKIP.
|
||||
* If the action is EXIT, that action can be returned.
|
||||
* If the action is CONTINUE, index can be returned.
|
||||
*/
|
||||
type Visitor<V extends Node> = (
|
||||
node: V,
|
||||
ancestors: Node[]
|
||||
) => void | Action | Index | ActionTuple
|
||||
}
|
||||
|
||||
declare const visitParents: {
|
||||
/**
|
||||
* Visit children of tree which pass a test
|
||||
*
|
||||
* @param tree abstract syntax tree to visit
|
||||
* @param test test node
|
||||
* @param visitor function to run for each node
|
||||
* @param reverse visit the tree in reverse, defaults to false
|
||||
* @typeParam T tree node
|
||||
* @typeParam V node type found
|
||||
*/
|
||||
<V extends Node>(
|
||||
tree: Node,
|
||||
test: Test<V> | Array<Test<any>>,
|
||||
visitor: visitParents.Visitor<V>,
|
||||
reverse?: boolean
|
||||
): void
|
||||
|
||||
/**
|
||||
* Visit children of a tree
|
||||
*
|
||||
* @param tree abstract syntax tree to visit
|
||||
* @param visitor function to run for each node
|
||||
* @param reverse visit the tree in reverse, defaults to false
|
||||
*/
|
||||
(tree: Node, visitor: visitParents.Visitor<Node>, reverse?: boolean): void
|
||||
|
||||
/**
|
||||
* Continue traversing as normal
|
||||
*/
|
||||
CONTINUE: visitParents.Continue
|
||||
|
||||
/**
|
||||
* Do not traverse this node’s children
|
||||
*/
|
||||
SKIP: visitParents.Skip
|
||||
|
||||
/**
|
||||
* Stop traversing immediately
|
||||
*/
|
||||
EXIT: visitParents.Exit
|
||||
}
|
||||
|
||||
export = visitParents
|
||||
76
node_modules/mdast-util-find-and-replace/package.json
generated
vendored
Normal file
76
node_modules/mdast-util-find-and-replace/package.json
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"name": "mdast-util-find-and-replace",
|
||||
"version": "1.1.1",
|
||||
"description": "mdast utility to find and replace text in a tree",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"mdast",
|
||||
"mdast-util",
|
||||
"util",
|
||||
"utility",
|
||||
"markdown",
|
||||
"find",
|
||||
"replace"
|
||||
],
|
||||
"repository": "syntax-tree/mdast-util-find-and-replace",
|
||||
"bugs": "https://github.com/syntax-tree/mdast-util-find-and-replace/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"unist-util-is": "^4.0.0",
|
||||
"unist-util-visit-parents": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"unist-builder": "^2.0.0",
|
||||
"xo": "^0.37.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test.js",
|
||||
"test": "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,
|
||||
"rules": {
|
||||
"unicorn/prefer-type-error": "off",
|
||||
"guard-for-in": "off"
|
||||
}
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
187
node_modules/mdast-util-find-and-replace/readme.md
generated
vendored
Normal file
187
node_modules/mdast-util-find-and-replace/readme.md
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
# mdast-util-find-and-replace
|
||||
|
||||
[![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]
|
||||
|
||||
[**mdast**][mdast] utility to find and replace text in a [*tree*][tree].
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install mdast-util-find-and-replace
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
var u = require('unist-builder')
|
||||
var inspect = require('unist-util-inspect')
|
||||
var findAndReplace = require('mdast-util-find-and-replace')
|
||||
|
||||
var tree = u('paragraph', [
|
||||
u('text', 'Some '),
|
||||
u('emphasis', [u('text', 'emphasis')]),
|
||||
u('text', ' and '),
|
||||
u('strong', [u('text', 'importance')]),
|
||||
u('text', '.')
|
||||
])
|
||||
|
||||
findAndReplace(tree, 'and', 'or')
|
||||
|
||||
findAndReplace(tree, {emphasis: 'em', importance: 'strong'})
|
||||
|
||||
findAndReplace(tree, {
|
||||
Some: function ($0) {
|
||||
return u('link', {url: '//example.com#' + $0}, [u('text', $0)])
|
||||
}
|
||||
})
|
||||
|
||||
console.log(inspect(tree))
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
paragraph[8]
|
||||
├─ link[1] [url="//example.com#Some"]
|
||||
│ └─ text: "Some"
|
||||
├─ text: " "
|
||||
├─ emphasis[1]
|
||||
│ └─ text: "em"
|
||||
├─ text: " "
|
||||
├─ text: "or"
|
||||
├─ text: " "
|
||||
├─ strong[1]
|
||||
│ └─ text: "strong"
|
||||
└─ text: "."
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `findAndReplace(tree, find[, replace][, options])`
|
||||
|
||||
Find and replace text in [**mdast**][mdast] [*tree*][tree]s.
|
||||
The algorithm searches the tree in [*preorder*][preorder] for complete values
|
||||
in [`Text`][text] nodes.
|
||||
Partial matches are not supported.
|
||||
|
||||
###### Signatures
|
||||
|
||||
* `findAndReplace(tree, find, replace?[, options])`
|
||||
* `findAndReplace(tree, search[, options])`
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `tree` ([`Node`][node])
|
||||
— [**mdast**][mdast] [*tree*][tree]
|
||||
* `find` (`string` or `RegExp`)
|
||||
— Value to find and remove.
|
||||
When `string`, escaped and made into a global `RegExp`
|
||||
* `replace` (`string` or `Function`)
|
||||
— Value to insert.
|
||||
When `string`, turned into a [`Text`][text] node.
|
||||
When `Function`, invoked with the results of calling `RegExp.exec` as
|
||||
arguments, in which case it can return a single or a list of [`Node`][node],
|
||||
a `string` (which is wrapped in a [`Text`][text] node), or `false` to not
|
||||
replace
|
||||
* `search` (`Object` or `Array`)
|
||||
— Perform multiple find-and-replaces.
|
||||
When `Array`, each entry is a tuple (`Array`) of a `find` (at `0`) and
|
||||
`replace` (at `1`).
|
||||
When `Object`, each key is a `find` (in string form) and each value is a
|
||||
`replace`
|
||||
* `options.ignore` (`Test`, default: `[]`)
|
||||
— Any [`unist-util-is`][test] compatible test.
|
||||
|
||||
###### Returns
|
||||
|
||||
The given, modified, `tree`.
|
||||
|
||||
## Security
|
||||
|
||||
Use of `mdast-util-find-and-replace` does not involve [**hast**][hast] or user
|
||||
content so there are no openings for [cross-site scripting (XSS)][xss] attacks.
|
||||
|
||||
## Related
|
||||
|
||||
* [`hast-util-find-and-replace`](https://github.com/syntax-tree/hast-util-find-and-replace)
|
||||
— hast utility to find and replace text
|
||||
* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
|
||||
— select unist nodes with CSS-like selectors
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
|
||||
started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
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]
|
||||
|
||||
<!-- Definition -->
|
||||
|
||||
[build-badge]: https://github.com/syntax-tree/mdast-util-find-and-replace/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/mdast-util-find-and-replace/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-find-and-replace.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-find-and-replace
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-find-and-replace.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/mdast-util-find-and-replace
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-find-and-replace.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=mdast-util-find-and-replace
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[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
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[hast]: https://github.com/syntax-tree/hast
|
||||
|
||||
[mdast]: https://github.com/syntax-tree/mdast
|
||||
|
||||
[node]: https://github.com/syntax-tree/mdast#ndoes
|
||||
|
||||
[tree]: https://github.com/syntax-tree/unist#tree
|
||||
|
||||
[preorder]: https://github.com/syntax-tree/unist#preorder
|
||||
|
||||
[text]: https://github.com/syntax-tree/mdast#text
|
||||
|
||||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
|
||||
|
||||
[test]: https://github.com/syntax-tree/unist-util-is#api
|
||||
Reference in New Issue
Block a user