# HTML to React This is a library that renders HTML strings into [React](https://facebook.github.io/react/) components without using `dangerouslySetInnerHTML`. Converts standard HTML elements, attributes and inline styles into their React equivalents and provides a simple way to modify and replace the content. This library is a hard fork of https://github.com/peternewnham/react-html-parser. It has some improvements and is converted to typescript. [![npm](https://img.shields.io/npm/v/@hedgedoc/html-to-react.svg)](https://www.npmjs.com/package/@hedgedoc/html-to-react) [![Downloads](https://img.shields.io/npm/dw/@hedgedoc/html-to-react.svg)](https://www.npmjs.com/package/@hedgedoc/html-to-react) ## Install ```bash npm install @hedgedoc/html-to-react # or yarn add @hedgedoc/html-to-react ``` ## Usage ```typescript import React from 'react'; import { convertHtmlToReact } from '@hedgedoc/html-to-react'; class HtmlComponent extends React.Component { render() { const html = '
Example HTML string
'; return
{ convertHtmlToReact(html) }
; } } ``` ## Security It is important to understand that this library should not be used as a direct replacement for using properly sanitized HTML and that it only provides the same level of protection that React does which does not provide 100% protection. All HTML should be properly sanitized using a dedicated sanitisation library (such as [dompurify](https://www.npmjs.com/package/dompurify) for node/js) before being passed to this library to ensure that you are fully protected from [malicious injections](https://en.wikipedia.org/wiki/Cross-site_scripting). ### What doesn't React protect me from? Whilst React has a [certain level of protection to injection attacks](https://reactjs.org/docs/introducing-jsx.html#jsx-prevents-injection-attacks) built into it, it doesn't cover everything, for example: * xss via iframe src: `