Thats stuff I would take into consideration when doing it, I am sure this is not the most efficient solution.
Basically I would have table where I would place tags or characters that might be with in a tag over three characters. For example these are some words I would put into a table.
html
htm
php
body
border
cell
table
font
style
class
meta
http
size
and so on ...
It would pull this list from a database and check them against the search keyword and than return a message to the user saying couldn't search keyword if it found a match. Or it just wouldn't place the highlight tags around it.
So if someone typed in "html" or "table" it wouldn't return the search. Or I could simply just not add the highlight tag since that is what is really messing up the display. Only on specific keywords found in the database.
The draw back is if this end up being a website where someone wanted to search for results of the word, "body" or "border". I wouldn't think it would be that big of a deal but something to think about.
Like I said it was just a thought and wanted to get feedback on it. It might be a lot of work to add all these attributes and html tags but I have some control over this since the only people who would be adding new html tags are designers that I work directly with.
Let me know if this makes sense.