1 | # rehype-parse [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]
|
2 |
|
3 | [Parser][] for [**unified**][unified]. Parses HTML to a
|
4 | [**HAST**][hast] syntax tree. Used in the [**rehype**
|
5 | processor][processor].
|
6 |
|
7 | ## Installation
|
8 |
|
9 | [npm][]:
|
10 |
|
11 | ```bash
|
12 | npm install rehype-parse
|
13 | ```
|
14 |
|
15 | ## Usage
|
16 |
|
17 | ```js
|
18 | var unified = require('unified');
|
19 | var createStream = require('unified-stream');
|
20 | var parse = require('rehype-parse');
|
21 | var stringify = require('rehype-stringify');
|
22 |
|
23 | process.stdin
|
24 | .pipe(createStream(unified().use(parse).use(stringify)))
|
25 | .pipe(process.stdout);
|
26 | ```
|
27 |
|
28 | ## API
|
29 |
|
30 | ### `processor.use(parse[, options])`
|
31 |
|
32 | Configure the `processor` to read HTML as input and process an
|
33 | [**HAST**][hast] syntax tree.
|
34 |
|
35 | ##### `options`
|
36 |
|
37 | ###### `options.fragment`
|
38 |
|
39 | Specify whether to parse a fragment (`boolean`, default: `false`),
|
40 | instead of a complete document. In document mode, unopened `html`,
|
41 | `head`, and `body` elements are opened in just the right places.
|
42 |
|
43 | ###### `options.verbose`
|
44 |
|
45 | Patch extra positional information (`boolean`, default: `false`).
|
46 | If specified, the following element:
|
47 |
|
48 | ```html
|
49 | <img src="#" alt>
|
50 | ```
|
51 |
|
52 | ...has the following `data`:
|
53 |
|
54 | ```js
|
55 | { position:
|
56 | { opening:
|
57 | { start: { line: 1, column: 1, offset: 0 },
|
58 | end: { line: 1, column: 18, offset: 17 } },
|
59 | closing: null,
|
60 | properties:
|
61 | { src:
|
62 | { start: { line: 1, column: 6, offset: 5 },
|
63 | end: { line: 1, column: 13, offset: 12 } },
|
64 | alt:
|
65 | { start: { line: 1, column: 14, offset: 13 },
|
66 | end: { line: 1, column: 17, offset: 16 } } } } }
|
67 | ```
|
68 |
|
69 | ### `parse.Parser`
|
70 |
|
71 | Access to the [parser][], if you need it.
|
72 |
|
73 | ## License
|
74 |
|
75 | [MIT][license] © [Titus Wormer][author]
|
76 |
|
77 |
|
78 |
|
79 | [build-badge]: https://img.shields.io/travis/wooorm/rehype.svg
|
80 |
|
81 | [build-status]: https://travis-ci.org/wooorm/rehype
|
82 |
|
83 | [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/rehype.svg
|
84 |
|
85 | [coverage-status]: https://codecov.io/github/wooorm/rehype
|
86 |
|
87 | [chat-badge]: https://img.shields.io/gitter/room/wooorm/rehype.svg
|
88 |
|
89 | [chat]: https://gitter.im/wooorm/rehype
|
90 |
|
91 | [license]: https://github.com/wooorm/rehype/blob/master/LICENSE
|
92 |
|
93 | [author]: http://wooorm.com
|
94 |
|
95 | [npm]: https://docs.npmjs.com/cli/install
|
96 |
|
97 | [unified]: https://github.com/unifiedjs/unified
|
98 |
|
99 | [processor]: https://github.com/wooorm/rehype/blob/master/packages/rehype
|
100 |
|
101 | [hast]: https://github.com/syntax-tree/hast
|
102 |
|
103 | [parser]: https://github.com/unifiedjs/unified#processorparser
|