leforestier / yattag

Python library to generate HTML or XML in a readable, concise and pythonic way.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

stephanki opened this issue · comments

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')

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.