Skip to content

Commit

Permalink
docs(readme): document option htmlparser2 and any risks
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 3, 2020
1 parent 8a057ed commit 5944dd8
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ parse(

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

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):
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):

```js
parse('<br>', {
Expand Down Expand Up @@ -224,6 +224,34 @@ parse('<br>', {
});
```

### htmlparser2

This library passes the following options to [htmlparser2](https://github.com/fb55/htmlparser2/tree/v3.10.1) on the server-side:

```js
{
decodeEntities: true,
lowerCaseAttributeNames: false
}
```

By passing your own options, the default library options will be **replaced** (not merged).

As a result, to enable `decodeEntities` and `xmlMode`, you need to do the following:

```js
parse('<p /><p />', {
htmlparser2: {
decodeEntities: true,
xmlMode: true
}
});
```

See [htmlparser2 options](https://github.com/fb55/htmlparser2/wiki/Parser-options).

> **Warning**: By overriding htmlparser2 options, there's a chance of breaking universal rendering. Do this at your own risk.
## FAQ

#### Is this library XSS safe?
Expand Down

0 comments on commit 5944dd8

Please sign in to comment.