diff options
author | Jason A. Donenfeld | 2016-06-17 12:27:10 +0200 |
---|---|---|
committer | Jason A. Donenfeld | 2016-06-17 12:28:03 +0200 |
commit | 7d51120440346108aad74f007431ad65b307f6d7 (patch) | |
tree | 17e4a4f0e7df7998848906aad00576181fac266b | |
parent | d88ec849c4f7af41a8a41af1a4f79a2b4d41717a (diff) | |
download | cgit-7d51120440346108aad74f007431ad65b307f6d7.tar.gz cgit-7d51120440346108aad74f007431ad65b307f6d7.tar.bz2 cgit-7d51120440346108aad74f007431ad65b307f6d7.zip |
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>
-rwxr-xr-x | filters/html-converters/md2html | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index c8ee7d9..ebf3856 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html | |||
@@ -1,7 +1,11 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
2 | import markdown | 2 | import markdown |
3 | import sys | ||
4 | import io | ||
3 | from pygments.formatters import HtmlFormatter | 5 | from pygments.formatters import HtmlFormatter |
4 | print(''' | 6 | sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') |
7 | sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') | ||
8 | sys.stdout.write(''' | ||
5 | <style> | 9 | <style> |
6 | .markdown-body { | 10 | .markdown-body { |
7 | font-size: 14px; | 11 | font-size: 14px; |
@@ -279,11 +283,12 @@ print(''' | |||
279 | border: none; | 283 | border: none; |
280 | } | 284 | } |
281 | ''') | 285 | ''') |
282 | print(HtmlFormatter(style='pastie').get_style_defs('.highlight')) | 286 | sys.stdout.write(HtmlFormatter(style='pastie').get_style_defs('.highlight')) |
283 | print(''' | 287 | sys.stdout.write(''' |
284 | </style> | 288 | </style> |
285 | ''') | 289 | ''') |
286 | print("<div class='markdown-body'>") | 290 | sys.stdout.write("<div class='markdown-body'>") |
291 | sys.stdout.flush() | ||
287 | # Note: you may want to run this through bleach for sanitization | 292 | # Note: you may want to run this through bleach for sanitization |
288 | markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}}) | 293 | markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}}) |
289 | print("</div>") | 294 | sys.stdout.write("</div>") |