From 7d51120440346108aad74f007431ad65b307f6d7 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 17 Jun 2016 12:27:10 +0200 Subject: [PATCH] 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 Suggested-by: Daniel Campbell --- filters/html-converters/md2html | 17 +++++++++++------ 1 file 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 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import markdown +import sys +import io 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(''' ''') -print("
") +sys.stdout.write("
") +sys.stdout.flush() # 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"}}) -print("
") +sys.stdout.write("
")