escape pango markup for all characters that break it

This commit is contained in:
Nikos Kouremenos 2005-07-23 12:45:17 +00:00
parent a037ca8369
commit d9ff414ac5
1 changed files with 12 additions and 4 deletions

View File

@ -20,9 +20,17 @@
## GNU General Public License for more details.
##
import cgi
import xml.sax.saxutils
def escape_for_pango_markup(string):
# escapes chars for pango markup not to break
if string is not None:
return cgi.escape(string)
# escapes < > & \ "
# for pango markup not to break
if string is None:
return
if gtk.pygtk_version >= (2, 8, 0) and gtk.gtk_version >= (2, 8, 0):
escaped_str = gobject.markup_escape_text(string)
else:
escaped_str =xml.sax.saxutils.escape(string, {'\\': '&apos;',
'"': '&quot;'})
return escaped_str