diff options
author | Georg Brandl <georg@python.org> | 2010-11-21 21:18:57 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-11-21 21:18:57 +0100 |
commit | 9481a557c1ae732f2b194e27a54880cfe8b8737d (patch) | |
tree | 6788752a3a934ebee286f4a36b81534ac5c6738f /sphinx/websupport/storage/differ.py | |
parent | 9a3a3df917ce1fd513b874e974f0e4f21bff6229 (diff) | |
download | sphinx-git-9481a557c1ae732f2b194e27a54880cfe8b8737d.tar.gz |
Add a text-based diff view e.g. for display in emails.
Diffstat (limited to 'sphinx/websupport/storage/differ.py')
-rw-r--r-- | sphinx/websupport/storage/differ.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/sphinx/websupport/storage/differ.py b/sphinx/websupport/storage/differ.py index 8e430a137..10b76b345 100644 --- a/sphinx/websupport/storage/differ.py +++ b/sphinx/websupport/storage/differ.py @@ -20,19 +20,25 @@ class CombinedHtmlDiff(object): """ highlight_regex = re.compile(r'([\+\-\^]+)') - def make_html(self, source, proposal): + def __init__(self, source, proposal): + proposal = escape(proposal) + + differ = Differ() + self.diff = list(differ.compare(source.splitlines(1), + proposal.splitlines(1))) + + def make_text(self): + return '\n'.join(self.diff) + + def make_html(self): """Return the HTML representation of the differences between `source` and `proposal`. :param source: the original text :param proposal: the proposed text """ - proposal = escape(proposal) - - differ = Differ() - diff = list(differ.compare(source.splitlines(1), - proposal.splitlines(1))) html = [] + diff = self.diff[:] line = diff.pop(0) next = diff.pop(0) while True: |