3
3
[ ![ Build] [ build-badge ]] [ build ]
4
4
[ ![ Coverage] [ coverage-badge ]] [ coverage ]
5
5
[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
+ [ ![ Size] [ size-badge ]] [ size ]
7
+ [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8
+ [ ![ Backers] [ backers-badge ]] [ collective ]
6
9
[ ![ Chat] [ chat-badge ]] [ chat ]
7
10
8
- Transform [ HAST ] [ ] to HTML.
11
+ [ ** hast ** ] [ hast ] utility to transform to HTML.
9
12
10
- ## Installation
13
+ ## Install
11
14
12
15
[ npm] [ ] :
13
16
14
- ``` bash
17
+ ``` sh
15
18
npm install hast-util-to-html
16
19
```
17
20
18
21
## Usage
19
22
20
- ``` javascript
23
+ ``` js
21
24
var h = require (' hastscript' )
22
25
var toHTML = require (' hast-util-to-html' )
23
26
@@ -41,27 +44,29 @@ Yields:
41
44
42
45
### ` toHTML(tree[, options]) `
43
46
44
- Stringify the given [ HAST tree] [ hast ] .
47
+ Stringify the given [ ** hast ** ] [ hast ] [ * tree* ] [ tree ] .
45
48
46
49
###### ` options.space `
47
50
48
- Whether the root of the given tree is in the ` 'html' ` or ` 'svg' ` space (enum,
49
- ` 'svg' ` or ` 'html' ` , default: ` 'html' ` ).
51
+ Whether the [ * root* ] [ root ] of the [ * tree* ] [ tree ] is in the ` 'html' ` or ` 'svg' `
52
+ space (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` ).
50
53
51
54
If an ` svg ` element is found in the HTML space, ` toHTML ` automatically switches
52
- to the SVG space when entering the element, and switches back when leaving .
55
+ to the SVG space when entering the element, and switches back when exiting .
53
56
54
57
###### ` options.entities `
55
58
56
- Configuration for [ ` stringify-entities ` ] [ stringify-entities ]
57
- (` Object ` , default: ` {} ` ). Do not use ` escapeOnly ` , ` attribute ` , or
58
- ` subset ` (` toHTML ` already passes those). However, ` useNamedReferences ` ,
59
- ` useShortestReferences ` , and ` omitOptionalSemicolons ` are all fine.
59
+ Configuration for [ ` stringify-entities ` ] [ stringify-entities ] (` Object ` , default:
60
+ ` {} ` ).
61
+ Do not use ` escapeOnly ` , ` attribute ` , or ` subset ` (` toHTML ` already passes
62
+ those, so they won’t work).
63
+ However, ` useNamedReferences ` , ` useShortestReferences ` , and
64
+ ` omitOptionalSemicolons ` are all fine.
60
65
61
66
###### ` options.voids `
62
67
63
- Tag- names of elements to stringify without closing tag ( ` Array.<string> ` ,
64
- default: [ ` html-void-elements ` ] [ html-void-elements ] ).
68
+ Tag names of [ * elements* ] [ element ] to stringify without closing tag
69
+ ( ` Array.<string> ` , default: [ ` html-void-elements ` ] [ html-void-elements ] ).
65
70
66
71
Not used in the SVG space.
67
72
@@ -71,37 +76,38 @@ Preferred quote to use (`'"'` or `'\''`, default: `'"'`).
71
76
72
77
###### ` options.quoteSmart `
73
78
74
- Use the other quote if that results in less bytes (` boolean ` , default:
75
- ` false ` ).
79
+ Use the other quote if that results in less bytes (` boolean ` , default: ` false ` ).
76
80
77
81
###### ` options.preferUnquoted `
78
82
79
- Leave attributes unquoted if that results in less bytes (` boolean ` ,
80
- default: ` false ` ).
83
+ Leave attributes unquoted if that results in less bytes (` boolean ` , default:
84
+ ` false ` ).
81
85
82
86
Not used in the SVG space.
83
87
84
88
###### ` options.omitOptionalTags `
85
89
86
90
Omit optional opening and closing tags (` boolean ` , default: ` false ` ).
87
91
For example, in ` <ol><li>one</li><li>two</li></ol> ` , both ` </li> `
88
- closing tags can be omitted. The first because it’s followed by
89
- another ` li ` , the last because it’s followed by nothing.
92
+ closing tags can be omitted.
93
+ The first because it’s followed by another ` li ` , the last because it’s followed
94
+ by nothing.
90
95
91
96
Not used in the SVG space.
92
97
93
98
###### ` options.collapseEmptyAttributes `
94
99
95
100
Collapse empty attributes: ` class="" ` is stringified as ` class ` instead
96
- (` boolean ` , default: ` false ` ). ** Note ** : boolean attributes, such as
97
- ` hidden ` , are always collapsed.
101
+ (` boolean ` , default: ` false ` ).
102
+ ** Note ** : boolean attributes, such as ` hidden ` , are always collapsed.
98
103
99
104
Not used in the SVG space.
100
105
101
106
###### ` options.closeSelfClosing `
102
107
103
108
Close self-closing nodes with an extra slash (` / ` ): ` <img /> ` instead of
104
109
` <img> ` (` boolean ` , default: ` false ` ).
110
+ See ` tightSelfClosing ` to control whether a space is used before the slash.
105
111
106
112
Not used in the SVG space.
107
113
@@ -110,55 +116,56 @@ Not used in the SVG space.
110
116
Close SVG elements without any content with slash (` / ` ) on the opening tag
111
117
instead of an end tag: ` <circle /> ` instead of ` <circle></circle> ` (` boolean ` ,
112
118
default: ` false ` ).
119
+ See ` tightSelfClosing ` to control whether a space is used before the slash.
113
120
114
121
Not used in the HTML space.
115
122
116
123
###### ` options.tightSelfClosing `
117
124
118
- Do not use an extra space when closing self-closing elements: ` <img/> `
119
- instead of ` <img /> ` (` boolean ` , default: ` false ` ). ** Note ** : Only used
120
- if ` closeSelfClosing: true ` or ` closeEmptyElements: true ` .
125
+ Do not use an extra space when closing self-closing elements: ` <img/> ` instead
126
+ of ` <img /> ` (` boolean ` , default: ` false ` ).
127
+ ** Note ** : Only used if ` closeSelfClosing: true ` or ` closeEmptyElements: true ` .
121
128
122
129
###### ` options.tightCommaSeparatedLists `
123
130
124
- Join known comma-separated attribute values with just a comma (` , ` ),
125
- instead of padding them on the right as well (` ,· ` , where ` · ` represents a
126
- space) (` boolean ` , default: ` false ` ).
131
+ Join known comma-separated attribute values with just a comma (` , ` ), instead of
132
+ padding them on the right as well (` ,· ` , where ` · ` represents a space)
133
+ (` boolean ` , default: ` false ` ).
127
134
128
135
###### ` options.tightAttributes `
129
136
130
- Join attributes together, without white-space, if possible:
131
- ` class="a b" title="c d"` is stringified as ` class="a b"title="c d" `
132
- instead to save bytes (` boolean ` , default: ` false ` ). ** Note ** : creates
133
- invalid (but working) markup.
137
+ Join attributes together, without white-space, if possible: `class="a b"
138
+ title="c d"` is stringified as ` class="a b"title="c d"` instead to save bytes
139
+ (` boolean ` , default: ` false ` ).
140
+ ** Note ** : creates invalid (but working) markup.
134
141
135
142
Not used in the SVG space.
136
143
137
144
###### ` options.tightDoctype `
138
145
139
146
Drop unneeded spaces in doctypes: ` <!doctypehtml> ` instead of ` <!doctype html> `
140
- to save bytes (` boolean ` , default: ` false ` ). ** Note ** : creates
141
- invalid (but working) markup.
147
+ to save bytes (` boolean ` , default: ` false ` ).
148
+ ** Note ** : creates invalid (but working) markup.
142
149
143
150
###### ` options.allowParseErrors `
144
151
145
- Do not encode characters which trigger parse errors (even though they
146
- work), to save bytes (` boolean ` , default: ` false ` ). ** Note ** : creates
147
- invalid (but working) markup.
152
+ Do not encode characters which cause parse errors (even though they work), to
153
+ save bytes (` boolean ` , default: ` false ` ).
154
+ ** Note ** : creates invalid (but working) markup.
148
155
149
156
Not used in the SVG space.
150
157
151
158
###### ` options.allowDangerousCharacters `
152
159
153
- Do not encode some characters which cause XSS vulnerabilities in older
154
- browsers (` boolean ` , default: ` false ` ). ** Note ** : Only set this if you
155
- completely trust the content.
160
+ Do not encode some characters which cause XSS vulnerabilities in older browsers
161
+ (` boolean ` , default: ` false ` ).
162
+ ** Note ** : Only set this if you completely trust the content.
156
163
157
164
###### ` options.allowDangerousHTML `
158
165
159
- Allow ` raw ` nodes and insert them as raw HTML. When falsey, encodes
160
- ` raw ` nodes (` boolean ` , default: ` false ` ). ** Note ** : Only set this if
161
- you completely trust the content.
166
+ Allow ` raw ` nodes and insert them as raw HTML.
167
+ When falsey, encodes ` raw ` nodes (` boolean ` , default: ` false ` ).
168
+ ** Note ** : Only set this if you completely trust the content.
162
169
163
170
## Related
164
171
@@ -169,11 +176,13 @@ you completely trust the content.
169
176
170
177
## Contribute
171
178
172
- See [ ` contributing.md ` in ` syntax-tree/hast ` ] [ contributing ] for ways to get
179
+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
173
180
started.
181
+ See [ ` support.md ` ] [ support ] for ways to get help.
174
182
175
- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
176
- repository, organisation, or community you agree to abide by its terms.
183
+ This project has a [ Code of Conduct] [ coc ] .
184
+ By interacting with this repository, organisation, or community you agree to
185
+ abide by its terms.
177
186
178
187
## License
179
188
@@ -193,24 +202,42 @@ repository, organisation, or community you agree to abide by its terms.
193
202
194
203
[ downloads ] : https://www.npmjs.com/package/hast-util-to-html
195
204
205
+ [ size-badge ] : https://img.shields.io/bundlephobia/minzip/hast-util-to-html.svg
206
+
207
+ [ size ] : https://bundlephobia.com/result?p=hast-util-to-html
208
+
209
+ [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
210
+
211
+ [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
212
+
213
+ [ collective ] : https://opencollective.com/unified
214
+
196
215
[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
197
216
198
- [ chat ] : https://spectrum.chat/unified/rehype
217
+ [ chat ] : https://spectrum.chat/unified/syntax-tree
199
218
200
219
[ npm ] : https://docs.npmjs.com/cli/install
201
220
202
221
[ license ] : license
203
222
204
223
[ author ] : https://wooorm.com
205
224
206
- [ hast ] : https://github.com/syntax-tree/hast
225
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
226
+
227
+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
228
+
229
+ [ coc ] : https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
207
230
208
231
[ html-void-elements ] : https://github.com/wooorm/html-void-elements
209
232
210
233
[ stringify-entities ] : https://github.com/wooorm/stringify-entities
211
234
212
235
[ hast-util-sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
213
236
214
- [ contributing ] : https://github.com/syntax-tree/hast/blob/master/contributing.md
237
+ [ tree ] : https://github.com/syntax-tree/unist#tree
238
+
239
+ [ root ] : https://github.com/syntax-tree/unist#root
240
+
241
+ [ hast ] : https://github.com/syntax-tree/hast
215
242
216
- [ coc ] : https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md
243
+ [ element ] : https://github.com/syntax-tree/hast#element
0 commit comments