aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/__init__.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2011-07-28 10:02:38 -0400
committerWaylan Limberg <waylan@gmail.com>2011-07-28 10:02:38 -0400
commit80f6ac599f79546512b522566cb421acea1aca19 (patch)
treeb60ff3b1680a8d79e74fe87d9f12099fc970e089 /markdown/__init__.py
parent5ad27f85db3e5c0a0e6f05ab099bfbfc8b0d0dd5 (diff)
downloadmarkdown-80f6ac599f79546512b522566cb421acea1aca19.tar.gz
markdown-80f6ac599f79546512b522566cb421acea1aca19.tar.bz2
markdown-80f6ac599f79546512b522566cb421acea1aca19.zip
All internal encoding of output now uses the 'xmlcharrefreplace' error handler. Also added a note to the docs. Anyone doing their own encoding of output should be as well.
Diffstat (limited to 'markdown/__init__.py')
-rw-r--r--markdown/__init__.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py
index 562ee5f..630198e 100644
--- a/markdown/__init__.py
+++ b/markdown/__init__.py
@@ -311,7 +311,8 @@ class Markdown:
Decodes the file using the provided encoding (defaults to utf-8),
passes the file content to markdown, and outputs the html to either
the provided stream or the file with provided name, using the same
- encoding as the source file.
+ encoding as the source file. The 'xmlcharrefreplace' error handler is
+ used when encoding the output.
**Note:** This is the only place that decoding and encoding of unicode
takes place in Python-Markdown. (All other code is unicode-in /
@@ -341,11 +342,13 @@ class Markdown:
# Write to file or stdout
if isinstance(output, (str, unicode)):
- output_file = codecs.open(output, "w", encoding=encoding)
+ output_file = codecs.open(output, "w",
+ encoding=encoding,
+ errors="xmlcharrefreplace")
output_file.write(html)
output_file.close()
else:
- output.write(html.encode(encoding))
+ output.write(html.encode(encoding, errors="xmlcharrefreplace"))
return self