summaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorAlberto Bertogli <albertito@blitiri.com.ar>2012-11-18 11:39:45 +0100
committerAlberto Bertogli <albertito@blitiri.com.ar>2012-11-18 15:55:27 +0100
commitbad8c52ef2712ac89ec9626c4788727553aa3096 (patch)
tree2a55d04a90b841483fc33ba35cb4f7701c5924ad /utils.py
parent62da3ebc08949d60a9d7b6ce84d9fe6ed68110db (diff)
downloadgit-arr-fork-bad8c52ef2712ac89ec9626c4788727553aa3096.zip
Fall back to guess the lexer by content
If we can't guess the lexer by the file name, try to guess based on the content. This allows pygments to colorize extension-less files, usually scripts. Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/utils.py b/utils.py
index cee4bb7..039d02b 100644
--- a/utils.py
+++ b/utils.py
@@ -50,9 +50,13 @@ def colorize_diff(s):
def colorize_blob(fname, s):
try:
- lexer = lexers.guess_lexer_for_filename(fname, s)
+ lexer = lexers.guess_lexer_for_filename(fname, s, encoding = 'utf-8')
except lexers.ClassNotFound:
- lexer = lexers.TextLexer(encoding = 'utf-8')
+ try:
+ lexer = lexers.guess_lexer(s[:200], encoding = 'utf-8')
+ except lexers.ClassNotFound:
+ lexer = lexers.TextLexer(encoding = 'utf-8')
+
formatter = HtmlFormatter(encoding = 'utf-8',
cssclass = 'source_code',
linenos = 'table')