🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

html-converter-react

Advanced tools

Socket logo

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.

2.0.0
latest
Version published
Weekly downloads
36
-51.35%
Maintainers
1
Weekly downloads
 
Created

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}

FAQs

Package last updated on 02 Feb 2023

Did you know?

Socket

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