Make tag replacement/transformation cover a few more cases and a bit less brittle.

Yes, I'm parsing HTML with regexp.
Yes, it's better than what it was doing before.
Yes, I want to do it better someday.
No, you don't get to bitch about it unless you're gonna fix it.