mirror of https://github.com/cheat/cheat.git
Merge branch 'more_lexers' of git://github.com/cnicolov/cheat into cnicolov-more_lexers
This commit is contained in:
commit
7abb663bf4
|
@ -13,14 +13,23 @@ def colorize(sheet_content):
|
|||
|
||||
try:
|
||||
from pygments import highlight
|
||||
from pygments.lexers import BashLexer
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
from pygments.formatters import TerminalFormatter
|
||||
|
||||
# if pygments can't load, just return the uncolorized text
|
||||
except ImportError:
|
||||
return sheet_content
|
||||
|
||||
return highlight(sheet_content, BashLexer(), TerminalFormatter())
|
||||
first_line = sheet_content.splitlines()[0]
|
||||
lexer = get_lexer_by_name('bash')
|
||||
if first_line.startswith('```'):
|
||||
sheet_content = '\n'.join(sheet_content.split('\n')[1:])
|
||||
try:
|
||||
lexer = get_lexer_by_name(first_line[3:])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return highlight(sheet_content, lexer, TerminalFormatter())
|
||||
|
||||
|
||||
def die(message):
|
||||
|
|
Loading…
Reference in New Issue