Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-10-26
Medium Priority
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 111

Expert Comment

by:Ray Paseur
ID: 37032577
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
ID: 37032592
Notepad makes a great Word to tinyMCE "filter."
LVL 34

Accepted Solution

Beverley Portlock earned 2000 total points
ID: 37032928
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 111

Expert Comment

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

ID: 37128938
I like the explanation

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

864 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