rewrite: add doctype rewriting, more tests on various markup edge cases