I have found that the only way you can edit with tinymce a text originally created without tinymce and maintain the old formatting (namely respecting the old linebreaks, used by Drupal's linebreak converter filter) is to use these two settings:

Apply source formatting: FALSE
(This needs to be false, otherwise you will have both BR tags and linebreaks, which the linebreak converter will turn into additional BR tags)
Convert newlines to brs: TRUE
(This will turn your old linebreaks into BR tags; without this, they *will* get removed and you will have your entire text joined into one giant paragraph; this happens even if you have tinymce.module's Remove linebreaks set to false... at least it does to me... can that be right?)

Convert newlines to brs is not an option offered by tinymce.module, so I had to add it.

I'm sorry I'm not able to provide a proper patch, but these are the two simple additions to the code that one has to do (the lines marked with an + are the ones you need to add):

  $init['apply_source_formatting'] = $settings['apply_source_formatting'] ? $settings['apply_source_formatting'] : 'true';
+  $init['convert_newlines_to_brs'] = $settings['convert_newlines_to_brs'] ? $settings['convert_newlines_to_brs'] : 'false';
  $form['output']['apply_source_formatting'] = array(
     '#type' => 'select',
     '#title' => t('Apply source formatting'),
     '#default_value' => $edit->settings['apply_source_formatting'],
     '#options' => array('true' => 'true', 'false' => 'false'),
     '#description' => t('This option makes TinyMCE apply source formatting.  Set this to true for a cleaner HTML source.  Choose false to avoid conflicts with some filters.')
  );

+  $form['output']['convert_newlines_to_brs'] = array(
+     '#type' => 'select',
+     '#title' => t('Convert newlines to brs'),
+     '#default_value' => $edit->settings['convert_newlines_to_brs'],
+     '#options' => array('true' => 'true', 'false' => 'false'),
+     '#description' => t('If you set this option to true newline characters codes get converted in to br elements. This option is set to false by default.')
+  );

Thank you.

Comments

oriol_e9g’s picture

It's working but it's not a definitively solution for the problem.

TinyMCE it's not compatible with the Drupal's linebreak converter filter.

If you have a node created without tinymce and then enable the rich-text you cannot see the linebreaks created by the Drupal's linebreak converter filter.

This option will turn old linebreaks to brs and you will see correctly all line breaks in the tinymce editor, but then, if you disable the rich-text you will lost the linebreaks and will appear in the text the brs.

It would be better a solution that not change the original text when only enable and disable the rich-text.

ricmadeira’s picture

Thanks!

This option will turn old linebreaks to brs and you will see correctly all line breaks in the tinymce editor, but then, if you disable the rich-text you will lost the linebreaks and will appear in the text the brs.

Yeah, but the final appearance remains exactly the same, and at the end of the day that's what counts. If you only use the editor and don't turn it off, you'll never even know there was a change... which is better than the current state of things, where just by having the editor turned on your old text will change irreversibly if you save it.

Anyway, I too would prefer a more elegant solution, but I don't see it happening very easily (in terms of the complexity of what you would have to make the module do to assure compatibility with the linebreak converter filter) so I'm asking for this to be implemented now. The default setting does not change; it only gives people the option to reconfigure it themselves if they want.

ashtonium’s picture

Status: Reviewed & tested by the community » Needs review

You could also accomplish this without any modifications to the module by simply override the TinyMCE theme function:

  1. copy the entire "theme_tinymce_theme" function from the README.TXT file to your template.php in your theme folder and rename it to "phptemplate_tinymce_theme"
  2. add this line to the beginning of the function:
    $init['convert_newlines_to_brs'] = true;

Just my opinion, but as this seems more like a special case fix, I don't think it should be an option in the UI for the module. I'm not sure if there's any case other than what you described when people would want to enable this feature, and it seems like it may cause more problems than it fixes (from people enabling it out of curiosity and messing up their html)

If it does get added, the form's description text should probably be improved to indicate this it is for compatibility with nodes created without TinyMCE, and that "Apply Source Formatting" will need to be set to false.

xcorex’s picture

ashtonium,

Fatal error: Cannot redeclare theme_tinymce_theme() (previously declared in /home/domains/xxx.org/web/modules/tinymce/tinymce.module:297) in /home/domains/xxx.org/web/themes/garland/template.php on line 8

yched’s picture

read closer :
copy the entire "theme_tinymce_theme" function from the README.TXT file to your template.php in your theme folder and rename it to "phptemplate_tinymce_theme"

xcorex’s picture

doesnot work either. =/

ricmadeira’s picture

Just my opinion, but as this seems more like a special case fix, I don't think it should be an option in the UI for the module. I'm not sure if there's any case other than what you described when people would want to enable this feature, and it seems like it may cause more problems than it fixes (from people enabling it out of curiosity and messing up their html)

Well, that could be said of most of the "Cleanup and output" options too; it's not a module for the faint of heart, you have to enable Full HTML and all that. Plus it's a required workaround for sites where you have TinyMCE users editing non-TinyMCE posts, be they old or new, like Book pages.

Since the default option stays exactly the same, people mess with that at their own risk... and it's not like turning it on will break their entire site. It might mess a post create under different settings that they are editing, and it will do so only if they - after seeing the unwanted changes - hit the "publish" button.

sambtaylor’s picture

I come from the world of poetry, and we definitely need to be able to have single line breaks output. I have been going crazy trying to figure this out, and I get tired of hearing people say that there is practically no reason why people would need them. We need them all the time, line by line.

ashtonium’s picture

Just a note in response to sambtaylor: if you're using TinyMCE normally, you can hold SHIFT and press ENTER to insert a single line break: <br /> instead of the paragraph break: </p> <p> that you get normally.

It's very frustrating because it's not really documented very well, and it's something that I have to make sure the show my clients when I install TinyMCE for them. Personally, I prefer the "press ENTER once to get a line break and press ENTER a second time to turn the line break into a paragraph break" method that other WYSIWYG editors use as it's much more intuitive.

sambtaylor’s picture

This really isn't the solution that I want (as I would like to have the user not have to take this extra step), BUT I CAN"T EVEN GET IT TO DO THIS. On my install of tinymce, shit and enter still makes a paragraph break.

scedwar’s picture

Same problem, but looking for an elegant solution! Anyone?

nicknickoli’s picture

I was wondering if anyone has looked at using Drupal's filter. I'm not sure the best way to que this up though. Adding a 'Add Breaks' link under TinyMCE would reload the page. Anything else seems more complicated than just running all the nodes through this with some php!

  function mymodule_form_alter($form_id, &$form) 
{
if(strpos($_GET['q'], 'addbreaks') && !empty($form['body_filter']['body']['#default_value'])) {
	$form['body_filter']['body']['#default_value'] = filter_filter('process', 2, -1, $form['body_filter']['body']['#default_value']);
} } 
pomliane’s picture

Status: Needs review » Closed (won't fix)

This version of TinyMCE is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.

This issue has been automagically closed by a script.