From ea4da8c18926d28b8a8e9bcbb452d0fe8052f32c Mon Sep 17 00:00:00 2001 From: ryanss Date: Thu, 22 Jan 2015 16:23:43 -0500 Subject: Improve handling of string encoding/decoding --- plugin/hackernews.py | 10 ++++++++-- 1 file 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: -- cgit v1.2.3