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>
This commit is contained in:
parent
62da3ebc08
commit
bad8c52ef2
8
utils.py
8
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')
|
||||
|
Loading…
Reference in New Issue
Block a user