コード例 #1
0
ファイル: models.py プロジェクト: aether-space/spacepaste
 def compare_to(self, other, context_lines=4, template=False):
     """Compare the paste with another paste."""
     udiff = u'\n'.join(difflib.unified_diff(
         self.code.splitlines(),
         other.code.splitlines(),
         fromfile='Paste #%s' % self.identifier,
         tofile='Paste #%s' % other.identifier,
         lineterm='',
         n=context_lines
     ))
     if template:
         diff, info = prepare_udiff(udiff)
         return diff and diff[0] or None
     return udiff
コード例 #2
0
ファイル: highlighting.py プロジェクト: shirkey/spacepaste
def highlight_diff(code, _linenos=True):
    """Highlights an unified diff."""
    diffs, info = prepare_udiff(code)
    if code and not diffs:
        # the diff was quite very much malformatted.
        # TODO: we do not yet support diffs made by GNU Diff!
        lexer = TextLexer()
        style = get_style(name_only=True)
        formatter = HtmlFormatter(linenos=_linenos, cssclass='syntax',
                                  style=style)
        return u'<div class="code">%s</div>' % \
               pygments.highlight(code, lexer, formatter)
    return render_template('utils/udiff.html', diffs=diffs, info=info,
                           linenos=_linenos)