about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Hesse <mail@eworm.de>2015-10-12 18:23:56 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2015-10-12 18:36:23 +0200
commit143e65252c1c842774bc5a601d5faef97ca6c886 (patch)
tree2e58322f826f3add63d41b2eb2b0f973d74430ae
parentmd2html: the default of stdin works fine (diff)
downloadcgit-pink-143e65252c1c842774bc5a601d5faef97ca6c886.tar.gz
cgit-pink-143e65252c1c842774bc5a601d5faef97ca6c886.zip
filters: port syntax-highlighting.py to python 3.x
Signed-off-by: Christian Hesse <mail@eworm.de>
Diffstat (limited to '')
-rwxr-xr-xfilters/syntax-highlighting.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index bcf32c8..b5d615e 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -1,6 +1,6 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 
-# This script uses Pygments and Python2. You must have both installed
+# This script uses Pygments and Python3. You must have both installed
 # for this to work.
 #
 # http://pygments.org/
@@ -29,25 +29,24 @@ from pygments.lexers import guess_lexer_for_filename
 from pygments.formatters import HtmlFormatter
 
 
-# read stdin and decode to utf-8. ignore any unkown signs.
-data = sys.stdin.read().decode(encoding='utf-8', errors='ignore')
+data = sys.stdin.read()
 filename = sys.argv[1]
-formatter = HtmlFormatter(encoding='utf-8', style='pastie')
+formatter = HtmlFormatter(style='pastie')
 
 try:
-	lexer = guess_lexer_for_filename(filename, data, encoding='utf-8')
+	lexer = guess_lexer_for_filename(filename, data)
 except ClassNotFound:
 	# check if there is any shebang
 	if data[0:2] == '#!':
-		lexer = guess_lexer(data, encoding='utf-8')
+		lexer = guess_lexer(data)
 	else:
-		lexer = TextLexer(encoding='utf-8')
+		lexer = TextLexer()
 except TypeError:
-	lexer = TextLexer(encoding='utf-8')
+	lexer = TextLexer()
 
 # highlight! :-)
 # printout pygments' css definitions as well
 sys.stdout.write('<style>')
 sys.stdout.write(formatter.get_style_defs('.highlight'))
 sys.stdout.write('</style>')
-highlight(data, lexer, formatter, outfile=sys.stdout)
+sys.stdout.write(highlight(data, lexer, formatter, outfile=None))
;follow=1'>Ignore SIGPIPE in relayJune McEnroe Allows restarting consumers safely. 2019-09-07Add A Memory Called EmpireJune McEnroe 2019-09-05Handle lack of Content-TypeJune McEnroe 2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe Oops, didn't see this. 2019-09-05Decode entities in titlesJune McEnroe 2019-09-05Print title as soon as it's availableJune McEnroe 2019-09-05Use CURL_PREFIX to set flagsJune McEnroe 2019-09-05Add titleJune McEnroe 2019-09-04Add Avorter n'est pas tuerJune McEnroe 2019-08-29Unset executable on shell scriptsJune McEnroe 2019-08-29Add long-missing setopt to bin.7June McEnroe 2019-08-29Add editJune McEnroe