I have switched to TinyMCE from FCK due to the <p>&nbsp;<.p> issue with FCK. Everything so far is fine with TinyMCE. However, I do not like the way TinyMCE forces paragraphs instead of line breaks on enter. I understand the developers have reasons for wanting paragraphs as default, but it's really confusing from a user perspective when a forum requires shift-enter to line break.

As such, I want to disable this function and get line breaks by default.

I have read the TinyMCE FAQ, forums, and documentation, and their standard answer is:

1) http://wiki.moxiecode.com/index.php/TinyMCE:FAQ#TinyMCE_produce_BR_eleme...

tinyMCE.init({
   forced_root_block : false,
   force_br_newlines : true,
   force_p_newlines : false
});

2) http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/force_br_newlines

tinyMCE.init({
	...
	force_br_newlines : true,
        forced_root_block : '' // Needed for 3.x
});

I would like to try these configurations, but I am having a lot of trouble understanding or figuring out where to put this code - in TinyMCE, the WYSIWYG module, or my site's theme.

Can you help me figure out where it goes or how to enter it?

Thanks for any help you can provide.

Comments

nimi’s picture

I am having the exact same issue. Did you find a solution that works?

uomeds’s picture

From what I have read, I am almost certain the tinyMCE.init({ solutions I posted above should work. We just have to figure out where and how to insert it.

I am hoping the WYSIWYG coder can clarify, since I think it needs to go into the module.

TwoD’s picture

Status: Active » Fixed

Personally, I expect paragraphs when pressing enter and think excessive use of linkebreaks are what makes many websites (and wordprocessor documents!) very hard to style or zoom/scale the text nicely on.

But you can try this, from #313497: Allow configuration of advanced editor settings. I haven't actually tested it but I think it should work.

drupal_add_js( array(
  "wysiwyg" => array(
    "configs" => array(
      "tinymce" => array(
        "formatN" => array( // Replace N with the id num of the format TinyMCE is enabled for.
          'forced_root_block' => FALSE,
          'force_br_newlines' => TRUE,
          'force_p_newlines' => FALSE
        )
      )
    )
  )
),'setting');

Just leave out the starting/ending PHP tags and put it in your template.php file. If you have enabled TinyMCE for more than one format you can just add another formatN key to the tinymce array.

Once the issue I mentioned above is fixed, you should not need this workaround anymore.

Status: Fixed » Closed (fixed)

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

samchok’s picture

The above code in template.php seemed to work for me. But now I'm getting a new problem: The TinyMCE editor correctly create a 'br' instead of 'p' tag, but when the Preview (and the newly created page) shows no 'br' or 'p' at all! Allt he text is on the same line...
What could it be?

samchok’s picture

Status: Closed (fixed) » Active

I add that the input type associated to the editor is "Full HTML", so no tags should be filtered by drupal.
Also, the 'br' tags are present in DB: if I edit the page the editor still displays new lines and disabling the editor the 'br' tags are still there.
So it seems that drupal is not showing the 'br' tags in the 'view' tab only.

samchok’s picture

Status: Active » Closed (fixed)

The problem was with the HTML filter checkbox associated with the "Full HTML" input type. Disabling it everything works fine again.

srobert72’s picture

asnair’s picture

Yes, this works!

Notes:
template.php file is in the themes folder. And this code is to be inserted outside of any function.
The N in FormatN is to be obtained from admin/settings/filters (in Drupal). In my case the selected Input Format is "Full HTML" which is 2nd in the list. Hence, I replaced N with 2

I pasted the following code above all the functions:-

<?php
//added on 30 Dec 2011 for tinyMCE to use instead of

drupal_add_js( array(
"wysiwyg" => array(
"configs" => array(
"tinymce" => array(
"format2" => array( // Replace N with the id num of the format TinyMCE is enabled for.
'forced_root_block' => FALSE,
'force_br_newlines' => TRUE,
'force_p_newlines' => FALSE
)
)
)
)
),'setting');
// end add

function theme166_menu_local_task($link, $active = FALSE) {
etc

TwoD’s picture

We have a better way of doing this now. See wysiwyg.api.php for details.

sites/all/modules/MYMODULE/MYMODULE.info:

name = My custom module
description = Overrides some settings for TinyMCE
core = 6.x

sites/all/modules/MYMODULE/MYMODULE.module

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'tinymce') {
    $settings['forced_root_block'] = FALSE;
    $settings['force_br_newlines'] = TRUE;
    $settings['force_p_newlines'] = FALSE;
  }
}

Enable the module as usual.
Now it'll work with all themes you've got installed without further modifications, even if updating Wysiwyg or TinyMCE.

mototribe’s picture

thanks TwoD, exactly what I was looking for - works just fine with D7. This should be a settings option in the module

TwoD’s picture

Once I get to finalizing the patch for allowing editors and plugins change the settings GUI, we can add all those settings as separate checkboxes.

ximizu’s picture

solution #10 works perfectly for with D7.
Thanks TwoD.

RAWDESK’s picture

Issue summary: View changes

#10 worked perfectly to prevent <p> tags from occurring around youtube embedded media, which rendered faulty with an unwanted blank line in front of it.
@TwoD, good idea to provide this in wysiwyg admin UI. Let me know if review/testing is wanted.