Skip to content

Commit 321a38c

Browse files
committed
Refactor docs
1 parent 39fb71f commit 321a38c

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

readme.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
Transform [HAST][] (HTML) to [MDAST][] (markdown).
44

5-
> This is stable in versioning now, but may change a bit in the future.
6-
>
7-
> See [GH-3][3] for progress.
5+
> **Note**: You probably want to use [rehype-remark][].
86
97
## Installation
108

@@ -16,17 +14,30 @@ npm install hast-util-to-mdast
1614

1715
## Usage
1816

17+
Say we have the following `example.html`:
18+
19+
```html
20+
<h2>Hello <strong>world!</strong></h2>
21+
```
22+
23+
…and next to it, `example.js`:
24+
1925
```javascript
20-
var rehype = require('rehype');
21-
var remark = require('remark');
26+
var unified = require('unified');
27+
var parse = require('rehype-parse');
28+
var stringify = require('remark-stringify');
29+
var vfile = require('to-vfile');
2230
var toMDAST = require('hast-util-to-mdast');
2331

24-
var hast = rehype().parse('<h2>Hello <strong>world!</strong></h2>');
25-
var doc = remark().stringify(toMDAST(hast));
32+
var file = vfile.readSync('example.html');
33+
var hast = unified().use(parse).parse(file);
34+
var mdast = toMDAST(hast);
35+
var doc = unified().use(stringify).stringify(mdast);
36+
2637
console.log(doc);
2738
```
2839

29-
Yields:
40+
Now, running `node example.js` yields:
3041

3142
```markdown
3243
## Hello **world!**
@@ -38,6 +49,8 @@ Yields:
3849

3950
Transform the given [HAST][] tree to an [MDAST][] tree.
4051

52+
##### Options
53+
4154
###### `options.handlers`
4255

4356
Object mapping tag-names to functions handling those elements.
@@ -49,6 +62,10 @@ Whether the given tree is a complete document. If `document: true`,
4962
implicit paragraphs are added in the `root` node around inline MDAST nodes.
5063
Otherwise, inline MDAST nodes are wrapped when needed.
5164

65+
##### Returns
66+
67+
[`MDASTNode`][mdast].
68+
5269
## Related
5370

5471
* [`mdast-util-to-hast`][mdast-util-to-hast]
@@ -87,7 +104,7 @@ repository, organisation, or community you agree to abide by its terms.
87104

88105
[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast
89106

90-
[3]: https://github.com/syntax-tree/hast-util-to-mdast/issues/3
107+
[rehype-remark]: https://github.com/rehypejs/rehype-remark
91108

92109
[handlers]: https://github.com/syntax-tree/hast-util-to-mdast/tree/master/handlers
93110

0 commit comments

Comments
 (0)