This is great - as a developer who has just recently migrated away from xhtml in favour of 4.01, I was looking for something similar. Not only does the core output a couple of things xhtml, but many snippets and other contributions do as well. (I didn’t realize that xhtml-style self-closing tags were considered valid in the body of an html 4.01 document.. interesting.)
I’m still finding my way through MODx - getting easier every day thanks to the wonderful community. But what I do have is lots of php experience. So after I found this post, I thought I should make a couple of small optimizations.
This is the code for my version of the plugin, based on the plugin "tutorial" in the Documentation section of the main site, and based on the plugin discussed above.
$e = &$modx->Event;
switch ($e->name) {
case 'OnWebPagePrerender':
$modx->documentOutput = str_replace(' />', '>',$modx->documentOutput);
break;
default :
return; // stop here - this is very important.
break;
}
As far as I understand it, str_replace is going to be significantly faster than using regular expressions. (Using regex is faster when you’re running a complicated search/replace that can otherwise only be obtained by a sequence of str_replace commands.)
Also.. and I know it’s costing me more to write this sentence than the CPU cycles that this "tip" will save.. but *in some configurations* using single quotes uses fewer cycles than double quotes. When double quotes are used, the php parser scans the string for the existence of any variables so it can do variable replacement. In this plugin, it only happens three times, so it really is highly insignificant, but for some reason, I have felt compelled to write this paragraph anyway. Must be the egg nog ;-)
The only problem that I can forsee this plugin causing is that if you want to cite some xhtml-style code on a valid html 4.01 page, it’s going to get replaced. You can avoid this by escaping the angle brackets:
<!-- instead of this -->
<p>
Waffles for dinner?
<br /><!-- if you're citing code on a valid html 4.01 page, you may not want the plugin to alter this self-closing tag -->
WAFFLES???
</p>
<!-- write your xhtml-style citations like this -->
<p>
Waffles for dinner?
<br /><!-- now the plugin won't replace <br /> with <br> -->
WAFFLES???
</p>
It’s definitely the nog.