Force TinyMCE drupal module to produce BR instead of P

Here are a few reasons why BR elements and the force_br_newlines aren't enabled by default in tinyMCE and why forced_root_block is.

  1. Paragraphs were invented for a reason. Try modifying paragraph margins using CSS without using paragraph tags and you see what we mean.
  2. The IE WYSIWYG environment is built on handling paragraphs when it comes to alignment/list management and much more. TinyMCE and other editors will start producing lots of strange results if you enable force_br_newlines.
  3. The space between the paragraphs can be removed using a simple CSS trick like this. p {margin:0; padding: 0;}. This is not possible with BR elements, since the whole line is not wrapped in a container. So P elements gives you the flexibility to choose.
  4. If you really must have BR instead of paragraph elements for some reason – for example to interface with Flash or send e-mail messages –, then simply post process them away by replacing <p with <span and </p> with </span><br />, which takes care of P tags with class or style attributes. The same process but from BR tags to P tags can not be done since you don't have a reference for the start element.
  5. Paragraphs make more semantically correct XHTML markup, and we are trying to make an XHTML editor, not an old HTML editor.
  6. Paragraphs are mostly more valid containers for text in a W3C strict environment since plain text nodes are not allowed in all containers.
  7. BR elements can still be produced if you really need one at a specific place for some reason using Shift+Enter/Return this is exactly the same behavior popular Word processors have. Check this video.
  8. We have never seen one single valid reason why paragraphs must not be used unless it's for e-mail software or for integration with Flash, and both cases can and should be solved with post processing if you want the user to be able to modify the contents again with TinyMCE. If you have a good reason please drop us a e-mail describing it and I will put it on my exceptions list.

If you want to continu to use <BR> instead of <P> for your Drupal website, create a module called "tiny_mce_br" and add the following code inside : 

tiny_mce_br.info

name = tiny_mce_br
description = Overrides some settings for TinyMCE
dependencies[] = wysiwyg
core = 7.x

tiny_mce_br.module

<?php
function tiny_mce_br_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;
}
}

Environnement :

  • Drupal 7
  • tinyMCE 3.4.9
  • Wysiwyg 7.x-2.1

About the author

Consultant, Web strategist, and Drupal enthusiast, I use open source software to build application that connects people and spread ideas. I believe that internet can lead to powerful changes for progressive organizations, and for our future.

Keep in touch here