[Doc-SIG] CharEnt support in HTML4css1.py

David Priest priest@sfu.ca
Thu, 20 Mar 2003 13:17:16 -0800

The following replacement code allows HTML4css1.py to support the use of 
charents.  It can be easily adapted to the other writers, I'm sure.

    def encode(self, text):
        """Encode special characters in `text` & return."""
        # @@@ A codec to do these and all other HTML entities would be 
#        text = text.replace("&", "&")
        # match standard charent forms (# &xHEXNUM; and &namedEntity;)
        text = re.sub(r'&(?!(([a-zA-Z]{2,};)|(#(x|X)?[0-9a-fA-F]{2,4};)))', 
r'&', text)
        text = text.replace("<", "&lt;")
        text = text.replace('"', "&quot;")
        text = text.replace(">", "&gt;")
        text = text.replace("@", "&#64;") # may thwart some address 
        return text