You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It converts an HTML string to one or more [React elements](https://reactjs.org/docs/react-api.html#creating-react-elements). There's also an option to [replace an element](#replacedomnode) with your own.
19
19
20
-
#### Example:
20
+
Example:
21
21
22
22
```js
23
-
var parse =require('html-react-parser');
23
+
constparse=require('html-react-parser');
24
24
parse('<div>text</div>'); // equivalent to `React.createElement('div', {}, 'text')`
No, this library is _**not**_[XSS (cross-site scripting)](https://wikipedia.org/wiki/Cross-site_scripting) safe. See [#94](https://github.com/remarkablemark/html-react-parser/issues/94).
302
302
303
-
#### Does this library sanitize invalid HTML?
303
+
#### Does invalid HTML get sanitized?
304
304
305
-
No, this library does _**not**_perform HTML sanitization. See [#124](https://github.com/remarkablemark/html-react-parser/issues/124), [#125](https://github.com/remarkablemark/html-react-parser/issues/125), and [#141](https://github.com/remarkablemark/html-react-parser/issues/141).
305
+
No, this library does _**not**_sanitize HTML. See [#124](https://github.com/remarkablemark/html-react-parser/issues/124), [#125](https://github.com/remarkablemark/html-react-parser/issues/125), and [#141](https://github.com/remarkablemark/html-react-parser/issues/141).
306
306
307
307
#### Are `<script>` tags parsed?
308
308
309
309
Although `<script>` tags and their contents are rendered on the server-side, they're not evaluated on the client-side. See [#98](https://github.com/remarkablemark/html-react-parser/issues/98).
310
310
311
-
#### Why aren't my HTML attributes getting called?
311
+
#### Attributes aren't getting called
312
312
313
-
This is because [inline event handlers](https://developer.mozilla.org/docs/Web/Guide/Events/Event_handlers)like`onclick` are parsed as a _string_instead of a _function_. See [#73](https://github.com/remarkablemark/html-react-parser/issues/73).
313
+
The reason why your HTML attributes aren't getting called is because [inline event handlers](https://developer.mozilla.org/docs/Web/Guide/Events/Event_handlers)(e.g.,`onclick`) are parsed as a _string_rather than a _function_. See [#73](https://github.com/remarkablemark/html-react-parser/issues/73).
314
314
315
-
#### The parser throws an error.
315
+
#### Parser throws an error
316
316
317
-
Check if your arguments are valid. Also, see ["Does this library sanitize invalid HTML?"](https://github.com/remarkablemark/html-react-parser#does-this-library-sanitize-invalid-html).
317
+
If the parser throws an erorr, check if your arguments are valid. See ["Does invalid HTML get sanitized?"](#does-invalid-html-get-sanitized).
318
318
319
-
#### Does this library support SSR?
319
+
#### Is SSR supported?
320
320
321
-
Yes, this library supports server-side rendering on Node.js. See [demo](https://repl.it/@remarkablemark/html-react-parser-SSR).
321
+
Yes, server-side rendering on Node.js is supported by this library. See [demo](https://repl.it/@remarkablemark/html-react-parser-SSR).
322
322
323
-
#### Why are my elements nested incorrectly?
323
+
#### Elements aren't nested correctly
324
324
325
-
Make sure your [HTML markup is valid](https://validator.w3.org/). The HTML to DOM parsing will be affected if you're using self-closing syntax (`/>`) on non-void elements:
325
+
If your elements are nested incorrectly, check to make sure your [HTML markup is valid](https://validator.w3.org/). The HTML to DOM parsing will be affected if you're using self-closing syntax (`/>`) on non-void elements:
326
326
327
327
```js
328
328
parse('<div /><div />'); // returns single element instead of array of elements
329
329
```
330
330
331
331
See [#158](https://github.com/remarkablemark/html-react-parser/issues/158).
332
332
333
-
#### I get "Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of table."
333
+
#### Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of table
334
334
335
-
Enable the [trim](https://github.com/remarkablemark/html-react-parser#trim) option. See [#155](https://github.com/remarkablemark/html-react-parser/issues/155).
335
+
Enable the [trim](#trim) option. See [#155](https://github.com/remarkablemark/html-react-parser/issues/155).
336
336
337
-
#### Don't change case of tags.
337
+
#### Don't change case of tags
338
338
339
-
Tags are lowercased by default. To prevent that from happening, pass the [htmlparser2 option](https://github.com/remarkablemark/html-react-parser#htmlparser2):
339
+
Tags are lowercased by default. To prevent that from happening, pass the [htmlparser2 option](#htmlparser2):
340
340
341
341
```js
342
342
constoptions= {
@@ -403,10 +403,10 @@ Support this project with your organization. Your logo will show up here with a
0 commit comments