2
2
3
3
Transform [ HAST] [ ] (HTML) to [ MDAST] [ ] (markdown).
4
4
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] [ ] .
8
6
9
7
## Installation
10
8
@@ -16,17 +14,30 @@ npm install hast-util-to-mdast
16
14
17
15
## Usage
18
16
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
+
19
25
``` 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' );
22
30
var toMDAST = require (' hast-util-to-mdast' );
23
31
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
+
26
37
console .log (doc);
27
38
```
28
39
29
- Yields :
40
+ Now, running ` node example.js ` yields :
30
41
31
42
``` markdown
32
43
## Hello **world!**
@@ -38,6 +49,8 @@ Yields:
38
49
39
50
Transform the given [ HAST] [ ] tree to an [ MDAST] [ ] tree.
40
51
52
+ ##### Options
53
+
41
54
###### ` options.handlers `
42
55
43
56
Object mapping tag-names to functions handling those elements.
@@ -49,6 +62,10 @@ Whether the given tree is a complete document. If `document: true`,
49
62
implicit paragraphs are added in the ` root ` node around inline MDAST nodes.
50
63
Otherwise, inline MDAST nodes are wrapped when needed.
51
64
65
+ ##### Returns
66
+
67
+ [ ` MDASTNode ` ] [ mdast ] .
68
+
52
69
## Related
53
70
54
71
* [ ` mdast-util-to-hast ` ] [ mdast-util-to-hast ]
@@ -87,7 +104,7 @@ repository, organisation, or community you agree to abide by its terms.
87
104
88
105
[ mdast-util-to-hast ] : https://github.com/syntax-tree/mdast-util-to-hast
89
106
90
- [ 3 ] : https://github.com/syntax-tree/hast-util-to-mdast/issues/3
107
+ [ rehype-remark ] : https://github.com/rehypejs/rehype-remark
91
108
92
109
[ handlers ] : https://github.com/syntax-tree/hast-util-to-mdast/tree/master/handlers
93
110
0 commit comments