List for cgit developers and users
 help / color / mirror / Atom feed
From: list at eworm.de (Christian Hesse)
Subject: [PATCH 1/1] filters: port syntax-highlighting.py to python 3.x
Date: Mon, 12 Oct 2015 18:23:56 +0200	[thread overview]
Message-ID: <1444667036-28065-1-git-send-email-list@eworm.de> (raw)

From: Christian Hesse <mail at eworm.de>

Signed-off-by: Christian Hesse <mail at eworm.de>
---
 filters/syntax-highlighting.py | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index bcf32c8..a7ebf18 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 
 # This script uses Pygments and Python2. You must have both installed
 # for this to work.
@@ -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))
-- 
2.6.1



             reply	other threads:[~2015-10-12 16:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-12 16:23 list [this message]
2015-10-12 16:36 ` Jason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1444667036-28065-1-git-send-email-list@eworm.de \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).