summaryrefslogtreecommitdiff
path: root/watchnews
diff options
context:
space:
mode:
Diffstat (limited to 'watchnews')
-rw-r--r--watchnews/web.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/watchnews/web.py b/watchnews/web.py
index b212349..ab87018 100644
--- a/watchnews/web.py
+++ b/watchnews/web.py
@@ -9,6 +9,7 @@ import difflib
class DiffSupport:
+
def __init__(self):
self.inline_style = False
@@ -20,19 +21,21 @@ class DiffSupport:
def _diff_lines(self, lines1, lines2):
diff = difflib._mdiff(lines1, lines2)
rows = []
+ in_change = False
for ((line1, diff1), (line2, diff2), flag) in diff:
+ if flag ^ in_change:
+ rows.append(html.tr(html.td(' '.join('↔' * 10)),
+ html.td(' '.join('↔' * 10))))
+ in_change = flag
rows.append(html.tr(
- html.th(),
- html.td(line1),
html.td(*self._format_diff(diff1)),
- html.td(line2),
html.td(*self._format_diff(diff2))
))
return html.table(rows, **{'class': 'textdiff'})
-
+
def _format_diff(self, line):
actionclass = {
- '+': 'diff_add',
+ '+': 'diff_add',
'-': 'diff_sub',
'^': 'diff_chg'}
actionname = {
@@ -50,10 +53,11 @@ class DiffSupport:
text = line[nextpos + 2:endpos]
if self.inline_style:
elem = html.span(text)
- elem.xmlname = actionname[line[nextpos+1]]
+ elem.xmlname = actionname[line[nextpos + 1]]
elems += [elem]
else:
- elems += [html.span(text, **{'class':actionclass[line[nextpos+1]]})]
+ elems += [html.span(text, **
+ {'class': actionclass[line[nextpos + 1]]})]
line = line[endpos:]
nextpos = line.find('\x00')
@@ -78,7 +82,7 @@ class Difftable(html.div, DiffSupport):
def single_version(self, version):
self.append(html.table(
html.tr(html.th('Title'), html.td(html.a(version.title,
- href=version.url))),
+ href=version.url))),
html.tr(html.th('Authors'), html.td(version.authors)),
html.tr(html.th('Date'), html.td(
version.created_date.strftime('%x %X'))),
@@ -102,7 +106,7 @@ class Difftable(html.div, DiffSupport):
self.append(html.div(html.table(
html.tr(html.th('Title'),
html.td(html.a(from_difftitle, href=from_version.url)),
- html.td(html.a(to_difftitle, href=to_version.url)),
+ html.td(html.a(to_difftitle, href=to_version.url)),
**{'class': 'textdiff'}),
html.tr(html.th('Authors'),
html.td(from_authors),
@@ -224,4 +228,3 @@ def get_app():
return Template.item(item, list(versions)).string('utf-8')
return app
-