Skip to content

Commit 759b7a9

Browse files
docs(readme): document trim option under Options and FAQ
1 parent d2964e8 commit 759b7a9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,32 @@ See [htmlparser2 options](https://github.com/fb55/htmlparser2/wiki/Parser-option
252252

253253
> **Warning**: By overriding htmlparser2 options, there's a chance of breaking universal rendering. Do this at your own risk.
254254
255+
### trim
256+
257+
Normally, whitespace is preserved:
258+
259+
```js
260+
parse('<br>\n'); // [React.createElement('br'), '\n']
261+
```
262+
263+
By enabling the `trim` option, whitespace text nodes will be skipped:
264+
265+
```js
266+
parse('<br>\n', { trim: true }); // React.createElement('br')
267+
```
268+
269+
This addresses the warning:
270+
271+
```
272+
Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <table>. Make sure you don't have any extra whitespace between tags on each line of your source code.
273+
```
274+
275+
However, this option may strip out intentional whitespace:
276+
277+
```js
278+
parse('<p> </p>', { trim: true }); // React.createElement('p')
279+
```
280+
255281
## FAQ
256282

257283
#### Is this library XSS safe?
@@ -288,6 +314,10 @@ parse('<div /><div />'); // returns single element instead of array of elements
288314

289315
See [#158](https://github.com/remarkablemark/html-react-parser/issues/158).
290316

317+
#### I get "Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of table."
318+
319+
Enable the [trim](https://github.com/remarkablemark/html-react-parser#trim) option. See [#155](https://github.com/remarkablemark/html-react-parser/issues/155).
320+
291321
## Benchmarks
292322

293323
```sh

0 commit comments

Comments
 (0)