md2html: use utf-8 and flush output buffer

Otherwise we get the classic Python UTF-8 errors, and the text is all
out of order. While we're at it, switch to python3 so we only have to
support one set of oddball semantics.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Suggested-by: Daniel Campbell <dlcampbell@gmx.com>
This commit is contained in:
Jason A. Donenfeld 2016-06-17 12:27:10 +02:00
父節點 d88ec849c4
當前提交 7d51120440

查看文件

@ -1,7 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python3
import markdown import markdown
import sys
import io
from pygments.formatters import HtmlFormatter from pygments.formatters import HtmlFormatter
print(''' sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stdout.write('''
<style> <style>
.markdown-body { .markdown-body {
font-size: 14px; font-size: 14px;
@ -279,11 +283,12 @@ print('''
border: none; border: none;
} }
''') ''')
print(HtmlFormatter(style='pastie').get_style_defs('.highlight')) sys.stdout.write(HtmlFormatter(style='pastie').get_style_defs('.highlight'))
print(''' sys.stdout.write('''
</style> </style>
''') ''')
print("<div class='markdown-body'>") sys.stdout.write("<div class='markdown-body'>")
sys.stdout.flush()
# Note: you may want to run this through bleach for sanitization # Note: you may want to run this through bleach for sanitization
markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}}) markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}})
print("</div>") sys.stdout.write("</div>")