tags:

views:

141

answers:

2

I have a TextEdit widget in PyQt that I use to print out a log in HTML. I use HTML so I can separate entries into color categories (red for error, yellow for debug, blue for message, etc), but this creates a problem. Most of the debug messages are XML. When I use appendHtml on the widget, it strips out all the tags.

How can I pretty print XML in an HTML document?

+4  A: 

cgi.escape can help you. It will convert the characters '&', '<' and '>' in the string to HTML-safe sequences. That is enough to prevent interpretation of xml tags.

>>> cgi.escape('<tag>')
'&lt;tag&gt;
nosklo