Also depending on the jQuery code used in the page you can get Sizzle attributes left in the saved html e.g.
What is the best way to clean this HTML on paste / during editing (clear formatting tool) / on save ?
We want to save just the structural formatting (H1-6/UL/OL/LI/STRONG/EM/A/IMG) with no styling (having removed the font/size/colour tools)
10 Answers, 1 is accepted
The Sizzle attributes should not be included at any time in the DOM. Please list the steps required to get them in the editor content.
Regarding the full format cleaning, you can post-process the editor content, removing the style attributes (whenever you get the editor value). The most robust way to do so is through HTML parsing (rather than regex matching), for example $(editor.value()).find("[style]").removeAttr("style").html();Regards,
I have now got my Clean Format command working which does a depth first parse of the DOM cleaning each node as it comes back up the tree:
and can call it when a user pastes content into the editor as follows:
I have since seen there is a list of 'Cleaners' that you run internally when pasting content so I tried writing my own cleaner instead of having to handle the paste event for each editor but am not sure how to register the cleaner ? Also do the cleaners get run prior to the paste event being called ?
Any suggestions would be appreciated ...
See the following jsBin for an example on how to register the cleaner. The key takeaway is the line
This functionality is not documented, as we have not many requests for custom cleaners; if such need arises, we will introduce a public API to do this. I don't expect much breaking changes for this code, but please keep in mind that it is not official.All the best,
I am testing with the latest internal build (2013.2.912) and am wondering if there has been any further development (additions) on this with regard to the built in cleaner. I am attempting to accomplish the same thing in this post (clean style attributes from html tags).
Is there a better way to do this now or is the provided example still the best way to accomplish this?
Thank you for any info you can provide.
There has been no further development with this regard. You can use the code shown in the jsbin demo.Regards,
I'm looking for something quite what you are describing here. A paste-handler that strips anything but the structural formatting and if possible a custom button that does the same task. How did your final solution end up? Would it be possible for you to share the actual cleaning code (the cleanNode function)?
Here is what I am currently using - please share any updates/improvements or comments back here :-)
This is a text with a blue word.
- and "blue" is marked blue, then effectively the space between blue and word will be removed as well when pasting.
Not a big issue, I just removed the last line in the clean method. But thanks a million - this is a great help.
Another issue is that I cant seem to add a text-only button the way you create the clean button. I end up with a button with a "random" portion of the icon sprite as background - not a regular text-based button. But then again, the users doesn't need that, so I've skipped it :o) None the less - I would like to know how its done, should you know it.