Rewrite pretty-printing HTML elements to prevent throwing internal errors
Fixes errors occuring when using a non-native DOM implementation