src/cm/utils/diff.py
changeset 250 cae2de810f77
parent 149 0f2c5744b39b
child 251 3eb5299e8085
equal deleted inserted replaced
249:31934b8c7bef 250:cae2de810f77
   111                 mode = 'tag'            
   111                 mode = 'tag'            
   112             elif c in string.whitespace: out.append(cur+c); cur = ''
   112             elif c in string.whitespace: out.append(cur+c); cur = ''
   113             else: cur += c
   113             else: cur += c
   114     out.append(cur)
   114     out.append(cur)
   115     return filter(lambda x: x is not '', out)
   115     return filter(lambda x: x is not '', out)
       
   116 
       
   117 # 
       
   118 
       
   119 from ext.diff_match_patch import diff_match_patch
       
   120 
       
   121 class diff_match_patch2(diff_match_patch):
       
   122     def diff_prettyHtml_one_way(self, diffs, way=False, mode='red'):
       
   123       """Convert a diff array into a pretty HTML report.
       
   124     
       
   125       Args:
       
   126         diffs: Array of diff tuples.
       
   127         way: [None, 1, 2]
       
   128         mode: ['ins_del', 'red']
       
   129     
       
   130       Returns:
       
   131         HTML representation.
       
   132       """
       
   133       html = []
       
   134       i = 0
       
   135       for (op, data) in diffs:
       
   136         text = data #(data.replace("&", "&amp;").replace("<", "&lt;")
       
   137                    #.replace(">", "&gt;").replace("\n", "&para;<BR>"))
       
   138         if op == self.DIFF_INSERT and (not way or way==1):
       
   139             if mode=='red':
       
   140                 html.append('<span class="diffchange-ins">%s</span>' % (text))
       
   141             else:
       
   142                 html.append('<ins>%s</ins>' % (text))
       
   143                 
       
   144         elif op == self.DIFF_DELETE and (not way or way==2):
       
   145             if mode=='red':
       
   146                 html.append('<span class="diffchange-del">%s</span>'% (text))
       
   147             else:
       
   148                 html.append('<del>%s</del>'% (text))                
       
   149         elif op == self.DIFF_EQUAL:
       
   150           html.append("<SPAN>%s</SPAN>" % (text))
       
   151         if op != self.DIFF_DELETE:
       
   152           i += len(data)
       
   153       return "".join(html)