Skip to content

Commit 5944dd8

Browse files
docs(readme): document option htmlparser2 and any risks
1 parent 8a057ed commit 5944dd8

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ parse(
106106

107107
The `replace` callback allows you to swap an element with another React element.
108108

109-
The first argument is an object with the same output as [htmlparser2](https://github.com/fb55/htmlparser2)'s [domhandler](https://github.com/fb55/domhandler#example):
109+
The first argument is an object with the same output as [htmlparser2](https://github.com/fb55/htmlparser2/tree/v3.10.1)'s [domhandler](https://github.com/fb55/domhandler#example):
110110

111111
```js
112112
parse('<br>', {
@@ -224,6 +224,34 @@ parse('<br>', {
224224
});
225225
```
226226

227+
### htmlparser2
228+
229+
This library passes the following options to [htmlparser2](https://github.com/fb55/htmlparser2/tree/v3.10.1) on the server-side:
230+
231+
```js
232+
{
233+
decodeEntities: true,
234+
lowerCaseAttributeNames: false
235+
}
236+
```
237+
238+
By passing your own options, the default library options will be **replaced** (not merged).
239+
240+
As a result, to enable `decodeEntities` and `xmlMode`, you need to do the following:
241+
242+
```js
243+
parse('<p /><p />', {
244+
htmlparser2: {
245+
decodeEntities: true,
246+
xmlMode: true
247+
}
248+
});
249+
```
250+
251+
See [htmlparser2 options](https://github.com/fb55/htmlparser2/wiki/Parser-options).
252+
253+
> **Warning**: By overriding htmlparser2 options, there's a chance of breaking universal rendering. Do this at your own risk.
254+
227255
## FAQ
228256

229257
#### Is this library XSS safe?

0 commit comments

Comments
 (0)