aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Artemenko <svetlyak.40wt@gmail.com>2012-07-26 12:52:37 +0400
committerAlexander Artemenko <svetlyak.40wt@gmail.com>2012-07-26 12:59:52 +0400
commit1132f9e20cd7a5d6be809651f1034c44c32dbc0e (patch)
treee71b36e68512320b93ed7e8c4c32cd8181b16d34
parentd13c203052a8b22a92b9e096e03005bff40013d2 (diff)
downloadmarkdown-1132f9e20cd7a5d6be809651f1034c44c32dbc0e.tar.gz
markdown-1132f9e20cd7a5d6be809651f1034c44c32dbc0e.tar.bz2
markdown-1132f9e20cd7a5d6be809651f1034c44c32dbc0e.zip
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.
-rw-r--r--markdown/__init__.py3
1 files changed, 2 insertions, 1 deletions
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