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

Posted on 2011-10-26
Last Modified: 2012-05-12
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
Question by:rgb192
    LVL 107

    Expert Comment

    by:Ray Paseur
    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!
    LVL 14

    Expert Comment

    by:Scott Madeira
    Notepad makes a great Word to tinyMCE "filter."
    LVL 34

    Accepted Solution

    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

    LVL 107

    Expert Comment

    by:Ray Paseur
    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.

    Author Closing Comment

    I like the explanation

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now