rsuite-theme
Version:
The suite theme for pagurian
90 lines (55 loc) • 1.9 kB
Markdown
Modify direct children of a parent.
[][]:
```bash
npm install unist-util-modify-children
```
```javascript
var remark = require('remark');
var modifyChildren = require('unist-util-modify-children');
var doc = remark().use(plugin).process('This _and_ that');
console.log(String(doc));
function plugin() {
return transformer;
function transformer(tree) {
modifyChildren(modifier)(tree.children[0]);
}
}
function modifier(node, index, parent) {
if (node.type === 'emphasis') {
parent.children.splice(index, 1, {type: 'strong', children: node.children});
return index + 1;
}
}
```
Yields:
```js
This **and** that
```
Wrap [`modifier`][modifier] to be invoked for each child in the node given to
[`modify`][modify].
Invoked if [`modify`][modify] is called on a parent node for each `child`
in `parent`.
`number` (optional) — Next position to iterate.
Invoke the bound [`modifier`][modifier] for each child in `parent`
([`Node`][node]).
[][license] © [Titus Wormer][author]
<!-- Definitions -->
[]: https://img.shields.io/travis/syntax-tree/unist-util-modify-children.svg
[]: https://travis-ci.org/syntax-tree/unist-util-modify-children
[]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-modify-children.svg
[]: https://codecov.io/github/syntax-tree/unist-util-modify-children
[]: https://docs.npmjs.com/cli/install
[]: LICENSE
[]: http://wooorm.com
[]: https://github.com/syntax-tree/unist#node
[]:
[]: