From f8cfab4db9e197a403da6c444de1eb295357c9c3 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 22 Nov 2015 01:36:39 +0100 Subject: generation of rss feed --- watchnews/web.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'watchnews/web.py') diff --git a/watchnews/web.py b/watchnews/web.py index 438e649..05ffcdc 100644 --- a/watchnews/web.py +++ b/watchnews/web.py @@ -9,6 +9,8 @@ import difflib class DiffSupport: + def __init__(self): + self.inline_style = False def _diff(self, line1, line2): diff = list(difflib._mdiff([line1], [line2])) @@ -27,21 +29,31 @@ class DiffSupport: html.td(*self._format_diff(diff2)) )) return html.table(rows, **{'class': 'textdiff'}) - + def _format_diff(self, line): + actionclass = { + '+': 'diff_add', + '-': 'diff_sub', + '^': 'diff_chg'} + actionname = { + '+': 'i', + '-': 'strike', + '^': 'strong'} elems = [] nextpos = line.find("\x00") while nextpos != -1 and nextpos + 1 < len(line): - actionclass = { - '+': 'diff_add', '-': 'diff_sub', - '^': 'diff_chg'}[line[nextpos + 1]] endpos = line.find("\x01", nextpos + 2) if nextpos != 0: # intermediate unchanged text elems += [html.span(line[:nextpos])] text = line[nextpos + 2:endpos] - elems += [html.span(text, **{'class': actionclass})] + if self.inline_style: + elem = html.span(text) + elem.xmlname = actionname[line[nextpos+1]] + elems += [elem] + else: + elems += [html.span(text, **{'class':actionclass[line[nextpos+1]]})] line = line[endpos:] nextpos = line.find("\x00") @@ -53,8 +65,10 @@ class DiffSupport: class Difftable(html.div, DiffSupport): - def __init__(self, to_version, from_version=None): + def __init__(self, to_version, from_version=None, inline_style=False): super().__init__() + self.xmlname = "div" + self.inline_style = inline_style if from_version == None: self.single_version(to_version) else: -- cgit v1.2.1