• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

tinymce text editor leaves empty <p></p> tags

Using content management system made simple cmsms which uses Smarty templates tinymce text editor leaves empty <p></p> tags.  This sometimes happens when I toggle the WYSIWYG checkbox
1 Solution
Ray PaseurCommented:
Yes, it happens to me, too.  Sometimes I have found the best way to fix this problem is to go into the data base with phpMyAdmin.

Just wait till one of your clients copies a text from a word document and pastes that into tinyMCE!
Scott MadeiraCommented:
Notepad makes a great Word to tinyMCE "filter."
Beverley PortlockCommented:
Look in tiny_init.js for a line like

force_br_newlines : false,

which changes blanklines to <p>/<p> either remove this or set it to true and it will put <br/> tags in

With regard to Ray's comment about people pasting from Word, there is a WORD PASTE add-in. Here is a sample of part of a line in my tiny_init

theme_advanced_buttons1 : 'pasteword,bold,italic, ... etc

An alternative is to filter content from text areas through a series of regexes

     // 008 Clear out spurious stuff from Word and other word processors. Intended
     // to be used with the TinyMCE editor
     function xmlCleanOut( $test ) {

          // Clean out all XML paired tags <w:abcde>.....</w:abcde>
          $patt1 = '#(\s*?<{1}[a-zA-Z0-9]+:.+?>{1}.*?<{1}/{1}[a-zA-Z0-9]+:[a-zA-Z0-9]+>{1}\s*?)#';

          // Clean out all XML single tags <w:abcde/> or </w:abcde>
          $patt2 = '#(\s*?<{1}/?[a-zA-Z0-9]+:[a-zA-Z0-9]+/?>{1}\s*?)#';

          // Clean out all Office-related HTML comments <!-- ...mso... -->
          $patt3 = '#(\s*?<!--\s*?\[.+?\smso\s.+\].*?-->\s*?)#';

          // Whack all class=MsoNormal stuff.
          $patt4 = '#(\s*?class\s*?=\s*?MsoNormal\s*?)#i';

          // Clean out all newlines
          $test = str_replace(array("\n", "\r\n", "\r"), "", $test);

          $test = preg_replace( $patt1, '', $test );
          $test = preg_replace( $patt2, '', $test );
          $test = preg_replace( $patt3, '', $test );
          $test = preg_replace( $patt4, '', $test );

          // Put selected newlines back in and return
          return str_replace( array("><", "> <", ">  <"), ">\n<", $test );

Open in new window

Ray PaseurCommented:
Hey, Brian - that's great!  I think it has been a couple of years since I looked at my tinyMCE stuff, and it can probably use an update.  I have been using smadeira's technique, but every so often someone forgets and makes a has of things.
rgb192Author Commented:
I like the explanation
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now