TinyMce extra br and p near new lines bug

acknowledgements_logo_tinymce

I encountered a known problem while installing tiny mce on expression engine, transforming new lines to br or p tags.

When i speak of newline I mean nr or chr(13)+chr(10). I saw that the “bug” appeared on different platforms like blogspot, joomla anywhere where tinymce exists.

It’s a known problem, but i didn`t found an actual solution on google. People that use br and not paragraphs resolved it with

  • force_br_newlines : true,
  • forced_root_block : ”,

but i wanted paragraphs not line breaks.

First i thought the problem was the expression engine so i disabled the formatting option at the “custom weblog field” to “none”(instead of xhtml or auto
(from cpanel and from all previous entries).

No change, then i tried to modify tinymce’s settings, still nothing.

Then i pinned down the problem : when i edit an entry, tiny mce automatically transforms the ascii “newline” to
or

 

. I checked the database, the field text was good (only

‘s and normal newlines). I tried with Opera and Firefox … the problem persisted. When you hit “Edit entry” you can see double spaces between paragraphs, and when i hit “html” source from the tiny mce bars (“code” button) there they were : lots of line breaks over all newlines.

What is happening :

//you enter
<p>Lorem ipsum dolor sit amet consectetuer a ut ut hendrerit Sed. Maecenas justo.</p><br /><p>In sit justo ipsum Vestibulum a semper orci Pellentesque nibh pulvinar. Pretium In et elit tincidunt mauris nisl dui sed Sed est. Duis sed.</p><br />//and becomes
<p>Lorem ipsum dolor sit amet consectetuer a ut ut hendrerit Sed. Maecenas justo.</p><br /><br /><p>In sit justo ipsum Vestibulum a semper orci Pellentesque nibh pulvinar. Pretium In et elit tincidunt mauris nisl dui sed Sed est. Duis sed.</p>
//or
<p>Lorem ipsum dolor sit amet consectetuer a ut ut hendrerit Sed. Maecenas justo.</p><br /><p>&amp;nbsp;</p><p>In sit justo ipsum Vestibulum a semper orci Pellentesque nibh pulvinar. Pretium In et elit tincidunt mauris nisl dui sed Sed est. Duis sed.</p> 

I read and set all the tiny mce related settings, but still nothing :

  • convert_newlines_to_brs: “false”,
  • force_p_newlines: “true”,
  • force_br_newlines : “false”,
  • remove_redundant_brs : “true”,
  • remove_linebreaks : “true”,
  • forced_root_block : “”,

I found a workaround with a custom cleanup, that before the submit removes all the line breaks from the input, is kinda cruel but if you are desperate it works (i think, i didn’t tested it).

function CustomCleanup(type, content) {<br />  switch (type) {<br />   // gets passed when user submits the form<br />   case "get_from_editor":<br />    content = content.replace(/<br />/gi, "n"); // would be nice if this replace only replaces the brs in a pre block. bur for the moment it is ok.<br />    break;<br />   // gets passed when new content is inserted into the editor<br />   case "insert_to_editor":<br />    break;<br />  }<br />return content;<br />}<br /><br />tinyMCE.init({<br />    ...<br />    cleanup_callback : "myCustomCleanup"<br />});<br />

Finally the solution

After some swearing time and play around with this settings it came to me what i did wrong, the settings were boolean type, and i gived them string values.

Ok let me explain it, convert_newlines_to_brs: false is good, convert_newlines_to_brs: “false” is actual convert_newlines_to_brs: true or convert_newlines_to_brs: “anything-here”

So, actual is not a bug, just a bad setting and the solution is : convert_newlines_to_brs: false , without the double quotes.

Morale : when you are in a hurry to fix something, return to it after a break grin.

About B3aT

Love to pair programming a HTML5 game with Jack Daniels while playing a MMO and riding a hookah.
Games,fishing,tech books,military and not doing sport as hobbies.

Category(s): Blog (personal), Software
Tags: ,

You have thoughts ? write them

Your email address will not be published. Required fields are marked *

4 − t|hree =

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>