I'm testing TinyMCE as an option for those of my users who are intimidated by HTML. So far it's working well, except for one thing: the HTML generated by TinyMCE is all on one line. Now, this has no effect on what the site looks like, but it does have an effect on the site admin (me) who might want to edit the HTML after the user has submitted it. E.g., TinyMCE makes this:

<h3>My favorite foods</h3><ul><li>tomatoes</li><li>chocolate</li><li>strawberries</li></ul>

I want it to make this:

<h3>My favorite foods</h3>
<ul>
<li>tomatoes</li>
<li>chocolate</li>
<li>strawberries</li>
</ul>

I tried the HTML Tidy module; however this doesn't quite do what I'm looking for--while it provides a *filter* that is applied when the node content is served, it doesn't actually do anything to the user's original input. What I'm looking for is something I can use to automatically make the source of the node legible for advanced users.

(Note: this is not a Filtered HTML issue as I've seen in many other posts. I don't want or care about <p> tags being inserted, I just want the \n character added in the appropriate places to the actual submission. HTML Tidy does this when the node is accessed (along with indentation), but does not do anything for the actual source I'm editing).

Anyone have any suggestions as to how I could accomplish this? Short of writing my own parser to stick in those line breaks.

Comments

xjm’s picture

Digging through the TinyMCE docs, I found the remove_linebreaks config option:
http://tinymce.moxiecode.com/tinymce/docs/option_remove_linebreaks.html

Anyone have any ideas as to how I might go about getting Drupal to set this config option for TinyMCE? I have no idea whether it will do the trick, but it seems worth a shot.

xjm’s picture

Well, adding remove_linebreaks as a configuration option in tinymce.module helps halfway, in that it does not eat the linebreaks from existing HTML documents. However, new nodes created with TinyMCE still do not have any line breaks in the source (nor does content added to existing nodes).

Back to the drawing board. Any suggestions as to how I can control line breaks in the TinyMCE output? Ideally, a line break would be added to the TinyMCE-generated HTML each time the user presses enter in the TinyMCE editor box. A less perfect option that would still get the job done would be some sort of formatting cleanup utility (non-filter) that would automatically add linebreaks in good places (like HTML Tidy does), at least after the closing tags of block elements and so forth.

xjm’s picture

I found the solution on the TinyMCE forums:
http://tinymce.moxiecode.com/punbb/viewtopic.php?id=2878

To implement these settings, I added the following two snippets to tinymce.module

In tinymce_config() which begins on line 480:

  $init['remove_linebreaks'] = $settings['remove_linebreaks'] ? $settings['remove_linebreaks'] : 'true';
  $init['apply_source_formatting'] = $settings['apply_source_formatting'] ? $settings['apply_source_formatting'] : 'true';

In tinymce_profile_form() (around line 625):

  $form['output']['remove_linebreaks'] = array(
    '#type' => 'select',
    '#title' => t('Remove Linebreaks'),
    '#default_value' => $edit->settings['remove_linebreaks'],
    '#options' => array('true' => 'true', 'false' => 'false'),
    '#description' => t('Set this option to false to prevent TinyMCE from removing linebreaks from existing nodes.  True avoids conflicts with some filters.')
  );

  $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.')
  );

My feature request:
http://drupal.org/node/80851

whereisian’s picture

I've been looking for that fix for ages. Can't thank you enough.

Milan_Knizek’s picture

Same here, thanks!

thehardings’s picture

Only place i found help on this!
works perfectly taking out/removing the line breaks
dan

terrypearson’s picture

For that, you deserve the Nobel Prize.

I just spent a day and a half trying to figure out what was wrong and your solution took me one minute!

Thank you so very much!

Owen Barton’s picture

Please note that the feature request (and patch) for this is over at http://drupal.org/node/80851

leed’s picture

Thank you!
I hope that tinyMCE module gets updated with your solution!!!

SirBerberitz’s picture

Hi all,

could somebody give me a hint why this is not working with Drupal 6.5 and TinyMCE 6.x-1.1-dev?

I would like to get this working asap as I spent so much time to find a solution ... :(

Thanks in advance

SirBerberitz

PS: in my tinymce.module there is no tinymce_profile_form() (around line 625) ???

SirBerberitz’s picture

It was my fault, I found the solution here

Thanks to all!

SirBerberitz