|
1 |
| -# hast-util-to-mdast |
| 1 | +# hast-util-to-mdast [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] |
2 | 2 |
|
3 |
| -Convert [HAST trees](https://github.com/syntax-tree/hast) to [MDAST trees](https://github.com/syntax-tree/mdast). |
| 3 | +Transform [HAST][] (HTML) to [MDAST][] (markdown). |
4 | 4 |
|
5 |
| -## About |
| 5 | +> :warn: Work in progress :warn |
| 6 | +> See [GH-3][3] for progress. |
6 | 7 |
|
7 |
| -Based on the code in [mdast-util-to-hast](https://github.com/wooorm/mdast-util-to-hast), this module provides a way to transform an HTML abstract syntax tree into a markdown abstract syntax tree. |
| 8 | +## Installation |
8 | 9 |
|
9 |
| -Used with [rehype](https://npmjs.com/rehype) and [remark](https://npmjs.com/remark), this allows you to convert HTML into markdown. |
| 10 | +[npm][]: |
10 | 11 |
|
11 |
| -### Work in progress |
| 12 | +```bash |
| 13 | +npm install hast-util-to-mdast |
| 14 | +``` |
12 | 15 |
|
13 |
| -So far this only transforms a few HTML elements, and there's more work to do. To see what's been completed so far look at [the handlers directory](/handlers). |
| 16 | +## Usage |
14 | 17 |
|
15 |
| -## Install |
| 18 | +```javascript |
| 19 | +var rehype = require('rehype'); |
| 20 | +var remark = require('remark'); |
| 21 | +var toMDAST = require('hast-util-to-mdast'); |
16 | 22 |
|
17 |
| -```sh |
18 |
| -npm install --save hast-util-to-mdast |
| 23 | +var hast = rehype().parse('<h2>Hello <strong>world!</strong></h2>'); |
| 24 | +var doc = remark().stringify(toMDAST(hast)); |
| 25 | +console.log(doc); |
19 | 26 | ```
|
20 | 27 |
|
21 |
| -## Usage |
| 28 | +Yields: |
22 | 29 |
|
23 |
| -```js |
24 |
| -var unified = require('unified') |
25 |
| -var parse = require('rehype-parse') |
26 |
| -var stringify = require('remark-stringify') |
| 30 | +```txt |
| 31 | +## Hello **world!** |
| 32 | +``` |
27 | 33 |
|
28 |
| -var toMDAST = require('hast-util-to-mdast') |
| 34 | +## API |
29 | 35 |
|
30 |
| -var result = unified() |
31 |
| - .use(parse) |
32 |
| - .use(function () { return toMDAST }) |
33 |
| - .use(stringify) |
34 |
| - .process(html, { fragment: true }) |
| 36 | +### `toMDAST(node)` |
35 | 37 |
|
36 |
| -console.log(result.contents) |
37 |
| -``` |
| 38 | +Transform the given [HAST][] tree to an [MDAST][] tree. |
38 | 39 |
|
| 40 | +## Related |
| 41 | + |
| 42 | +* [`mdast-util-to-hast`][mdast-util-to-hast] |
39 | 43 |
|
40 | 44 | ## License
|
41 | 45 |
|
42 |
| -[MIT](LICENSE.md) |
| 46 | +[MIT][license] © [Titus Wormer][author] |
| 47 | + |
| 48 | +<!-- Definitions --> |
| 49 | + |
| 50 | +[travis-badge]: https://img.shields.io/travis/syntax-tree/hast-util-to-mdast.svg |
| 51 | + |
| 52 | +[travis]: https://travis-ci.org/syntax-tree/hast-util-to-mdast |
| 53 | + |
| 54 | +[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-mdast.svg |
| 55 | + |
| 56 | +[codecov]: https://codecov.io/github/syntax-tree/hast-util-to-mdast |
| 57 | + |
| 58 | +[npm]: https://docs.npmjs.com/cli/install |
| 59 | + |
| 60 | +[license]: LICENSE |
| 61 | + |
| 62 | +[author]: http://wooorm.com |
| 63 | + |
| 64 | +[mdast]: https://github.com/syntax-tree/mdast |
| 65 | + |
| 66 | +[hast]: https://github.com/syntax-tree/hast |
| 67 | + |
| 68 | +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast |
| 69 | + |
| 70 | +[3]: https://github.com/syntax-tree/hast-util-to-mdast/issues/3 |
0 commit comments