This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

ghdiff

Generate Github-style HTML for unified diffs.

Changes

0.4 (2014-06-13)

  • Add iPython magic (mgaitan)

0.3 (2014-04-06)

  • Fix Python 3 issue when running as a command-line script.

0.2

  • Detect character encoding when reading files (Nyoroon)
  • PEP-8 clean up (laulaz)
  • Fix display problem when text line is too long (laulaz)

0.1

  • initial release.

diff

Generate a diff and output Github-style HTML for it.

>>> import ghdiff
>>> from six import print_
>>> print_(ghdiff.diff("a\nb", "b\nb"))
<style type="text/css">
...
</style>
<div class="diff">
    <div class="control">@@&nbsp;-1,2&nbsp;+1,2&nbsp;@@
    </div>
    <div class="delete">-a</div>
    <div class="">&nbsp;b</div>
    <div class="insert">+b</div>
</div>

The css option controls whether or not the output includes CSS.

>>> print_(ghdiff.diff("blah blah blah\nb", "blah zxqq blah\nb", css=False))
<div class="diff">
    <div class="control">@@&nbsp;-1,2&nbsp;+1,2&nbsp;@@
    </div>
    <div class="delete">-blah&nbsp;<span class="highlight">blah</span>&nbsp;blah</div>
    <div class="insert">+blah&nbsp;<span class="highlight">zxqq</span>&nbsp;blah</div>
    <div class="">&nbsp;b</div>
</div>

diff accepts lists of strings representing lines as well.

>>> print_(ghdiff.diff(["blah blah blah", "b"], ["blah zxqq blah", "b"]))
<style type="text/css">
...
</style>
<div class="diff">
    <div class="control">@@&nbsp;-1,2&nbsp;+1,2&nbsp;@@
    </div>
    <div class="delete">-blah&nbsp;<span class="highlight">blah</span>&nbsp;blah</div>
    <div class="insert">+blah&nbsp;<span class="highlight">zxqq</span>&nbsp;blah</div>
    <div class="">&nbsp;b</div>
</div>

IPython magic

ghdiff also works as an IPython magic:

In[1]: %load_ext ghdiff

In[2]: %ghdiff var1 var2

See a notebook example

colorize

colorize takes an existing unified diff and outputs Github-style markup.

>>> print_(ghdiff.colorize("""\
... index 921100e..8b177e1 100755
... --- a/src/ghdiff.py
... +++ b/src/ghdiff.py
... @@ -10,20 +10,24 @@ def escape(text):
...  default_css = \"\"\"\
...  <style type="text/css">
...  %s
... -</style>\"\"\" % (open(os.path.join(os.path.dirname(__file__), "default.css")).read(),)
... +</style>
... +\"\"\" % (open(os.path.join(os.path.dirname(__file__), "default.css")).read(),)
... +"""))
<style type="text/css">
...
</style>
<div class="diff">
<div class="control">@@&nbsp;-10,20&nbsp;+10,24&nbsp;@@&nbsp;def&nbsp;escape(text):</div>
<div class="">&nbsp;default_css&nbsp;=&nbsp;"""&nbsp;&lt;style&nbsp;type="text/css"&gt;</div>
<div class="">&nbsp;%s</div>
<div class="delete">-&lt;/style&gt;"""&nbsp;%&nbsp;(open(os.path.join(os.path.dirname(__file__),&nbsp;"default.css")).read(),)</div>
<div class="insert">+&lt;/style&gt;</div>
<div class="insert">+"""&nbsp;%&nbsp;(open(os.path.join(os.path.dirname(__file__),&nbsp;"default.css")).read(),)</div>
<div class="insert">+</div>
</div>
Release History

Release History

0.4

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
ghdiff-0.4.tar.gz (5.7 kB) Copy SHA256 Checksum SHA256 Source Jun 13, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting