We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26931
    • 2,314 Posts
    Hi everybody,

    i try to display html, css, snippet-calls etc. on a (MODx) website...placing then within <pre><code></code></pre> strangely doesn’t work, everything gets parsed. escaping snippet calls like this:
    [<!-- -->!Snippet? ...!<!-- -->]
    does work, but not with placeholders and html-tags...has anybody an idea what i could be doing wrong? maybe a tinymce setting?

    thanks, j
      • 26931
      • 2,314 Posts
      okay, looks like MODx is also parsing within <pre> and <code> tags, so with the friendly help of Bogdan Günther i got a plugin working which will solve this problem:

      // load content
      	$content=$modx->documentObject['content'];
      	
      	// HTML-Parser
      	function parseMODxHTML($matches)
      	{
      		$code=$matches[1];
      		$code=str_replace('&', '&', $code);
      		$code=str_replace('[', '[', $code);
      		$code=str_replace(']', ']', $code);
      		$code=str_replace('{', '{', $code);
      		$code=str_replace('}', '}', $code);
      		$code=str_replace('<', '<', $code);
      		$code=str_replace('>', '>', $code);
      		$code=str_replace(chr(10).chr(9).chr(9), chr(10), $code);
      		$code=str_replace(chr(9), '   ', $code);
      		
      		return $GLOBALS['tagStart'].$code.$GLOBALS['tagEnd'];
      	}
      		
      	$GLOBALS['tagStart']='<code>'; $GLOBALS['tagEnd']='</code>';
      	$content=preg_replace_callback('#'.$GLOBALS['tagStart'].'(.*?)'.$GLOBALS['tagEnd'].'#s', 'parseMODxHTML', $content);
      	
      	$GLOBALS['tagStart']='<pre>'; $GLOBALS['tagEnd']='</pre>';
      	$content=preg_replace_callback('#'.$GLOBALS['tagStart'].'(.*?)'.$GLOBALS['tagEnd'].'#s', 'parseMODxHTML', $content);
      	
      	$GLOBALS['tagStart']='<pre class="prettyprint">'; $GLOBALS['tagEnd']='</pre>';
      	$content=preg_replace_callback('#'.$GLOBALS['tagStart'].'(.*?)'.$GLOBALS['tagEnd'].'#s', 'parseMODxHTML', $content);
      	
      	$content=str_replace(chr(10).'   </pre>', '</pre>', $content);
      	
      	// save content
      	$modx->documentObject['content']=$content;


      check System Event: "OnLoadWebDocument"

      :)
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I just use keyboard macros. alt-left bracket automagically prints out &#91; etc. There are a number of applications that create and manage keyboard macros for Windows and Mac. I think Linux has that built-in, I used to use them but it’s been a long time.

        The one I’m using now is called "Butler", and does a whole lot more; of especial interest is multiple pasteboards.



          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 26931
          • 2,314 Posts
          thanks sottwell, i’ll check that out too! j
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Well, the plugin would be of especial interest if it converted them back OnWebPagePrerender. Then readers could copy/paste code.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 26931
              • 2,314 Posts
              hmm....actually i’m able to copy & paste shocked one thing i need to come by though, are the escaped ampersands & -> &amp; that show up on the rendered pages (within the <code>-tags)...have you got an idea for that sottwell wink
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Well, those are most likely put in by TinyMCE, and I rarely use it, so I’m not sure how to make it stop that conversion.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 26931
                  • 2,314 Posts
                  if i disable "RichText" for that document it would work, but maybe there’s a more elegant way? normally i use another plugin to ecape stray & -> &amp; (especially in title tags & wayfinder) so that the site xhtml-validates, guess that would also interfere with this plugin...getting the <code>-tags to work properly could be useful if you want to write MODx-tutorials on an actual MODx website smiley
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Looking at the TinyMCE forums, it appears that a lot of people are having the same problems with it. The developers seem to be at a loss as to why anyone could possibly object to having their carefully-written code "cleaned up" under any circumstances. Personally, if I use & I mean &; if I want &amp; I’ll use it, and I don’t want it converted to &amp;amp; thank you very much!
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 26931
                      • 2,314 Posts
                      :) uncommenting that line seems to do the trick:

                      $code=str_replace('&', '&', $code);


                      ...so even wit RichText enabled (html preview displays & as &amp;) the output within <pre> and <code>-tags will be displayed as &.
                      btw., this plugin doesn’t interfere with the other plugin i’m running to convert stray & to xhtml-valid &amp; which runs on "OnWebPagePrerender"