pepebe
11/15/2013 - 1:57 PM

Remove p around modx tags used inside a tinymce rte field

Remove p around modx tags used inside a tinymce rte field

<?php
/*
plugin to remove p arround modx tags in tinymce
author: breezer

event: OnParseDocument
*/

    $eventName = $modx->event->name;
    switch ($eventName)
    {
     
        //case 'OnParseDocument':
        case 'OnWebPagePrerender':
        //case 'OnLoadWebDocument':
     
            $replace = array(
                 '<p>[[!'    => '[[!'
                ,']]</p>'    => ']]'
                
                ,'<p>[[*'    => '[[*'
                ,']]</p>'    => ']]' 
                
                ,'<p>[[#'    => '[[#'
                ,']]</p>'    => ']]'
                
                ,'<p>[[$'    => '[[$'
                ,']]</p>'    => ']]'
                //,'<p>'       => '<div>'
                //,'</p>'      => '</div>'
                ,'<p><div' => '<div'
                ,'</div></p>' => '</div>'
            );

            $content = $modx->resource->_output; // get a reference to the output

            $newContent = str_replace(
                 array_keys($replace)
                ,array_values($replace)
                ,$content
            );
            
            $modx->resource->_output = $newContent;
     
            break;
     
        default:
        
            break;
    }
     
    return;