I have my own snippet for outputting MODx tags, but for php, html, and css, I usually just turn off the rich text editor and use the HTML entities for everything that would cause trouble (I don't have that much code to present on my site).
Here's a snippet off the top of my head that will work, though. Each piece of code could go in its own chunk or directly in the snippet call (for short bits of code).
Snippet: ShowCode
Call: [[ShowCode? &codeChunk=`codeExample1`]]
<br />or
[[ShowCode? &rawCode=`<p>some raw code <b>here</b></p>`]]
<br /><br />Snippet Code:<br /><br />[code<?php
if (isset($rawCode)) {
$output = htmlentities($rawCode, ENT_QUOTES);
} else {
$str = $modx->getChunk($codeChunk);
$output =’<pre>’;
$output .= htmlentities($str, ENT_QUOTES);
$output .=’</pre>’;
}
return $output;
?> <br /><br />[Update 1/5/08: fixed a couple of typos and tested it. It works both ways and the chunk version will preserve your line breaks and your indenting.]<br /><br /><br />Hope this helps,<br /><br />Bob<br />