This is the approach taken by other compilers. While I found it quite weak too, I didn't want to "invent" a custom HTML solution. Reparsing the HTML doesn't seem to make a lot of sense to me. Even if lxml is fast, yet another parsing step is going to slow down processing. Not to mention that there might be added complexity in handling html4 v html5 v xhtml.