From 87dca2dd53804808f2ac46873b8eead2bd948f67 Mon Sep 17 00:00:00 2001 From: lookshe Date: Thu, 14 Jan 2016 20:34:09 +0100 Subject: reverted syntax-hightling.py to python2 --- filters/syntax-highlighting.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py index b5d615e..bcf32c8 100755 --- a/filters/syntax-highlighting.py +++ b/filters/syntax-highlighting.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python2 -# This script uses Pygments and Python3. You must have both installed +# This script uses Pygments and Python2. You must have both installed # for this to work. # # http://pygments.org/ @@ -29,24 +29,25 @@ from pygments.lexers import guess_lexer_for_filename from pygments.formatters import HtmlFormatter -data = sys.stdin.read() +# read stdin and decode to utf-8. ignore any unkown signs. +data = sys.stdin.read().decode(encoding='utf-8', errors='ignore') filename = sys.argv[1] -formatter = HtmlFormatter(style='pastie') +formatter = HtmlFormatter(encoding='utf-8', style='pastie') try: - lexer = guess_lexer_for_filename(filename, data) + lexer = guess_lexer_for_filename(filename, data, encoding='utf-8') except ClassNotFound: # check if there is any shebang if data[0:2] == '#!': - lexer = guess_lexer(data) + lexer = guess_lexer(data, encoding='utf-8') else: - lexer = TextLexer() + lexer = TextLexer(encoding='utf-8') except TypeError: - lexer = TextLexer() + lexer = TextLexer(encoding='utf-8') # highlight! :-) # printout pygments' css definitions as well sys.stdout.write('') -sys.stdout.write(highlight(data, lexer, formatter, outfile=None)) +highlight(data, lexer, formatter, outfile=sys.stdout) -- cgit v1.2.3