cStringIO doesn't support Unicode unless it can be encoded to an ASCII string.
Taking regex compiles outside.
Refining regular expression for dynamic text.
Empty attributes.
Silencing syntaxtic.
Correctly join lines with a newline.
. might not match all chars allowed in an attribute name.
Space before the no-content html tag.
Fixing no content tags.