Rewrite pretty-printing HTML elements to prevent throwing internal errors when using non-native DOM implementationd