From 9a9109d189d2fe00d707cbf39d0ec32f016a5a27 Mon Sep 17 00:00:00 2001 From: ryanss Date: Tue, 17 Mar 2015 23:59:00 -0400 Subject: Refactor duplicate code in print functions --- ftplugin/hackernews.py | 47 ++++++++--------------------------------------- 1 file changed, 8 insertions(+), 39 deletions(-) (limited to 'ftplugin') diff --git a/ftplugin/hackernews.py b/ftplugin/hackernews.py index a57ae9c..37f1e05 100644 --- a/ftplugin/hackernews.py +++ b/ftplugin/hackernews.py @@ -188,7 +188,7 @@ def link(external=False): bwrite("[http://news.ycombinator.com/item?id=%s]" % item_id) if 'content' in item: bwrite("") - print_content(item['content']) + print_comments([dict(content=item['content'])]) if 'poll' in item: bwrite("") max_score = max((c['points'] for c in item['poll'])) @@ -249,45 +249,13 @@ def recall_pos(): vim.current.window.cursor = (int(mark[0]), int(mark[1])) -def print_content(content): - for p in content.split("
"):
- if not p:
- continue
- p = html.unescape(p)
- p = p.replace("", "_").replace("", "_")
-
- # Convert Text tags
- # to markdown equivalent: (Text)[http://url/]
- s = p.find("a>")
- while s > 0:
- s += 2
- section = p[:s]
- m = re.search(r" "):
if not p:
continue
@@ -336,4 +304,5 @@ def print_comments(comments, level=0):
if contents and line.strip():
bwrite("")
bwrite("")
- print_comments(comment['comments'], level+1)
+ if 'comments' in comment:
+ print_comments(comment['comments'], level+1)
--
cgit v1.2.3