Hi all,
Most people know that if you want to prevent a MODx tag from being parsed in a page on a MODx site (for example, when writing a tutorial or documentation) then you can use the ole’ comment trick to prevent the parsing: [<!-- -->[mySnippet]<!-- -->]
That solves one problem, but creates another ... how many people have been caught out when they do a copy and paste and wonder why things don’t quite work? Because, inadvertently, they have copied the commented tag over.
So, here’s a simple little plugin that I’m developing as I redesign my personal site. The plugin attaches to the OnWebpagePrerender event and uses some simple regular expressions to remove the comments from the tags (as all MODx parsing is now completed at this point, they are displayed on the page in a niceCopy format

) The plugin itself may need a few tweaks here or there which is why I’m not yet posting this in the Repository.
Not sure if something like this exists already, but thought I’d post it here anyway.
<?php
/**
* Plugin: niceCopy v0.5
* Author: Garry Nutting
* Date: 22/01/07
*
* Event: OnWebpagePrerender
*/
// delimiter
$delim = '<!-- -->';
// replacement arrays
$replace = array(
'/\['.$delim.'[(.*?)]'.$delim.'\]/ims',
'/\['.$delim.'!(.*?)!'.$delim.'\]/ims',
'/\{'.$delim.'{(.*?)}'.$delim.'\}/ims',
'/\['.$delim.'\((.*?)\)'.$delim.'\]/ims',
'/\['.$delim.'\+(.*?)\+'.$delim.'\]/ims',
'/\['.$delim.'\*(.*?)\*'.$delim.'\]/ims',
);
$with = array(
'[[\1]]',
'[!\1!]',
'{{\1}}',
'[(\1)]',
'[+\1+]',
'[*\1*]'
);
// take copy of document output
$output = $modx->documentOutput;
// do replacement and send back to document output
$output = preg_replace($replace,$with,$output);
$modx->documentOutput = $output;
?>
Have fun,
Garry