An open API service indexing awesome lists of open source software.

https://github.com/ssi02014/react-sanitizer-parser

react-sanitizer-parser is a React element sanitizer parser.
https://github.com/ssi02014/react-sanitizer-parser

dompurify html-react-parser parser react xss

Last synced: 2 months ago
JSON representation

react-sanitizer-parser is a React element sanitizer parser.

Awesome Lists containing this project

README

          

# 💻 react-sanitizer-parser






react-sanitizer-parser is a React element sanitizer parser that utilizes the [html-react-parser](https://github.com/remarkablemark/html-react-parser) and [dompurify](https://github.com/cure53/DOMPurify) libraries.

## install
```
npm install react-sanitizer-parser
```
```
yarn add react-sanitizer-parser
```

## Usage
```tsx
import ReactSanitizerParser from "react-sanitizer-parser";

const Example = () => {
const dirty = `



React Sanitizer Parser


`;

return (
{dirty}
);
}
```

### htmlParserOptions & sanitizerConfig
- [html-react-parser Options](https://github.com/remarkablemark/html-react-parser#usage)
- [DOMPurify Config](https://github.com/cure53/DOMPurify#can-i-configure-dompurify)

```tsx
import ReactSanitizerParser from "react-sanitizer-parser";

const Example = () => {
const dirty = `



React Sanitizer Parser


`;

return (

{dirty}

);
}
```

### parse, DOMPurify
If you need to, you can use the `parse` method of html-react-parser and DOMPurify's `DOMPurify` directly.

```tsx
import ReactSanitizerParser, { parse, DOMPurify } from "react-sanitizer-parser";

function App() {
console.log(DOMPurify.sanitize("")); //
return (
<>
{parse("

React
")}
{`
React
`}
>
);
}
```