3 ms·
At domestika.com we've been developing a javascript XHTML purifier, for this purpose. It's based on the algorithm for parsing html, specified in the HTML5 draft
by bobfunk 18y ago
At domestika.com we've been developing a javascript XHTML purifier, for this purpose. It's based on the algorithm for parsing html, specified in the HTML5 draft, so it's a lot more powerful than the typical regular expression based solutions.
For our use we're only interested in a very small subset of XHTML. We use a rich text editor to let clients edit the contents of their web sites, and we don't want any tags included that could disrupt the design of the page. So only the most basic markup is allowed.
Should be easy to extend the script to take into account more of the elements specified in the HTML 5 draft, if anybody wants a more permissive purification...
Best of all, we just open-sourced the script.
Grab it from Github:
http://github.com/biilmann/javascript-xhtml-purifier http://github.com/biilmann/javascript-xhtml-purifier
Original anouncement (in Spanish):
http://domestika.org/foros/956-kode/hilos/73209-depuracion_de_xhtml_desde_javascript http://domestika.org/foros/956-kode/hilos/73209-depuracion_d...
- __FILE__ 18y agoIs there any way to prevent pasting rich text? I can strip out the tag soup, but it would be great to have the option to only allow pasting plain text.
- bobfunk 18y agoNopes - you have to cleanup the result of the paste. As soon as you enable designmode on a document, every paste coming from something like Word will be transformed into delicious tag soup for you to deal with. No way to just disable that 'feature'.