From 9481a557c1ae732f2b194e27a54880cfe8b8737d Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 21 Nov 2010 21:18:57 +0100 Subject: Add a text-based diff view e.g. for display in emails. --- sphinx/websupport/storage/differ.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'sphinx/websupport/storage/differ.py') 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: -- cgit v1.2.1