nwon-html-to-react
v1.3.2
Published
Tools for parsing HTML to React components and sanitizing HML
Readme
NWON-html-to-react
This packages provides you with a complete tooling for turning HTML into react components. It enables you to define exactly which tags you want to replace with what component.
Main exports
For replacing HTML with react components we expose:
replaceHtmlWithComponent- A function that takes an HTML string and a map of components to react componentsreplaceEmojis- A function that replaces emojis in a string with stable counterparts
We also expose the following useful things for sanitizing HTML:
SanitizeHtml- A component that returns sanitized HTMLuseSanitizedHtml- A hook that returns sanitized HTMLsanitizeHtml- A function that returns sanitized HTML
Sanitizing is based on isomorphic-dompurify,
which uses DOMPurify in the browser and DOMPurify with jsdom on the server.
replaceHtmlWithComponent always sanitizes as well. All of them take
DOMPurify's options,
merged on top of the default USE_PROFILES: { html: true }.
On the server isomorphic-dompurify needs Node ^22.22.2 || ^24.15.0 || >=26.
When bundling for the server (e.g. Next.js), keep jsdom external. Next.js
does that by default.
