I am using the FCKeditor to edit html templates that contain NVelocity. I am getting errors from NVelocity because the FCKeditor is removing carriage returns which NVelocity apparently uses to terminate a statement.
I found this support ticket(http://dev.fckeditor.net/ticket/2608) with a user having a similar issue where the FCKeditor is removing carriage returns which is causing Javascript to fail. This ticket refers to the Java version. I am using the .NET version of the FCKeditor and I have looked at the FCKeditor .NET source and do not see any references to carriage returns (ie. \r\n). I do see numerous references to carriage returns within the FCKeditor Javascript sourcecode and I have attempted to remove these without any success.
Does anyone know how I can prevent the FCKeditor from removing carriage returns?
Wed, 07/01/2009 - 01:02
#1
Re: How to prevent FCKeditor from removing carriage returns?
I tried but failed to recreate it, my \r\n's are all kept in place
Re: How to prevent FCKeditor from removing carriage returns?
Thanks a lot for taking the time to reply.
To reproduce it, in source view, type something and then hit the enter key to do a carriage return, then type something again. Then change to the WYSIWYG view, then change back to the source view and the carriage returns will be removed.
For example, if I type this in the source view:
Then change to the WYSIWYG view then back to source view it changes to:
There must be some configuration setting that I am missing.
In the fckconfig.js file I tried changing FCKConfig.FormatSource and FCKConfig.FormatOutput to false with no luck.
Re: How to prevent FCKeditor from removing carriage returns?
FCK Editor replaces any occurence of ...
<BR>
<BR/>
<BR clear="all">
etc
... with this P tag combo...
<p> </p>
It appears the replacement is happening on the read, not on the write. We can change the html to include the BR tag and it will go into the database, but upon retrieving the html to edit, FCK will replace all BR tags with the P.
I am trying to do some image layouts with the editor and br clear all is very important to not replace.
Also, removing all the chr(13) is frustrating. Makes the html very hard to read.
Re: How to prevent FCKeditor from removing carriage returns?
Hi
Sorry for the long time to reply, was on the road all yesterday.
First thing, \n\r is ONLY for formatting the source, it will make no difference in the actual layout unless it's in a <pre> tag, so I would not worry to much about it. Set the FCKConfig.FormatSource and FCKConfig.FormatOutput both to true and let it format it for you.
Change the FCKConfig.EnterMode = 'br' ; setting to be 'br' instead of 'p', that will fix both your problems, except that it might not be XHTML compliant (as far as I know). Have a look at http://en.wikipedia.org/wiki/XHTML if you want to read about compliance, I have not done this
Hope this solves it for you guys/gals
Re: How to prevent FCKeditor from removing carriage returns?
Thanks for trying to help. From what I have read removing carriage returns is a standard of W3C and so the FCKeditor does this on purpose so I am not sure how this is not happening for you unless you modified the code or you changed some configuration setting. I also tested in a completely new environment using the samples and it has the same behavior.
I know the carriage return is only in the source and that is the problem. FCKeditor removes it from the source. All I want is for the FCKeditor to not touch the source and leave it as is. You would think there would be a setting such as setting FCKConfig.FormatSource = false; that would do this but this doesn't work, it still removes carriage returns.
For anyone else that is having this problem, I was able to fix this by modifying the FCKeditor Javascript:
In these files:
fckeditor\editor\js\fckeditorcode_gecko.js
fckeditor\editor\js\fckeditorcode_iejs
In the current version (2.6.4.1) on line 26 if you remove replace operations such as: this.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,'');
You can also do a search for '\n' and '\r'
If you remove all ."replace(...);" it will stop the FCKeditor from removing carriage returns.
If anyone else knows of a more elegant way to do this such as a configuration setting, please let me know.
Re: How to prevent FCKeditor from removing carriage returns?
I have found that if you put a <p> tag directly before <br clear="all" /> the <br clear="all" /> tag does not get removed and works as expected. So a sequence like </p><br clear="all" /><p> gets replaced by <p>&npsb</p> but </p><p><br clear="all" /> does not. I have no real idea why and found this by accident. For formatting graphics this is such a basic requirement I think a button on the tool bar to insert this is very important and should not be very difficult to do (though beyond my capability to do it with confidence ). Now I only need to find out how to keep the raw html text with some formatting ie at least carriage returns so that switching from the WYSIWYG editor doesn't just give a difficult to search amorphous block. (TinyMCE seems better in this respect.) and find a spellchecker for CK editor and all my needs are fulfilled
Hope this helps.
Re: How to prevent FCKeditor from removing carriage returns?
Pretty simple too, just open up the file fckeditor/fckconfig.js.
Now navigate to around line 57, you will see FCKConfig.ProtectedSource.Add commands.
Now just add this in:
You can also do this for the IMG tag if you don't want it wrapped in the p tag.
You can protect any kind of code here, so if you have a custom language for your site, you can put it in here if you configure the regex correctly. For example, if you are using expression engine, you'd use this: