Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance
What are you trying to do?
I created a react app using the CRA and sanitize the HTML which has a style attribute and allowed the style attribute by setting the allowedAttributes using the following code.
import sanitizeHtml from "sanitize-html";
export default function App() {
const html = `<p style="background-color: green;">Welcome to the World</p>`;
const element = sanitizeHtml(html, {
allowedAttributes: {
"*": ["style"]
}
});
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<div dangerouslySetInnerHTML={{ __html: element }} />
</div>
);
}
But after the clean up of the HTML using the sanitizeHtml, style attribute is removed but this is not expected.
Details
Version of Node.js:
v18.14.2
Server Operating System:
Ubuntu 20.04.5 LTS
Additional context:
I create a app using the create-react-app.
package.json
What are you trying to do? I created a react app using the CRA and sanitize the HTML which has a style attribute and allowed the style attribute by setting the
allowedAttributes
using the following code.But after the clean up of the HTML using the sanitizeHtml, style attribute is removed but this is not expected.
Details
Version of Node.js: v18.14.2
Server Operating System: Ubuntu 20.04.5 LTS Additional context: I create a app using the
create-react-app
. package.json