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