|
1 | | -# mdast-zone [![Build Status][travis-badge]][travis] [![Coverage Status][coverage-badge]][coverage] |
| 1 | +# mdast-zone [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat] |
2 | 2 |
|
3 | | -[**mdast**][mdast] utility to treat HTML comments as ranges or markers. |
| 3 | +<!--lint disable list-item-spacing heading-increment no-duplicate-headings--> |
| 4 | + |
| 5 | +[**MDAST**][mdast] utility to treat HTML comments as ranges or markers. |
4 | 6 | Useful as a base for remark plugins. |
5 | 7 |
|
6 | 8 | ## Installation |
7 | 9 |
|
8 | | -[npm][npm-install]: |
| 10 | +[npm][]: |
9 | 11 |
|
10 | 12 | ```bash |
11 | 13 | npm install mdast-zone |
12 | 14 | ``` |
13 | 15 |
|
14 | | -**mdast-zone** is also available for [duo][], and as an AMD, CommonJS, |
15 | | -and globals module, [uncompressed and compressed][releases]. |
16 | | - |
17 | | -## Table of Contents |
18 | | - |
19 | | -* [Usage](#usage) |
20 | | - |
21 | | -* [API](#api) |
22 | | - |
23 | | - * [zone(options)](#zoneoptions) |
24 | | - |
25 | | - * [Marker](#marker) |
26 | | - * [function onparse(marker)](#function-onparsemarker) |
27 | | - * [function onstringify(marker)](#function-onstringifymarker) |
28 | | - * [function onrun(start, nodes, end, scope)](#function-onrunstart-nodes-end-scope) |
29 | | - |
30 | | -* [License](#license) |
| 16 | +**mdast-zone** is also available as an AMD, CommonJS, and |
| 17 | +globals module, [uncompressed and compressed][releases]. |
31 | 18 |
|
32 | 19 | ## Usage |
33 | 20 |
|
@@ -101,114 +88,94 @@ The first is exposed by this plugin in the form of an HTML comment which |
101 | 88 | sort-of looks like a self-closing, custom tag. The second by placing starting |
102 | 89 | and ending tags, as siblings, in a parent. |
103 | 90 |
|
104 | | -**Parameters**: |
105 | | - |
106 | | -* `options` (`Object`): |
107 | | - |
108 | | - * `name` (`string`) — Type to look for; |
109 | | - |
110 | | - * `onparse` ([`Function`](#function-onparsemarker), optional) |
111 | | - — Callback invoked when a marker is found during parsing; |
| 91 | +###### `options` |
112 | 92 |
|
113 | | - * `onstringify` ([`Function`](#function-onstringifymarker), optional) |
114 | | - — Callback invoked when a marker is found during stringification; |
| 93 | +* `name` (`string`) — Type to look for; |
| 94 | +* `onparse` ([`Function`][onparse], optional) |
| 95 | + — Callback invoked when a marker is found during parsing; |
| 96 | +* `onstringify` ([`Function`][onstringify], optional) |
| 97 | + — Callback invoked when a marker is found during stringification; |
| 98 | +* `onrun` ([Function][onrun], optional) |
| 99 | + — Callback invoked when a range is found during transformation. |
115 | 100 |
|
116 | | - * `onrun` ([Function](#function-onrunstart-nodes-end-scope), optional) |
117 | | - — Callback invoked when a range is found during transformation. |
| 101 | +###### Returns |
118 | 102 |
|
119 | | -**Returns**: `Function` — Should be passed to [`remark.use()`](https://github.com/wooorm/remark#remarkuseplugin-options). |
120 | | - |
121 | | -#### `Marker` |
122 | | - |
123 | | -**Example** |
124 | | - |
125 | | -```markdown |
126 | | -<!--foo bar="baz" qux--> |
127 | | -``` |
128 | | - |
129 | | -Yields: |
130 | | - |
131 | | -```json |
132 | | -{ |
133 | | - "type": "marker", |
134 | | - "attributes": "bar=\"baz\" qux", |
135 | | - "parameters": { |
136 | | - "bar": "baz", |
137 | | - "qux": true |
138 | | - }, |
139 | | - "node": { |
140 | | - "type": "html", |
141 | | - "value": "<!--foo bar=\"baz\" qux-->" |
142 | | - } |
143 | | -} |
144 | | -``` |
145 | | - |
146 | | -**Fields** |
147 | | - |
148 | | -* `type` (`string`) — Either `"marker"`, `"start"`, or `"end"`; |
149 | | -* `attributes` (`string`) — Raw, unparsed value; |
150 | | -* `parameters` (`Object.<string, *>`) — Parsed attributes; |
151 | | -* `node` ([`Node`][mdast-node]) — Original HTML node. |
| 103 | +`Function`, which should be passed to [`remark.use()`][use]. |
152 | 104 |
|
153 | 105 | #### `function onparse(marker)` |
154 | 106 |
|
155 | 107 | #### `function onstringify(marker)` |
156 | 108 |
|
157 | | -**Parameters** |
158 | | - |
159 | | -* `marker` ([`Marker`](#marker)) — Marker. |
160 | | - |
161 | 109 | When passing `name: "foo"` and `onparse: console.log.bind(console)` to |
162 | | -`zone()`, comments in the form of `<!--foo bar="baz" qux-->` are detected and |
163 | | -`onparse` is invoked: |
| 110 | +`zone()`, comments in the form of `<!--foo bar="baz" qux-->` are detected |
| 111 | +and `onparse` is invoked during the parsing phase. |
164 | 112 |
|
165 | 113 | An `onstringify` method could (instead, or both) be passed to `zone()`, |
166 | | -which would be invoked with the same `marker` but during the stringification |
167 | | -phase. |
| 114 | +which would be invoked with the same `marker` but during the |
| 115 | +stringification phase. |
168 | 116 |
|
169 | | -#### function onrun(start, nodes, end, scope) |
| 117 | +###### Parameters |
170 | 118 |
|
171 | | -**Parameters** |
| 119 | +* `marker` ([`Marker`][marker]). |
172 | 120 |
|
173 | | -* `start` ([`Marker`](#marker)) — Start of range; |
| 121 | +#### `function onrun(start, nodes, end, scope)` |
174 | 122 |
|
175 | | -* `nodes` (`Array.<Node>`) — Nodes between `start` and `end`; |
| 123 | +Invoked during the transformation phase with markers which determine |
| 124 | +a range: two markers, the first `start` and the last `end`, and the |
| 125 | +content inside. |
176 | 126 |
|
177 | | -* `end` ([`Marker`](#marker)) — End of range. |
| 127 | +###### Parameters |
178 | 128 |
|
| 129 | +* `start` ([`Marker`][marker]) — Start of range; |
| 130 | +* `nodes` (`Array.<Node>`) — Nodes between `start` and `end`; |
| 131 | +* `end` ([`Marker`][marker]) — End of range. |
179 | 132 | * `scope` (`Object`): |
180 | 133 |
|
181 | | - * `parent` ([`Node`][mdast-node]) — Parent of the range; |
| 134 | + * `parent` ([`Node`][node]) — Parent of the range; |
182 | 135 | * `start` (`number`) — Index of `start` in `parent`; |
183 | 136 | * `end` (`number`) — Index of `end` in `parent`. |
184 | 137 |
|
185 | | -**Returns**: `Array.<Node>?` — Zero or more nodes to replace the range |
186 | | -(including `start` and `end`s HTML comments) with. |
| 138 | +###### Returns |
| 139 | + |
| 140 | +`Array.<Node>?` — Zero or more nodes to replace the range (including |
| 141 | +`start` and `end`s markers) with. |
187 | 142 |
|
188 | 143 | ## License |
189 | 144 |
|
190 | | -[MIT][license] © [Titus Wormer][home] |
| 145 | +[MIT][license] © [Titus Wormer][author] |
191 | 146 |
|
192 | 147 | <!-- Definitions --> |
193 | 148 |
|
194 | | -[travis-badge]: https://img.shields.io/travis/wooorm/mdast-zone.svg |
| 149 | +[build-badge]: https://img.shields.io/travis/wooorm/mdast-zone.svg |
195 | 150 |
|
196 | | -[travis]: https://travis-ci.org/wooorm/mdast-zone |
| 151 | +[build-status]: https://travis-ci.org/wooorm/mdast-zone |
197 | 152 |
|
198 | 153 | [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/mdast-zone.svg |
199 | 154 |
|
200 | | -[coverage]: https://codecov.io/github/wooorm/mdast-zone |
| 155 | +[coverage-status]: https://codecov.io/github/wooorm/mdast-zone |
| 156 | + |
| 157 | +[chat-badge]: https://img.shields.io/gitter/room/wooorm/remark.svg |
| 158 | + |
| 159 | +[chat]: https://gitter.im/wooorm/remark |
| 160 | + |
| 161 | +[releases]: https://github.com/wooorm/mdast-zone/releases |
| 162 | + |
| 163 | +[license]: LICENSE |
| 164 | + |
| 165 | +[author]: http://wooorm.com |
| 166 | + |
| 167 | +[npm]: https://docs.npmjs.com/cli/install |
201 | 168 |
|
202 | 169 | [mdast]: https://github.com/wooorm/mdast |
203 | 170 |
|
204 | | -[mdast-node]: https://github.com/wooorm/mdast#node |
| 171 | +[node]: https://github.com/wooorm/mdast#node |
205 | 172 |
|
206 | | -[npm-install]: https://docs.npmjs.com/cli/install |
| 173 | +[onparse]: #function-onparsemarker |
207 | 174 |
|
208 | | -[duo]: http://duojs.org/#getting-started |
| 175 | +[onstringify]: #function-onstringifymarker |
209 | 176 |
|
210 | | -[releases]: https://github.com/wooorm/mdast-zone/releases |
| 177 | +[onrun]: #function-onrunstart-nodes-end-scope |
211 | 178 |
|
212 | | -[license]: LICENSE |
| 179 | +[use]: https://github.com/wooorm/unified#processoruseplugin-options |
213 | 180 |
|
214 | | -[home]: http://wooorm.com |
| 181 | +[marker]: https://github.com/wooorm/mdast-comment-marker#marker |
0 commit comments