Skip to content

Commit f05c4c7

Browse files
李文富liwenfu
andauthored
Add exports of one and all
Closes GH-64. Co-authored-by: liwenfu <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
1 parent 3a669b7 commit f05c4c7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import {one} from './lib/one.js'
2020
import {handlers} from './lib/handlers/index.js'
2121
import {own} from './lib/util/own.js'
2222

23+
export {one} from './lib/one.js'
24+
export {all} from './lib/all.js'
25+
2326
var block = convert(['heading', 'paragraph', 'root'])
2427

2528
/**

readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,18 @@ Yields:
237237
Some text with <svg viewBox="0 0 1 1" width="1" height="1"><rect fill="black" x="0" y="0" width="1" height="1"></rect></svg> a graphic… Wait is that a dead pixel?
238238
```
239239

240+
### `all(h, parent)`
241+
242+
Helper function for writing custom handlers passed to `options.handlers`.
243+
Pass it `h` and a parent node (hast) and it will turn the node’s children into
244+
an array of transformed nodes (mdast).
245+
246+
### `one(h, node, parent)`
247+
248+
Helper function for writing custom handlers passed to `options.handlers`.
249+
Pass it `h`, a `node`, and its `parent` (hast) and it will turn `node` into
250+
mdast content.
251+
240252
## Security
241253

242254
Use of `hast-util-to-mdast` can open you up to a

test/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@ import rehypeStringify from 'rehype-parse'
1818
import remarkStringify from 'remark-stringify'
1919
import assert from 'mdast-util-assert'
2020
import {removePosition} from 'unist-util-remove-position'
21-
import {toMdast} from '../index.js'
21+
import {one, all, toMdast} from '../index.js'
2222

2323
var fixtures = path.join('test', 'fixtures')
2424

25+
test('exports', function (t) {
26+
t.assert(
27+
one,
28+
'should export `one`'
29+
)
30+
31+
t.assert(
32+
all,
33+
'should export `all`'
34+
)
35+
36+
t.end()
37+
})
38+
2539
test('core', function (t) {
2640
t.deepEqual(
2741
toMdast(u('root', [h('strong', 'Alpha')])),

0 commit comments

Comments
 (0)