How to avoid WebKit contentEditable copy-paste resulting in unwanted CSS? How to avoid WebKit contentEditable copy-paste resulting in unwanted CSS? google-chrome google-chrome

How to avoid WebKit contentEditable copy-paste resulting in unwanted CSS?


I had the same problem, plus the problem that every browser creates different HTML. So I wrote a JavaScript port of the Sanitize library: Sanitize.js

Sanitize.js is a whitelist-based HTML sanitizer written in JavaScript. Given a list of acceptable elements and attributes, Sanitize.js will remove all unacceptable HTML from a DOM node.

Have a look at the example, where I capture the paste event and process the HTML afterwards.