From e9e5a267d1a0c9b9470262af8e78b35829290fe1 Mon Sep 17 00:00:00 2001 From: ryanss Date: Sun, 8 Feb 2015 20:20:43 -0500 Subject: Improve handling of job items and Ask HN items --- plugin/hackernews.py | 74 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 12 deletions(-) (limited to 'plugin') diff --git a/plugin/hackernews.py b/plugin/hackernews.py index 9f6f4ba..77f4ab2 100644 --- a/plugin/hackernews.py +++ b/plugin/hackernews.py @@ -110,13 +110,23 @@ def hacker_news_link(external=False): print "HackerNews.vim Error: HTTP Request Timeout" return vim.command("edit .hackernews") - bwrite("%s (%s)" % (item['title'], item['domain'])) - bwrite("%d points by %s %s | %d comments" - % (item['points'], item['user'], item['time_ago'], - item['comments_count'])) - if item['url'].find("item?id=") == 0: - item['url'] = "http://news.ycombinator.com/" + item['url'] - bwrite("[%s]" % item['url']) + if 'domain' in item: + bwrite("%s (%s)" % (item['title'], item['domain'])) + else: + bwrite(item['title']) + if item.get('comments_count', None): + bwrite("%d points by %s %s | %d comments" + % (item['points'], item['user'], item['time_ago'], + item['comments_count'])) + else: + bwrite(item['time_ago']) + if 'url' in item: + if item['url'].find("item?id=") == 0: + item['url'] = "http://news.ycombinator.com/" + item['url'] + bwrite("[%s]" % item['url']) + if 'content' in item: + bwrite("") + print_content(item['content']) bwrite("") bwrite("") print_comments(item['comments']) @@ -157,11 +167,21 @@ def hacker_news_link(external=False): print "HackerNews.vim Error: HTTP Request Timeout" return vim.command("edit .hackernews") - bwrite(item['title']) - bwrite("Posted %s by %s" % (item['time_ago'], item['user'])) - bwrite("%d Points / %d Comments" - % (item['points'], item['comments_count'])) - bwrite("[http://news.ycombinator.com/item?id=" + str(id) + "]") + if 'domain' in item: + bwrite("%s (%s)" % (item['title'], item['domain'])) + else: + bwrite(item['title']) + if item.get('comments_count', None): + bwrite("%d points by %s %s | %d comments" + % (item['points'], item['user'], item['time_ago'], + item['comments_count'])) + else: + bwrite(item['time_ago']) + if 'url' in item: + bwrite("[http://news.ycombinator.com/item?id=" + str(id) + "]") + if 'content' in item: + bwrite("") + print_content(item['content']) bwrite("") bwrite("") print_comments(item['comments']) @@ -193,6 +213,36 @@ def hacker_news_link(external=False): html = HTMLParser.HTMLParser() +def print_content(content): + for p in content.split("
"):
+ if not p:
+ continue
+ p = html.unescape(p)
+
+ # 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"