Just use a HTML parser, read the contents into an array of arrays, then output it in row order. The only tricky (but not difficult) part is dealing with column spans. If you have row spans, it's gonna get painful, but not much harder.
Makeshifts last the longest.