When pasting HTML to FCKeditor, it seems that ampersands are properly escaped to & but this only applies to normal text. If the content to be pasted contains, for example, JavaScript within a script tag, the ampersands in the JavaScript remain as-is. While this is basically OK (to ensure the JavaScript in question actually works), the resulting document fails XHTML validation.
I'm having a little trouble figuring out the "proper" way around this functionality. Is there a simple way to either strip all scripts from the pasted content or process them so that the content of script tags is wrapped in comments (<!-- and -->) which would still keep the JavaScript executable but also result in valid XHTML?
I'm having a little trouble figuring out the "proper" way around this functionality. Is there a simple way to either strip all scripts from the pasted content or process them so that the content of script tags is wrapped in comments (<!-- and -->) which would still keep the JavaScript executable but also result in valid XHTML?
Re: FCKeditor 2.6 and outputting valid XHTML
Re: FCKeditor 2.6 and outputting valid XHTML
<html>
<body>
<p>Text & stuff</p>
<script>if (true && true) {}</script>
</body>
</html>
...open it in a browser, select all content, copy it to the clipboard and then paste it to FCKeditor, we end up with...
<p>Text & stuff</p>
<script type="text/javascript">if (true && true) {}</script>
So it's probably working as intended but the unescaped ampersands in the script aren't XHTML compliant. It's a small issue but as we're trying to insert content procuded with FCKeditor to an XML file, this also means the XML file becomes invalid. It would be great if the output would either be...
<p>Text & stuff</p>
<script type="text/javascript"><!--if (true && true) {}--></script>
...or - even better - that FCKeditor could somehow be configured to strip script tags altogether. After all, they're usually just unwanted extras that just happen to tag along when copy/pasting content from web pages.
Re: FCKeditor 2.6 and outputting valid XHTML
That would not be well-formed XHTML, though, as sequences "--", which can occur in JavaScript, are not valid in XML comments. JavaScript and CSS are supposed to be enclosed in CDATA sections, like this:
Re: FCKeditor 2.6 and outputting valid XHTML
Ah, thanks - a very good point that I overlooked! Using ordinary comments could certainly still manage to render the outgoing document invalid.
Anyway, I take it there is no simple way (say, in fckconfig.js) to either wrap script contents within a CDATA section or to strip the scripts out altogether? After all, when copy/pasting text from HTML pages, the scripts possibly coming along most likely wouldn't work out of their original context, anyway.
I suppose writing a little plugin that simply fires on script tags and replaces them with nothing would be the most feasible way to get rid of them altogether? A bit of an overkill and haven't yet sampled if pasted data is passed via registered plugins before ending up in the editor but I suppose that's the way FCKeditor does it?