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 {{{ # Quick Open {{{
def make_highlighted_text(emph, text, positions): def make_highlighted_text(emph, text, positions):
positions = sorted(set(positions) - {-1}, reverse=True) positions = sorted(set(positions) - {-1})
for p in positions: if positions:
ch = get_char(text, p) parts = []
text = '%s<span style="%s">%s</span>%s' % (prepare_string_for_xml(text[:p]), emph, ch, prepare_string_for_xml(text[p+len(ch):])) pos = 0
for p in positions:
ch = get_char(text, p)
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 return text
class Results(QWidget): class Results(QWidget):
EMPH = "color:magenta; font-weight:bold" EMPH = "color:magenta; font-weight:bold"