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">@@ -1,2 +1,2 @@
</div>
<div class="delete">-a</div>
<div class=""> 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">@@ -1,2 +1,2 @@
</div>
<div class="delete">-blah <span class="highlight">blah</span> blah</div>
<div class="insert">+blah <span class="highlight">zxqq</span> blah</div>
<div class=""> 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">@@ -1,2 +1,2 @@
</div>
<div class="delete">-blah <span class="highlight">blah</span> blah</div>
<div class="insert">+blah <span class="highlight">zxqq</span> blah</div>
<div class=""> 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">@@ -10,20 +10,24 @@ def escape(text):</div>
<div class=""> default_css = """ <style type="text/css"></div>
<div class=""> %s</div>
<div class="delete">-</style>""" % (open(os.path.join(os.path.dirname(__file__), "default.css")).read(),)</div>
<div class="insert">+</style></div>
<div class="insert">+""" % (open(os.path.join(os.path.dirname(__file__), "default.css")).read(),)</div>
<div class="insert">+</div>
</div>
Metadata
Release files for ghdiff 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ghdiff-0.4.tar.gz | 5.7 kB | Without provenance | Details for ghdiff-0.4.tar.gz |
Release files / ghdiff-0.4.tar.gz
| Download URL | ghdiff-0.4.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13cf6a4fa6d7b7137e0734c69ed22ff1ca76108350ce8cb03d0124ac4584ad9e
|
|
BLAKE2b-256 checksum How to use checksums |
305b68b45b8fc943d851bdc2bff5f0c686d75340432b60ff042ab5f8399ed2f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ghdiff 0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.