Skip to content

Commit 9ad16c3

Browse files
committed
Update readme.md
1 parent 17df689 commit 9ad16c3

File tree

2 files changed

+101
-97
lines changed

2 files changed

+101
-97
lines changed

example.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1+
// Dependencies:
12
var heading = require('./index.js');
23
var remark = require('remark');
34

5+
// Plug-in:
6+
function plugin() {
7+
return function (node) {
8+
heading(node, 'foo', function (start, nodes, end) {
9+
return [
10+
start,
11+
{
12+
'type': 'paragraph',
13+
'children': [{
14+
'type': 'text',
15+
'value': 'Qux.'
16+
}]
17+
},
18+
end
19+
];
20+
});
21+
}
22+
}
23+
424
// Process a document.
5-
var doc = remark()
6-
.use(function () {
7-
return function (node) {
8-
heading(node, 'foo', function (start, nodes, end) {
9-
return [
10-
start,
11-
{
12-
'type': 'paragraph',
13-
'children': [
14-
{
15-
'type': 'text',
16-
'value': 'Qux.'
17-
}
18-
]
19-
},
20-
end
21-
];
22-
});
23-
}
24-
}).process([
25-
'# Foo',
26-
'',
27-
'Bar.',
28-
'',
29-
'# Baz',
30-
''
31-
].join('\n'));
25+
var file = remark().use(plugin).process([
26+
'# Foo',
27+
'',
28+
'Bar.',
29+
'',
30+
'# Baz',
31+
''
32+
].join('\n'));
3233

3334
// Yields:
34-
console.log('markdown', doc);
35+
console.log('markdown', String(file));

readme.md

Lines changed: 72 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,134 @@
1-
# mdast-util-heading-range [![Build Status][travis-badge]][travis] [![Coverage Status][coverage-badge]][coverage]
1+
# mdast-util-heading-range [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]
22

3-
Markdown heading as ranges in [**mdast**][mdast].
3+
<!--lint disable list-item-spacing heading-increment no-duplicate-headings-->
4+
5+
Markdown heading as ranges in [**MDAST**][mdast].
46

57
## Installation
68

7-
[npm][npm-install]:
9+
[npm][]:
810

911
```bash
1012
npm install mdast-util-heading-range
1113
```
1214

13-
**mdast-util-heading-range** is also as an AMD, CommonJS, and globals
14-
module, [uncompressed and compressed][releases].
15+
**mdast-util-heading-range** is also available as an AMD, CommonJS, and
16+
globals module, [uncompressed and compressed][releases].
1517

1618
## Usage
1719

20+
Dependencies:
21+
1822
```javascript
1923
var heading = require('mdast-util-heading-range');
2024
var remark = require('remark');
2125
```
2226

23-
Process a document.
27+
Plug-in:
2428

2529
```javascript
26-
var doc = remark()
27-
.use(function () {
28-
return function (node) {
29-
heading(node, 'foo', function (start, nodes, end) {
30-
return [
31-
start,
32-
{
33-
'type': 'paragraph',
34-
'children': [
35-
{
36-
'type': 'text',
37-
'value': 'Qux.'
38-
}
39-
]
40-
},
41-
end
42-
];
43-
});
44-
}
45-
}).process([
46-
'# Foo',
47-
'',
48-
'Bar.',
49-
'',
50-
'# Baz',
51-
''
52-
].join('\n'));
30+
function plugin() {
31+
return function (node) {
32+
heading(node, 'foo', function (start, nodes, end) {
33+
return [
34+
start,
35+
{
36+
'type': 'paragraph',
37+
'children': [{
38+
'type': 'text',
39+
'value': 'Qux.'
40+
}]
41+
},
42+
end
43+
];
44+
});
45+
}
46+
}
5347
```
5448

55-
Yields:
49+
Process a document.
5650

5751
```javascript
58-
console.log('markdown', doc);
52+
var file = remark().use(plugin).process([
53+
'# Foo',
54+
'',
55+
'Bar.',
56+
'',
57+
'# Baz',
58+
''
59+
].join('\n'));
5960
```
6061

61-
## API
62+
Yields:
6263

63-
### `heading(node, test, onrun)`
64+
```markdown
65+
# Foo
6466

65-
Transform part of a document without affecting other parts, by changing a
66-
section: a heading which passes `test`, until the next heading of the same
67-
or lower depth, or the end of the document.
67+
Qux.
6868

69-
**Parameters**
69+
# Baz
70+
```
7071

71-
* `node` ([`Node`][mdast-node]) — Node to search;
72+
## API
7273

73-
* `test` (`string`, `RegExp`, `function(string, Node): boolean`)
74-
— Heading to look for:
74+
### `heading(node, test, onrun)`
7575

76-
* When `string`, wrapped in
77-
`new RegExp('^(' + value + ')$', 'i')`;
76+
Transform part of a document without affecting other parts, by changing
77+
a section: a heading which passes `test`, until the next heading of the
78+
same or lower depth, or the end of the document.
7879

79-
* Then, when `RegExp`, wrapped in
80-
`function (value) {expression.test(value)}`.
80+
###### Parameters
8181

82-
* [`onrun`](#function-onrunstart-nodes-end-scope)
83-
(`Array.<Node>? = function (start, nodes, end)`)
84-
— Callback invoked when a range is found.
82+
* `node` ([`Node`][node]) — Node to search;
83+
* `test` (`string`, `RegExp`, `function(string, Node): boolean`)
84+
— Heading to look for. When `string`, wrapped in
85+
`new RegExp('^(' + value + ')$', 'i')`; when `RegExp`, wrapped
86+
in `function (value) {expression.test(value)}`.
87+
* `onrun` ([`Function`][onrun]).
8588

8689
#### `function onrun(start, nodes, end?, scope)`
8790

88-
**Parameters**
91+
Callback invoked when a range is found.
8992

90-
* `start` (`Heading`) — Start of range;
93+
###### Parameters
9194

95+
* `start` (`Heading`) — Start of range;
9296
* `nodes` (`Array.<Node>`) — Nodes between `start` and `end`;
93-
9497
* `end` (`Heading?`) — End of range, if any.
95-
9698
* `scope` (`Object`):
9799

98100
* `parent` (`Node`) — Parent of the range;
99101
* `start` (`number`) — Index of `start` in `parent`;
100102
* `end` (`number?`) — Index of `end` in `parent`.
101103

102-
**Returns**
103-
104-
`Array.<Node>?` — Zero or more nodes to replace the range (including
105-
`start`, and `end`) with.
106-
107104
## License
108105

109-
[MIT][license] © [Titus Wormer][home]
106+
[MIT][license] © [Titus Wormer][author]
110107

111108
<!-- Definitions -->
112109

113-
[travis-badge]: https://img.shields.io/travis/wooorm/mdast-util-heading-range.svg
110+
[build-badge]: https://img.shields.io/travis/wooorm/mdast-util-heading-range.svg
114111

115-
[travis]: https://travis-ci.org/wooorm/mdast-util-heading-range
112+
[build-status]: https://travis-ci.org/wooorm/mdast-util-heading-range
116113

117114
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/mdast-util-heading-range.svg
118115

119-
[coverage]: https://codecov.io/github/wooorm/mdast-util-heading-range
116+
[coverage-status]: https://codecov.io/github/wooorm/mdast-util-heading-range
120117

121-
[mdast]: https://github.com/wooorm/mdast
118+
[chat-badge]: https://img.shields.io/gitter/room/wooorm/remark.svg
122119

123-
[mdast-node]: https://github.com/wooorm/mdast#node
124-
125-
[npm-install]: https://docs.npmjs.com/cli/install
120+
[chat]: https://gitter.im/wooorm/remark
126121

127122
[releases]: https://github.com/wooorm/mdast-util-heading-range/releases
128123

129124
[license]: LICENSE
130125

131-
[home]: http://wooorm.com
126+
[author]: http://wooorm.com
127+
128+
[npm]: https://docs.npmjs.com/cli/install
129+
130+
[mdast]: https://github.com/wooorm/mdast
131+
132+
[node]: https://github.com/wooorm/mdast#node
133+
134+
[onrun]: #function-onrunstart-nodes-end-scope

0 commit comments

Comments
 (0)