Fix make_highlighted_text to work with XML unsafe text

This commit is contained in:
Kovid Goyal 2014-12-24 13:34:25 +05:30
parent 4fa1dcff15
commit d7c1ab0c7c

View File

@ -251,13 +251,19 @@ class ImportForeign(Dialog): # {{{
# Quick Open {{{
def make_highlighted_text(emph, text, positions):
positions = sorted(set(positions) - {-1}, reverse=True)
positions = sorted(set(positions) - {-1})
if positions:
parts = []
pos = 0
for p in positions:
ch = get_char(text, p)
text = '%s<span style="%s">%s</span>%s' % (prepare_string_for_xml(text[:p]), emph, ch, prepare_string_for_xml(text[p+len(ch):]))
parts.append(prepare_string_for_xml(text[pos:p]))
parts.append('<span style="%s">%s</span>' % (emph, prepare_string_for_xml(ch)))
pos = p + len(ch)
parts.append(prepare_string_for_xml(text[pos:]))
return ''.join(parts)
return text
class Results(QWidget):
EMPH = "color:magenta; font-weight:bold"