On my site, I have a ton of legacy content, some from Joomla's JCEditor, some with semantic html markup, and some without any markup at all.
I need to preserve line breaks when editing, but currently CKEditor mashes all the content together, and instead of converting double line breaks as a
or
, they are all removed, and content runs together.
For the WYSIWYG module, there is a plugin/patch that fixes this problem: #513998: Plugin to convert p- and br-tags to newlines, but I haven't seen anything similar for FCK/CKEditor. Do you know if you could incorporate this, perhaps as an option in the "Cleanup and Output" section of the CKEditor settings?
It would be helpful on more than one site I run... and it would allow me to use this module (rather than WYSIWYG) on two huge new sites I'm working on.
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | convert-newlines.patch | 1.62 KB | jcisio |
| #14 | 685146-line-break-converter.patch | 3.26 KB | wwalc |
Comments
Comment #1
mcrittenden commentedSub. I need this feature as well.
Comment #2
mephir commentedMaybe it could help http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Output_Formatting . You should add on the end of ckeditor.config.js something like below, for an example:
Comment #3
geerlingguy commentedPerhaps... I don't have time to test before the site launch, so I'm going to have to defer to someone else for now :(
Comment #4
bradezone commentedIndeed one could call this "a bummer" or "unfortunate" since you can set about ruining your content in major ways if you install CKeditor module and edit any existing content. Good thing we have revisions turned on, but geez, isn't this a fundamental disaster of a problem? Why does CK want to condense everything, and not preserve those line breaks?
Comment #5
mcrittenden commentedChanging title...seems like what we need is to convert new lines to line breaks, not the other way around. I kind of wonder if the easiest method is just a quick nl2br() in hook_nodeapi() for $op == prepare? Thoughts on that? A bit of a hack, but nothing better comes to mind at the moment.
P.S. Hi Brade! Your post popped up in my recent issues!
Comment #6
bradezone commentedAhoy, crittenden!
BTW there is a very easy fix for this major issue. Simply set the "FormatSource" config option to false. This way you can keep "convert line breaks" on and not worry about your existing content getting messed up.
I did this in "config.js" which is part of the ckeditor download itself, so the file now looks like:
But there's probably a better place to put it for the purpose of fixing this module.
Comment #7
bradezone commentedHmmm, this may only work part of the time. Found a few pages where it still crumples the text together...
Comment #8
mephir commented@bradezone: yes, there are two better places, for an example ckeditor.config.js or in "Custom Javascript Configuration" on profile settings page in Advanced section.
One question. Why you use ckeditor and nl2br? It only help when you creating page without any editor.
Comment #9
mcrittenden commentedmephir: the problem is if you use CKEditor to edit pages that were created before CKEditor was installed. Drupal's default input formats convert new lines to br/p tags, so you don't have to manually enter <p> every time you want a new paragraph, you can just hit enter twice.
However, this conversion happens on node *view*, not on node *save*, so the p/br tags don't exist in the DB, they just appear when the content is being viewed. Therefore, they're not there when you edit the node. So if you install CK and then edit a node that was created before CK was installed, it doesn't convert those new lines to p tags on the edit form, and it squishes all the code together so that they don't get preserved (and therefore Drupal can't convert them to paragraphs like it did before CK was installed).
We're trying to figure out the best way to make CKEditor either convert them to p tags, or not squish the lines together (so Drupal will do the converting).
Comment #10
geerlingguy commentedI would prefer that CKEditor simply preserves the new lines, as Drupal core does... this way when an editor is turned off again, it won't add markup to otherwise un-marked-up content...
Comment #11
mcrittenden commentedRe: #10, that's what bradezone's solution attempts to accomplish in #6, but apparently it has problems (see #7).
Comment #12
TapSkill commentedI notice the lack of control over how the source code looks, is that what this issue topic is about?
Comment #13
wwalc commentedOk... let's forget for a while about controlling CKEditor output through dataProcessor.writer and focus on preserving line breaks / paragraphs.
There is no way to tell CKEditor to remember about white characters. CKEditor is a HTML editor and things like double line breaks in source code are ignored by browsers, so does CKEditor.
Anyway, I think we can handle that in CKEditor module. The problem is that having the following source:
after enabling CKEditor module and editing existing node, we want still to have in the final output something like:
I think we can deal with that in a similar way like we call security filters. I'm attaching a patch that should handle such situation.
In "Cleanup and output" section another configuration setting is added: "Line break converter". If you enable it, CKEditor will call the line break converter when editing existing nodes. It means that you will no longer have in the source code:
but the final result should look more similar to what you expect.
Please test it and let me know.
(just a note that I've made some little cleanup in the code so the patch does not look that nice, however it should )
Comment #14
wwalc commentedComment #15
wwalc commented(please apply the patch to the CVS version, 6--1 branch)
Comment #16
wwalc commentedHmm anyone? I'd like to put it into the next release (6.x-1.1), but needs to be sure first that this is exactly what you need.
Comment #17
geerlingguy commentedSorry - I'll take a look at it tomorrow, as time allows.
Comment #18
jcisio commentedI'd like to test, but after apply the patch, select Enable on the "Cleanup and output" section, enable the "Line break convertor" filter in my format (in fact, I didn't use this filter, the line break convertor is done by the HTML Purifier module). But nothing happens. When I view the html source (on the browser), I don't see br or p tags.
In the Security setup, I select the HTML Purifier filter, but it doesn't convert like the way it does when I view content.
I didn't look into the source code of ckeditor.module, but perhaps because each filter has an config attached to a format. Does the module miss it?
And why doesn't just list "Line break convertor" into the security filters list?
Comment #19
jcisio commentedOoops I didn't read the patch before applying it. What it does it not applying the filter, but add the config.FormatSource=true in CKEditor. That doesn't solve my problem, neither.
Comment #20
wwalc commented@jcisio - did you test the patch from comment #14? I'm asking because there is no "FormatSource" there.
It should work in exactly the same way as if the "Line break converter" was checked in the security filters list. It is not listed there because it is not a security filter (to avoid confusion).
Make sure you have enabled the "Line break converter'" in CKEditor profile after applying the patch.
Comment #21
jcisio commentedYes, I did test the patch #14. So I was right in #18. But it didn't work (I enable the line break converter in the used format and enable that in CKEditor Cleanup & output).
About #19: sorry I was too quick, I saw "p;div;pre;address;h1;h2;h3;h4;h5;h6" just above and think that's something about the editor settings themselves.
I will check it again right now.
Comment #22
jcisio commentedI doesn't work. In my comment, the format was "Simple HTML" with the following filters:
- HTML Purifier
- Line break converter (I added this to test)
- Nofollow list filter
Then in CKEditor I enable the "Line break converter:" option.
I add a comment with CKEditor turned off (click on "Switch to plain text editor"), add a few text, submit. Then edit, with CKEditor enable, now all text is in a single paragraph. In the HTML source, the value in
<textarea>tag is not format (that means no p or br tags).That is strange too, as I enable Autoparagraph in HTML Purifier, and it displays as expected, but not when edit with CKEditor.
Comment #23
anniewang commentedHi,
I was wondering if any progress has been made on this. I'm having a huge problem, having switched from markitup editor to CKEditor and now all of my line and paragraph breaks are gone!
Can someone please help and advise some way to solve the problem? It seems like none of the existing strategies are working very well? Or maybe they are, I just don't really understand the technical language. Please help!
Thank you in advance.
Comment #24
mcrittenden commentedThis is CNW since there's already a patch.
Comment #25
mcrittenden commentedPatch in #14 only halfway worked for me. It worked great on about 50% of nodes, and the other 50% it didn't do anything to. I spent some time trying to figure out why it would affect some and not others, with no luck. Sorry I can't help more.
Comment #26
dczepierga commentedComment #27
mcrittenden commentedHow is this fixed? Not saying it's not, but some explanation would be nice.
Comment #28
rrizia commentedHi,
I tried each of the above provided solution but could not get it fixed.
Anyone can please help.
Thanks in advance
Rizwana Rizia
Comment #29
jcisio commentedI was rethinking about this issue. Conversion of old contents could be hard when mixing different formats. It could be avoided by a simple converter script which applies the auto paragraph filter on old contents and save the formatted content instead of original content (without
<p> and <br>tags).However, we can do other thing on the client side. For most users who don't write comments or who don't need CKEditor, the editor can be disabled by default. However we need a plugin to convert newlines to
<p> or <br>when users enable the editor, or when users submit comment without enable the editor. In this case, no autoparagraph filter on the server side.Briefly, we need a plugin that converts
- when user click on "Switch to rich text editor" at the first time
- or, when the form is submitted and the editor is never enabled
Comment #30
jcisio commentedThis patch does the first thing in #29. I don't know how to do the second ("when the form is submitted and the editor is never enabled") properly.
This patch is for website with CKEditor disabled by default, but user can turn it on, even when there is some text in the textarea.
Comment #31
jcisio commentedThe last ideas went to a separate issue #1050118: Added better support for Line break converter. CKEditor is now able to load properly content where new line characters were used. Revert the category.
Comment #32
geerlingguy commentedAlso, please note that there's a new project that's an addon for the WYSIWYG project, that does just this (and works with CKEditor, as provided through WYSIWYG): WYSIWYG Force Linebreaks. I've been using it on a variety of sites, and it does exactly this.
Comment #33
andypostpatch #30 works by the right way
Suppose second issue should be renamed to "Convert when detach event released" also cares about possible conflicts with wysiwyg and others
Comment #34
jcisio commentedPlease discuss about that patch at #1050118: Added better support for Line break converter. CKEditor is now able to load properly content where new line characters were used where we consolidate our effort on it.
Comment #35
dczepierga commentedI think we could closed this issue, as i see everything was said and fixed.
If i'm wrong pls correct me :)
Greetings