Alex Rivera | Logout

How to escape characters in Pango markup?

Asked 2009-11-19T00:17:10.703
14

My program has a gtk.TreeView which displays a gtk.ListStore. The gtk.ListStore contains strings like this:

"<span size='medium'><b>"+site_title+"</b></span>"+"\n"+URL

Where URL is (obviously) a URL string. Sometimes there are characters in URL that cause pango to fail to parse the markup.

Is there a way to escape URL as a whole so that pango will just ignore it so it will be displayed literally? If not, how should I "escape" special characters in URLs?

Edit
Report

2 Answers

22

glib.markup_escape_text may be a more canonical approach when using GTK.

answered 2009-11-25T18:18:54.807
2

You need to escape the values. I'm not sure what exact format Pango requires, but it looks like HTML and the cgi.escape function may be all you need.

import cgi
print "<span size='medium'><b>%s</b></span>\n%s" %
      (cgi.escape(site_title), cgi.escape(URL))
answered 2009-11-19T02:43:44.120

Your Answer