summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorryanss2015-01-22 16:23:43 -0500
committerryanss2015-01-22 16:23:43 -0500
commitea4da8c18926d28b8a8e9bcbb452d0fe8052f32c (patch)
tree2a085bb44a3c307d96d01ca2a127251f5c7bcfa3 /plugin
parent478e8c306e887f2228c9e52c24948785a9a2a243 (diff)
downloadvim-hn-ea4da8c18926d28b8a8e9bcbb452d0fe8052f32c.tar.gz
Improve handling of string encoding/decoding
Diffstat (limited to 'plugin')
-rw-r--r--plugin/hackernews.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/plugin/hackernews.py b/plugin/hackernews.py
index e46d2a9..900d3d5 100644
--- a/plugin/hackernews.py
+++ b/plugin/hackernews.py
@@ -14,11 +14,17 @@ def bwrite(s):
# Never write more than two blank lines in a row
if not s.strip() and not b[-1].strip() and not b[-2].strip():
return
+
+ # Vim buffer.append() cannot accept unicode type,
+ # must first encode to UTF-8 string
+ if isinstance(s, unicode):
+ s = s.encode('utf-8', errors='replace')
+
# Code block markers for syntax highlighting
- if s and s[-1] == unichr(160):
+ if s and s[-1] == unichr(160).encode('utf-8'):
b[-1] = s
return
- s = s.encode('utf-8')
+
if not b[0]:
b[0] = s
else: