summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Kylie McClain <somasis@exherbo.org> 2016-07-21 19:45:42 -0400
committerAvatar Kylie McClain <somasis@exherbo.org> 2016-07-21 19:45:53 -0400
commitf825ab0b1e38cc2a656d8223219e29646f28e68e (patch)
tree29f09c011eb206c2511a7981d487489fb473f5a3
parent83fab3782a8637f3d06b30465837e30a2363908a (diff)
downloadwww-f825ab0b1e38cc2a656d8223219e29646f28e68e.tar.gz
www-f825ab0b1e38cc2a656d8223219e29646f28e68e.tar.xz
filters/syntax-highlighting: use python2 version
-rwxr-xr-xcgit/filters/syntax-highlighting.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/cgit/filters/syntax-highlighting.py b/cgit/filters/syntax-highlighting.py
index a5791c1..eae7cc8 100755
--- a/cgit/filters/syntax-highlighting.py
+++ b/cgit/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/
@@ -30,26 +30,25 @@ from pygments.lexers import guess_lexer_for_filename
from pygments.formatters import HtmlFormatter
-sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
-sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
-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='paraiso-dark')
+formatter = HtmlFormatter(encoding='utf-8', style='paraiso-dark')
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('<style>')
sys.stdout.write(formatter.get_style_defs('.highlight'))
sys.stdout.write('</style>')
-sys.stdout.write(highlight(data, lexer, formatter, outfile=None))
+highlight(data, lexer, formatter, outfile=sys.stdout)