Skip to content

Commit 38bb76e

Browse files
committed
Refactor prose
1 parent cfb7b7c commit 38bb76e

File tree

1 file changed

+49
-24
lines changed

1 file changed

+49
-24
lines changed

readme.md

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,35 @@
1010

1111
Modify direct children of a parent.
1212

13-
## Installation
13+
## Install
1414

1515
[npm][]:
1616

17-
```bash
17+
```sh
1818
npm install unist-util-modify-children
1919
```
2020

2121
## Usage
2222

23-
```javascript
24-
var remark = require('remark')
23+
```js
24+
var u = require('unist-builder')
2525
var modifyChildren = require('unist-util-modify-children')
2626

27-
var doc = remark()
28-
.use(plugin)
29-
.process('This _and_ that')
27+
var modify = modifyChildren(modifier)
3028

31-
console.log(String(doc))
29+
var tree = u('root', [
30+
u('leaf', '1'),
31+
u('node', [u('leaf', '2')]),
32+
u('leaf', '3')
33+
])
3234

33-
function plugin() {
34-
return transformer
35-
function transformer(tree) {
36-
modifyChildren(modifier)(tree.children[0])
37-
}
38-
}
35+
modify(tree)
36+
37+
console.dir(tree, {depth: null})
3938

4039
function modifier(node, index, parent) {
41-
if (node.type === 'emphasis') {
42-
parent.children.splice(index, 1, {type: 'strong', children: node.children})
40+
if (node.type === 'node') {
41+
parent.children.splice(index, 1, {type: 'subtree', children: node.children})
4342
return index + 1
4443
}
4544
}
@@ -48,7 +47,14 @@ function modifier(node, index, parent) {
4847
Yields:
4948

5049
```js
51-
This **and** that
50+
{
51+
type: 'root',
52+
children: [
53+
{ type: 'leaf', value: '1' },
54+
{ type: 'subtree', children: [ { type: 'leaf', value: '2' } ] },
55+
{ type: 'leaf', value: '3' }
56+
]
57+
}
5258
```
5359

5460
## API
@@ -72,13 +78,30 @@ in `parent`.
7278
Invoke the bound [`modifier`][modifier] for each child in `parent`
7379
([`Node`][node]).
7480

81+
## Related
82+
83+
* [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)
84+
— Visit nodes
85+
* [`unist-util-visit-parents`](https://github.com/syntax-tree/unist-util-visit-parents)
86+
— Visit nodes with ancestral information
87+
* [`unist-util-filter`](https://github.com/eush77/unist-util-filter)
88+
— Create a new tree with all nodes that pass a test
89+
* [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)
90+
— Create a new tree with all nodes mapped by a given function
91+
* [`unist-util-remove`](https://github.com/eush77/unist-util-remove)
92+
— Remove nodes from a tree that pass a test
93+
* [`unist-util-select`](https://github.com/eush77/unist-util-select)
94+
— Select nodes with CSS-like selectors
95+
7596
## Contribute
7697

77-
See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get
98+
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
7899
started.
100+
See [`support.md`][support] for ways to get help.
79101

80-
This organisation has a [Code of Conduct][coc]. By interacting with this
81-
repository, organisation, or community you agree to abide by its terms.
102+
This project has a [Code of Conduct][coc].
103+
By interacting with this repository, organisation, or community you agree to
104+
abide by its terms.
82105

83106
## License
84107

@@ -118,12 +141,14 @@ repository, organisation, or community you agree to abide by its terms.
118141

119142
[author]: https://wooorm.com
120143

144+
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
145+
146+
[support]: https://github.com/syntax-tree/.github/blob/master/support.md
147+
148+
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
149+
121150
[node]: https://github.com/syntax-tree/unist#node
122151

123152
[modifier]: #next--modifierchild-index-parent
124153

125154
[modify]: #function-modifyparent
126-
127-
[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md
128-
129-
[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md

0 commit comments

Comments
 (0)