The problem is not in fulltext.php and search.php, only in html.php. Because the search results display special characters as HTML entitites (so, HTML won't get interpreted).
This url has code to find all text nodes in a document. Those nodes can then be searched for the search string.
2) Don't do syntax highlighting inside of html tags. This is also not a perfect solution, since some words won't be highlighted.
What I would suggest is to turn off search highlighting for pages that contain html tags by extending the metadata renderer to record when the html-function is called, i.e. when HTML is actually used in a page. However I don't think this will fix the problem with entities.
I mean jQuery (or even pure JS) should be able to walk DOM