diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py
index 56adb49dff..d2788703d6 100644
--- a/src/calibre/gui2/tweak_book/widgets.py
+++ b/src/calibre/gui2/tweak_book/widgets.py
@@ -252,10 +252,9 @@ class ImportForeign(Dialog): # {{{
def make_highlighted_text(emph, text, positions):
positions = sorted(set(positions) - {-1}, reverse=True)
- text = prepare_string_for_xml(text)
for p in positions:
ch = get_char(text, p)
- text = '%s%s%s' % (text[:p], emph, ch, text[p+len(ch):])
+ text = '%s%s%s' % (prepare_string_for_xml(text[:p]), emph, ch, prepare_string_for_xml(text[p+len(ch):]))
return text