简体   繁体   中英

Render Unified Diff with Python

I have a string which contains svn unified diff. My PyGTK app need to show this diff to user, and I want to render it like other diff tools do, or at least have it colorized.

Do you have something to suggest, external tool, library, custom implementation...? I was loking at http://kafka.fr.free.fr/diff2html/ but I prefer to use some library or sth like that, so users don't need to install third party apps.

I want use this for git and mercurial diffs later as well.

You could use difflib to generate diffs, and pygtkscintilla for syntax-highlighting, line-numbering, code-folding, etc.

If you only want syntax-highlighting (as opposed to all the editor features offered by pygtkscintilla), then you could also look at pygments .

The difflib.HtmlDiff class provides facilities for doing this. However, instead of starting with a unified diff file, HtmlDiff wants you to pass the complete "before" and "after" files. These files are easy to get with svn/git/mercurial commands without using the "diff" functionality of those VCS.

GtkSourceView是pygtk的TextView的替代品,它可以语法突出显示差异文件,包括统一差异。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM