Socket
Socket
Sign inDemoInstall

html-converter-react

Package Overview
Dependencies
130
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    html-converter-react

**html-converter-react** is an isomorphic utility function that provides easy way to convert your string into a safely sanitized html. It's built on top of dompurify and it's made to work with react.


Version published
Weekly downloads
89
decreased by-2.2%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

html-converter-react

html-converter-react is an isomorphic utility function that provides easy way to convert your string into a safely sanitized html. It's built on top of dompurify and it's made to work with react.

Works both on server side and client side (CSR/SSR). You can use Next.js/Gatsby.js/CRA

Full documentation on: https://github.com/Blagoj5/html-converter#readme

Installation
npm install html-converter-react
yarn add html-converter-react
Usage
import { htmlConverterReact } from 'html-converter-react';

const text = '<p>Paragraph</p>';
const textEls = '<p>Paragraph</p><p>Second paragraph</p>';
const dangerousText = '<p>Paragraph<script></script></p>';

const App = () => {
  return (
    <div>
      <h1>My App</h1>
      {htmlConverterReact(text)}
      {htmlConverterReact(textEls)}
      {htmlConverterReact(dangerousText)}
    </div>
  );
};

Explanation:

  • htmlConverterReact(text) - returns JSX.Element paragraph
  • htmlConverterReact(textEls) - returns JSX.Element paragraph with sanitized data: <p>Paragraph</p> (without script tag)
  • htmlConverterReact(dangerousText) - returns JSX.Element[] array of jsx elements, two paragraphs
Options
OptionDescriptionDefault
strThe string to be sanitized and parsed into a html
dompurifyConfigDompurify optionsundefined
htmlParserConfigHTMLReactParserOptions{trim: true}

Keywords

FAQs

Last updated on 02 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc