List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] Correct md2html's output order
@ 2016-05-21 10:25 dlcampbell
  0 siblings, 0 replies; only message in thread
From: dlcampbell @ 2016-05-21 10:25 UTC (permalink / raw)


Corrects md2html's output order by setting two Python-centric
environment variables before calling it. This ensures two things:

* The io streams are UTF-8, which Python 3 handles natively
* Unbuffered output will create the expected behavior by flushing on
  print() instead of embedding the expected HTML in the <style>
  element due to Python's automatic buffering.
---
 filters/about-formatting.sh     | 7 ++++++-
 filters/html-converters/md2html | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/filters/about-formatting.sh b/filters/about-formatting.sh
index 85daf9c..7e09be6 100755
--- a/filters/about-formatting.sh
+++ b/filters/about-formatting.sh
@@ -19,7 +19,12 @@
 
 cd "$(dirname $0)/html-converters/"
 case "$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" in
-	*.markdown|*.mdown|*.md|*.mkd) exec ./md2html; ;;
+	*.markdown|*.mdown|*.md|*.mkd)
+		# Ensure Python is using a UTF-8 stream
+		export PYTHONIOENCODING="utf-8"
+		# Force Python to flush buffers when printing to stdout
+		export PYTHONUNBUFFERED="true"
+		exec ./md2html; ;;
 	*.rst) exec ./rst2html; ;;
 	*.[1-9]) exec ./man2html; ;;
 	*.htm|*.html) exec cat; ;;
diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html
index c8ee7d9..9911523 100755
--- a/filters/html-converters/md2html
+++ b/filters/html-converters/md2html
@@ -281,9 +281,9 @@ print('''
 ''')
 print(HtmlFormatter(style='pastie').get_style_defs('.highlight'))
 print('''
-</style>   
+</style>
+<div class="markdown-body">
 ''')
-print("<div class='markdown-body'>")
 # 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("</div>")
-- 
2.8.2



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-05-21 10:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-21 10:25 [PATCH] Correct md2html's output order dlcampbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).