ts2: Improve the output of processed TS files

 - Remove a nasty hack we no longer need
 - Pretty-print empty tags without self-closing them
 - Always preserve TS doctype
 - Add a test reusing existing ts data

Fixes #1420