diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2015-11-22 01:36:39 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2015-11-22 01:36:39 +0100 |
commit | f8cfab4db9e197a403da6c444de1eb295357c9c3 (patch) | |
tree | 1ed6772d966c68f4e457c4a2612ef256d01a4efb /watchnews/web.py | |
parent | 6080b38fb2b6b3c1017bdd34bb7552bc7e26a4a0 (diff) | |
download | watchnews-f8cfab4db9e197a403da6c444de1eb295357c9c3.tar.gz watchnews-f8cfab4db9e197a403da6c444de1eb295357c9c3.zip |
generation of rss feed
Diffstat (limited to 'watchnews/web.py')
-rw-r--r-- | watchnews/web.py | 26 |
1 files changed, 20 insertions, 6 deletions
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: |