Line breaks collapsed when a pre-FCKeditor document is edited with FCKeditor
alakon - March 30, 2008 - 23:36
| Project: | FCKeditor - WYSIWYG HTML editor |
| Version: | 6.x-1.2-1 |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
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?

#1
I got the same results with FCKeditor_2.6rc, FCKeditor-6.x-1.1 module and Drupal 6.1.
#2
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 modeIt would be probably a good idea to provide a tool to do this automatically.
#3
Or even better solution: create new input format with Line break converter enabled.
Use it just for old articles.
#4
Thank you. :-)
#5
#6
Automatically closed -- issue fixed for two weeks with no activity.
#7
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!
<?php
// 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);
?>
#8
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.
#9
@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.
#10
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.
#11
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.
#12
Automatically closed -- issue fixed for two weeks with no activity.
#13
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?