I've looked at bug reports (both here and on the FCKeditor site), searched the FCKeditor documentation, and tried every combination of configurations that I thought might help, but I'm still running into this simple error--

When a member edits a node with FCKeditor enabled that they had previously authored without using FCKeditor (just the plain textarea box), all linebreaks are removed. The paragraphs run into each other.

And clicking "Switch to plain text editor" is not an effective workaround.

I'm using the FCKeditor 5.x-2.1 module with the FCKeditor 2.6 RC1 library and Drupal 5.7.

Any idea how to solve this?

CommentFileSizeAuthor
#23 ermannob_body_formatter.zip1.26 KBermannob

Comments

physcied’s picture

I got the same results with FCKeditor_2.6rc, FCKeditor-6.x-1.1 module and Drupal 6.1.

wwalc’s picture

The problems is in the way how did you configure your input filters.
Before you enabled FCKeditor, you probably had Line break converter enabled (http://drupal.fckeditor.net/filters).

Now you're trying to edit the same content with Line break converter disabled, thus your linebreaks are removed.

Possible workarounds:
- enable Line break converter (not recommended)
- start with FCKeditor disabled by default, replace all new line characters manually with <br> tag, use toggle to switch to WYSIWYG mode

It would be probably a good idea to provide a tool to do this automatically.

wwalc’s picture

Or even better solution: create new input format with Line break converter enabled.
Use it just for old articles.

physcied’s picture

Thank you. :-)

wwalc’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

BakerQ’s picture

Version: 5.x-2.1 » 6.x-1.2-1

I've got a bit more elegant solution which helped me out. The problem with creating a new filter for all the old content is that if a novice user goes back to edit their old content they will be confused by either the lack of a fancy editor or the lack of newlines. I created this PHP script and ran it to clense the node content and comments, then turned off the New Line filter. FCK was happy as a clam:

This was tested on a 6.2 Drupal Installation.... which was originally a D5.7 install that had had its content imported from a WP2.3 site... Anyway, the script basically looks through your node_revisions and comments tables and replaces:

</p><br><p> with </p><p >
\n\r with <br />

It can quickly be adapted to suit whatever newline combo your site is using. If I weren't in the middle of upgrading a site I'd have made the script a bit fancier by putting the ereg_replace statements into a function of their own so that identical cleaning occurs on both the node and comment level - for now I guess I leave that as an exercise to the user. :-) Good luck!

*** EDIT ***
Just found out that the code I posted had a couple shortcomings including one syntax error (damn last minute edits!)... but mostly it never updated the teaser as well. Apparently (at least with D6) and differences between the teaser and the main body of a node tells Drupal to display both. Lead to a situation where everything looked fine until you edited an old post and saved it, at which point the content appeared twice. So, anyway, that's fixed and I went ahead and threw together a clean() function to make sure that the same changes occur to all strings.

Just so it's clear, this PHP code gets put into its own file on your server and then gets called as a page - I guess it could work as an actual Drupal page or block via the PHP filter... that's just not how I'd do it. Edit the four variables up to match your server config and you're golden. (Maybe the next time I edit this I'll design it to go inside an actual Drupal PHP node so that it can pull the information automagically)....

Good luck!


// USED TO REMOVE NEW LINES FROM DRUPAL CONTENT IMPORTED FROM WORDPRESS.
// AFTER RUNNING THIS, TURN OFF THE NEW LINE FILTER AND ENABLE FCKEDITOR.


$server = "server";
$database_name = "database_name";
$username = "username";
$password = "password";



function clean($body) {
        // The following equals:    </p>\n\r<p >
        $pbrp__tags = chr(60) . chr(47) . chr(112) . chr(62) . chr(13) . chr(10) . chr(60) . chr(112) . chr(32) . chr(62);
        // The following equals:    </p>\n\r<p>
        $pbrp_tags = chr(60) . chr(47) . chr(112) . chr(62) . chr(13) . chr(10) . chr(60) . chr(112) . chr(62);
        $p_tags = "</p><p >";
        $newline  = chr(13) . chr(10);
        $br_tag = "<br />";

        $body = ereg_replace($pbrp_tags, $p_tags, $body);
        $body = ereg_replace($pbrp__tags, $p_tags, $body);
        $body = ereg_replace($newline, $br_tag, $body);
        return($body);
}


$g_link = mysql_connect($server, $username, $password) or die('Could not connect to server.' );
mysql_select_db($database_name, $g_link) or die("Could not select database: $database_name.");
echo("Connected successfully<br>\n");

$query = "select nid, title, teaser, body  from node_revisions";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
        $nid = $row['nid'];
        $title  = $row['title'];
        $teaser = $row['teaser'];
        $body = $row['body'];
        echo("Found $nid: $title... ");
        $body = clean($body);
        $teaser = clean($teaser);
        $body = addslashes($body);
        $teaser = addslashes($teaser);
        $query = "update node_revisions set body=\"$body\", teaser=\"$teaser\" where nid=\"$nid\";";
        mysql_query($query);
        if (mysql_error()) {
                echo("FAILURE: $query<br>Error: " . mysql_errno() . " " . mysql_error() . "<hr>");
                die();
        } else {
                echo("Done.<br/>");
        }
}

$query = "select cid, comment from comments";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
        $pattern  = chr(13) . chr(10);
        $cid = $row['cid'];
        $body = $row['comment'];
        echo("Found comment $cid...");
        $body = clean($body);
        $body = addslashes($body);
        $query = "update comments set comment=\"$body\" where cid=\"$cid\";";
        mysql_query($query);
        if (mysql_error()) {
                echo("FAILURE: $query<br><b>Error: " . mysql_errno() . " " . mysql_error() . "<hr>");
                die();
        } else {
                echo("Done.<br/>");
        }
}
mysql_close($g_link);
Flimm’s picture

Status: Closed (fixed) » Active

The module could easily be patched so that this wouldn't even be an issue any more. It could add line breaks to the html output, and it would then work.
Instead of outputting:
<p>first</p><p>second</p>
The module could have generated:

<p>first</p>
<p>second</p>

Making this issue a non-issue.
It almost makes line breaks in just plain text mode active, some users prefer plain text mode.

wwalc’s picture

Status: Active » Fixed

@Flimm - I guess you're talking about broken output formatting, take a look at #318540: FormatOutput doesn't format properly properly.
Should be available tomorrow as a dev release, remember to clear browser's cache after upgrading.

merilainen’s picture

I think the original problem was that there are no p-tags in older posts which have been created with "line break converter" disabled. I don't know if FCKeditor can see if the node has these /n line changes which this script removes.

merilainen’s picture

I cannot get this to work. I copied this to fix_line_changes.php, copied it to Drupal root and then called example.com/drupal/fix_line_changes.php. I get a listing of many nodes with ...done at the end, but then looking at the database, nothing is different. All content has just normal line changes (cr and lf) which should have been replaced with <br />-tag.

I have Drupal 5.11 installed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

geerlingguy’s picture

If I have a database with some nodes that have already been edited using FCKEditor (and cleaned up manually) in addition to some nodes that are still unchanged, would this only change the non-edited ones, leaving the now-cleaned-up FCKEditor nodes intact?

akaserer’s picture

on http://drupal.fckeditor.net/troubleshooting#8 i can find the recommendation:

Possible workarounds:

* Enable Line break converter (not recommended).

why should i disable line-break converter if i use fckeditor???

drupalfan2’s picture

When a member edits a node with FCKeditor enabled that they had previously authored without using FCKeditor (just the plain textarea box), all linebreaks are removed. The paragraphs run into each other.

This problem already exists.
Can you solve it? It es very important and many users have this problem.

atuline’s picture

Ditto here:

I am using Drupal 6.16, have installed WYSIWYG 6.X-2.1 in the sites/all/modules directory and CKEditor 3.2 in the sites/all/libraries directory.

When creating an article and toggling between Disable rich-text and Enable rich-text, CK Editor 3.2 will strip the linefeeds and smush the text together when using Firefox 3.6.3.

  • I have tried this with both the ‘Line break converter’ Input Filter enabled AND disabled. (now disabled)
  • I have also tried this with WYSIWYG’s ‘Preformatted’ Cleanup Output enabled as well as disabled. (now enabled)
  • I have also tried this with WYSIWYG’s ‘Remove linebreaks’ Cleanup Output enabled as well as disabled. (now disabled)

I flush the Drupal and Firefox 3.6 cache after each change. I have also disabled all caching on the Drupal performance page.

Oh, and http://drupal.ckeditor.com/troubleshooting?page=3#8 didn't really seem to resolve the issue.

Jorrit’s picture

From what page have you downloaded the module?

atuline’s picture

Jorrit’s picture

I don't know how you ended up at this issue tracker. This issue tracker is for the FCKeditor module. Not the CKeditor module (http://drupal.org/project/ckeditor) nor the WYSIWYG module (http://drupal.org/project/wysiwyg).

gpk’s picture

The original problem is solved in FCKeditor module 6.x-2.1 with a new option "Automatically detect and convert plain text:" under Cleanup and output in each profile's settings. See #575626: Activating Fckeditor breaks existing node formatting.

geerlingguy’s picture

I'm guessing this also works for CKEditor, then? I've been using #513998: Plugin to convert p- and br-tags to newlines for the time being.

gpk’s picture

Yes the option is also in the CKeditor module, but AFAIK it's not in Wysiwyg module so I imagine you still need #513998: Plugin to convert p- and br-tags to newlines.

ermannob’s picture

StatusFileSize
new1.26 KB

Hi,
I took BakerQ's code and made a tiny module that implements an action to be used with Views Bulk Operations.
My action cleans body and teaser and then performs a node_save().

Instructions are quite simple:
-install my module
-install Views Bulk Operations
-edit VBO's view to include the action "Fix new lines formatting in node body nad teaser (ermannob_body_formatter_action)"
-select the nodes you want to modify
-run the bulk operation.

Please note that my action expects you still have "Full HTML" Input format at number 2.

EDIT: sorry for my typo "nad"... :-P

pabloid’s picture

Thanks BakerQ for your script!

but be aware that nid is not the primary key in node_revisions, better to use vid field.

Here part of the update code:

$query = "select vid, title, teaser, body  from node_revisions";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
        $vid = $row['vid'];
        $title  = $row['title'];
        $teaser = $row['teaser'];
        $body = $row['body'];
        echo("Found $nid: $title... ");
        $body = clean($body);
        $teaser = clean($teaser);
        $body = addslashes($body);
        $teaser = addslashes($teaser);
        $query = "update node_revisions set body=\"$body\", teaser=\"$teaser\" where vid=\"$vid\";";
        mysql_query($query);
        if (mysql_error()) {
                echo("FAILURE: $query<br>Error: " . mysql_errno() . " " . mysql_error() . "<hr>");
                die();
        } else {
                echo("Done.<br/>");
        }
}
LouisDRosa’s picture

What is the best way to determine your newline combo in your text area ? So you can change the code to handle
differnt newline combo's ?

Louis

Anyway, the script basically looks through your node_revisions and comments tables and replaces:


with

\n\r with

It can quickly be adapted to suit whatever newline combo your site is using

What is the best way to determine your newline combo