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
-[Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of table](#warning-validatedomnesting-whitespace-text-nodes-cannot-appear-as-a-child-of-table)
50
51
-[Don't change case of tags](#dont-change-case-of-tags)
52
+
-[TS Error: Property 'attribs' does not exist on type 'DOMNode'](#ts-error-property-attribs-does-not-exist-on-type-domnode)
51
53
-[Performance](#performance)
52
54
-[Contributors](#contributors)
53
55
-[Code Contributors](#code-contributors)
@@ -133,9 +135,7 @@ parse(
133
135
);
134
136
```
135
137
136
-
### Options
137
-
138
-
#### replace(domNode)
138
+
### replace(domNode)
139
139
140
140
The `replace` option allows you to replace an element with another React element.
TypeScript projects will need to check the types in [v1.0.0](https://github.com/remarkablemark/html-react-parser/releases/tag/v1.0.0).
371
+
372
+
For `replace` option:
373
+
374
+
```tsx
375
+
importparse, { Element } from'html-react-parser';
376
+
377
+
parse('<br class="remove">', {
378
+
replace: domNode=> {
379
+
if (domNodeinstanceofElement&&domNode.attribs.class==='remove') {
380
+
return <></>;
381
+
}
382
+
}
383
+
});
384
+
```
385
+
352
386
## FAQ
353
387
354
-
####Is this XSS safe?
388
+
### Is this XSS safe?
355
389
356
390
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).
357
391
358
-
####Does invalid HTML get sanitized?
392
+
### Does invalid HTML get sanitized?
359
393
360
394
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).
361
395
362
-
####Are `<script>` tags parsed?
396
+
### Are `<script>` tags parsed?
363
397
364
398
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).
365
399
366
-
####Attributes aren't getting called
400
+
### Attributes aren't getting called
367
401
368
402
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).
369
403
370
-
####Parser throws an error
404
+
### Parser throws an error
371
405
372
406
If the parser throws an erorr, check if your arguments are valid. See ["Does invalid HTML get sanitized?"](#does-invalid-html-get-sanitized).
373
407
374
-
####Is SSR supported?
408
+
### Is SSR supported?
375
409
376
410
Yes, server-side rendering on Node.js is supported by this library. See [demo](https://repl.it/@remarkablemark/html-react-parser-SSR).
377
411
378
-
####Elements aren't nested correctly
412
+
### Elements aren't nested correctly
379
413
380
414
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:
381
415
@@ -385,11 +419,11 @@ parse('<div /><div />'); // returns single element instead of array of elements
385
419
386
420
See [#158](https://github.com/remarkablemark/html-react-parser/issues/158).
387
421
388
-
####Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of table
422
+
### Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of table
389
423
390
424
Enable the [trim](#trim) option. See [#155](https://github.com/remarkablemark/html-react-parser/issues/155).
391
425
392
-
####Don't change case of tags
426
+
### Don't change case of tags
393
427
394
428
Tags are lowercased by default. To prevent that from happening, pass the [htmlparser2 option](#htmlparser2):
See [#62](https://github.com/remarkablemark/html-react-parser/issues/62) and [example](https://repl.it/@remarkablemark/html-react-parser-62).
412
446
447
+
### TS Error: Property 'attribs' does not exist on type 'DOMNode'
448
+
449
+
The TypeScript error happens because `DOMNode` needs be an instance of domhandler's `Element`. See [migration](#migration) or [#199](https://github.com/remarkablemark/html-react-parser/issues/199).
0 commit comments