diff options
| author | ryanss | 2015-02-19 22:25:36 -0500 |
|---|---|---|
| committer | ryanss | 2015-02-19 22:25:36 -0500 |
| commit | 67a4d9db6193d11527ccc9c096a1778be74d52f5 (patch) | |
| tree | c289e0bab1fe66918ef2de221ec6948ca02542dc | |
| parent | 2b910b5b03517711188ae8aed0cb510cc7b8679f (diff) | |
| download | vim-hn-67a4d9db6193d11527ccc9c096a1778be74d52f5.tar.gz | |
Improve handling of html tags in comments
Fixes errors trying to view comments for item=8955426
| -rw-r--r-- | ftplugin/hackernews.py | 35 | ||||
| -rw-r--r-- | syntax/hackernews.vim | 4 |
2 files changed, 24 insertions, 15 deletions
diff --git a/ftplugin/hackernews.py b/ftplugin/hackernews.py index 8480979..cbbbc2c 100644 --- a/ftplugin/hackernews.py +++ b/ftplugin/hackernews.py @@ -246,15 +246,18 @@ def print_content(content): section = p[:s] m = re.search(r"<a.*href=[\"\']([^\"\']*)[\"\'].*>(.*)</a>", section) - # Do not bother with anchor text if it is same as href url - if m.group(1)[:20] == m.group(2)[:20]: - p = p.replace(m.group(0), "[%s]" % m.group(1)) + if m: + # Do not bother with anchor text if it is same as href url + if m.group(1)[:20] == m.group(2)[:20]: + p = p.replace(m.group(0), "[%s]" % m.group(1)) + else: + p = p.replace(m.group(0), + "(%s)[%s]" % (m.group(2), m.group(1))) + s = p.find("a>") else: - p = p.replace(m.group(0), - "(%s)[%s]" % (m.group(2), m.group(1))) - s = p.find("a>") + s = p.find("a>", s) - contents = textwrap.wrap(re.sub('<[^<]+?>', '', p), width=80) + contents = textwrap.wrap(re.sub(p), width=80) for line in contents: if line.strip(): bwrite(line) @@ -287,16 +290,18 @@ def print_comments(comments): section = p[:s] m = re.search(r"<a.*href=[\"\']([^\"\']*)[\"\'].*>(.*)</a>", section) - # Do not bother with anchor text if it is same as href url - if m.group(1)[:20] == m.group(2)[:20]: - p = p.replace(m.group(0), "[%s]" % m.group(1)) + if m: + # Do not bother with anchor text if it is same as href url + if m.group(1)[:20] == m.group(2)[:20]: + p = p.replace(m.group(0), "[%s]" % m.group(1)) + else: + p = p.replace(m.group(0), + "(%s)[%s]" % (m.group(2), m.group(1))) + s = p.find("a>") else: - p = p.replace(m.group(0), - "(%s)[%s]" % (m.group(2), m.group(1))) - s = p.find("a>") + s = p.find("a>", s) - contents = textwrap.wrap(re.sub('<[^<]+?>', '', p), - width=80, + contents = textwrap.wrap(p, width=80, initial_indent=" "*4*level, subsequent_indent=" "*4*level) for line in contents: diff --git a/syntax/hackernews.vim b/syntax/hackernews.vim index 4555b9d..7525ed2 100644 --- a/syntax/hackernews.vim +++ b/syntax/hackernews.vim @@ -43,6 +43,10 @@ syn match Comment /^\s*Comment\sby.\+ago:$/ " Highlight links syn region Constant start="\[http" end="\]" +" Italics <i> tags +syn region Italics start="<i>" end="</i>" +highlight Italics gui=italic + " Highlight code blocks syn region Statement start="^ " end="^ " |
