diff -r 31934b8c7bef -r cae2de810f77 src/cm/utils/diff.py --- a/src/cm/utils/diff.py Wed Apr 14 17:05:14 2010 +0200 +++ b/src/cm/utils/diff.py Thu Apr 15 14:33:56 2010 +0200 @@ -113,3 +113,41 @@ else: cur += c out.append(cur) return filter(lambda x: x is not '', out) + +# + +from ext.diff_match_patch import diff_match_patch + +class diff_match_patch2(diff_match_patch): + def diff_prettyHtml_one_way(self, diffs, way=False, mode='red'): + """Convert a diff array into a pretty HTML report. + + Args: + diffs: Array of diff tuples. + way: [None, 1, 2] + mode: ['ins_del', 'red'] + + Returns: + HTML representation. + """ + html = [] + i = 0 + for (op, data) in diffs: + text = data #(data.replace("&", "&").replace("<", "<") + #.replace(">", ">").replace("\n", "¶
")) + if op == self.DIFF_INSERT and (not way or way==1): + if mode=='red': + html.append('%s' % (text)) + else: + html.append('%s' % (text)) + + elif op == self.DIFF_DELETE and (not way or way==2): + if mode=='red': + html.append('%s'% (text)) + else: + html.append('%s'% (text)) + elif op == self.DIFF_EQUAL: + html.append("%s" % (text)) + if op != self.DIFF_DELETE: + i += len(data) + return "".join(html) \ No newline at end of file