diff --git a/toolserver/copyvios/highlighter.py b/toolserver/copyvios/highlighter.py index 79c3ec9..1fa773c 100644 --- a/toolserver/copyvios/highlighter.py +++ b/toolserver/copyvios/highlighter.py @@ -25,11 +25,14 @@ def highlight_delta(context, chain, delta): for paragraph in chain.text.split("\n"): words = [] for i, word in enumerate(paragraph.split(), i): - before = highlights[i - 1] - after = highlights[i + 1] - first = i == degree - last = i - degree + 1 == numwords - words.append(_highlight_word(word, before, after, first, last)) + if highlights[i]: + before = highlights[i - 1] + after = highlights[i + 1] + first = i == degree + last = i - degree + 1 == numwords + words.append(_highlight_word(word, before, after, first, last)) + else: + words.append(unicode(escape(word))) processed.append(u" ".join(words)) i += 1 @@ -37,30 +40,23 @@ def highlight_delta(context, chain, delta): def _highlight_word(word, before, after, first, last): if before and after: - # Word is in the middle of a highlighted block, so don't change - # anything unless this is the first word (force block to start) or the - # last word (force block to end): + # Word is in the middle of a highlighted block: res = unicode(escape(word)) if first: res = u'' + res if last: res += u'' - elif before: - # Word is the last in a highlighted block, so fade it out and then end - # the block; force open a block before the word if this is the first - # word: - res = _fade_word(word, u"out") + u"" - if first: - res = u'' + res elif after: - # Word is the first in a highlighted block, so start the block and then - # fade it in; force close the block after the word if this is the last - # word: + # Word is the first in a highlighted block: res = u'' + _fade_word(word, u"in") if last: res += u"" + elif before: + # Word is the last in a highlighted block: + res = _fade_word(word, u"out") + u"" + if first: + res = u'' + res else: - # Word is completely outside of a highlighted block, so do nothing: res = unicode(escape(word)) return res