mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix make_highlighted_text to work with XML unsafe text
This commit is contained in:
parent
4fa1dcff15
commit
d7c1ab0c7c
@ -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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user