leforestier / yattag

Python library to generate HTML or XML in a readable, concise and pythonic way.
332 stars 31 forks source link

Extension to simpledoc.html_escape to support also characters like @ÄÜö€ #37

Closed stephanki closed 6 years ago

stephanki commented 6 years ago

Currently only the characters <>& are escaped. Using cgi.escape() and encode works for much more characters:

see yattag.simpledoc.html_escape()

# original code
#return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
import cgi   
return cgi.escape(s).encode('ascii','xmlcharrefreplace').decode('ascii')
leforestier commented 6 years ago

I don't think that's an issue. Needing to write characters as html entities usually just means you declared the wrong character set. Pretty much everybody uses an utf-8 character set these days, with XML or HTML. In this context, the only characters that need to be escaped are '&' and '<'. You don't need to encode any other character using html entities.