Skip to content

Commit

Permalink
Fixed UnicodeEncodeError when output from markdown_py is piped into a…
Browse files Browse the repository at this point in the history
…nother program.

In this case text should be encoded into the output encoding explicitly, because
sys.stdout.encoding is None, when piping data.
  • Loading branch information
svetlyak40wt committed Jul 26, 2012
1 parent d13c203 commit 1132f9e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ def convertFile(self, input=None, output=None, encoding=None):
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

Expand Down

0 comments on commit 1132f9e

Please sign in to comment.