I'm using CKeditor 4.3 for editing Smarty templates with [[ and ]] delimiters. I started having trouble with it rearranging the source and generally breaking things, and found that others have run into this too, with various workarounds suggested. I'm also trying to use the placeholder plugin (the new widget version), but it's useless because of these problems.
I've set protectedSource to this:
CKEDITOR.config.protectedSource.push(/\[\[[^\]]*?\]\]/g);
Here's an example document:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>[[mytag]]</title> [[mytag]] </head> <body> [[mytag]] </body> </html>
Without protectedSource, that turns into this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>[[mytag]]</title> </head> <body>[[mytag]] [[mytag]]</body> </html>
Notice that it's moved one of the tags from the head into the body.
With protectedSource:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title><!--{cke_protected}%5B%5Bmytag%5D%5D--></title> [[mytag]] </head> <body>[[mytag]]</body> </html>
This time it left the head tag in place, but filtered the title one.
This post says:
Protected source means that <code> will be replaced by a comment when loading data to the editor and then back to <code> when getting data.
I wish that was true... The ...{cke_protected}... change remains when the form is submitted. Given that the placeholder in the title tag matches the protectedSource pattern, and it works correctly in the other locations, I can only assume this is a bug.
All that said, protectedSource isn't very helpful since it hides matched elements. I want them to remain editable, but have them exempted from filtering.
If I use the placeholder plugin (which I can use with defaults as it matches my tag pattern), it turns all my tags into widgets as expected, but it doesn't let them work everywhere.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title><span tabindex="-1" contenteditable="false" data-cke-widget-wrapper="1" data-cke-filter="off" class="cke_widget_wrapper cke_widget_new cke_widget_inline" data-cke-display-name="placeholder"><span class="cke_placeholder" data-cke-widget-keep-attr="0" data-widget="placeholder">[[mytag]]</span></span></title> </head> <body>[[mytag]] [[mytag]]</body> </html>
So again it moves a tag into the body, reformats the title tag contents, and leaves it there on form submission. I don't see why placeholders in the title tag are handled so differently. In some other cases I've had it remove a tag from the head and wrap it in a p tag before moving it into the body, but I think I solved that by turning off autoParagraph in config.
I really don't want any filtering - all of my content is filtered with htmlpurifier on submission.
Is there any way to make this work?
Incidentally your forum spam checker is apparently dead, and when it kicks you back to the post editor after failing to make the post, some markup has been stripped - code sections lose their background.