From 1132f9e20cd7a5d6be809651f1034c44c32dbc0e Mon Sep 17 00:00:00 2001 From: Alexander Artemenko Date: Thu, 26 Jul 2012 12:52:37 +0400 Subject: Fixed UnicodeEncodeError when output from markdown_py is piped into another program. In this case text should be encoded into the output encoding explicitly, because sys.stdout.encoding is None, when piping data. --- markdown/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/markdown/__init__.py b/markdown/__init__.py index 149ec30..b637c88 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -373,7 +373,8 @@ class Markdown: output_file.write(html) # Don't close here. User may want to write more. else: - sys.stdout.write(html) + stdout = codecs.getwriter(encoding)(sys.stdout, errors="xmlcharrefreplace") + stdout.write(html) return self -- cgit v1.2.3