mirror of
https://github.com/Erreur32/cheat.git
synced 2024-12-22 21:52:12 +01:00
Adds support for more lexers
If you use cheat to save some programming snippets this might be useful. For example if you have a long list of SQL Query cheats, you can do the following: Enter ```sql in the beginning of the file containing the cheats content. Example file: sql ```sql SELECT 17 & 16 = 16; SELECT 2+4+8+16 & 1 = 0;
This commit is contained in:
parent
b6137cac8b
commit
c1fbeffde5
1 changed files with 11 additions and 2 deletions
|
@ -12,14 +12,23 @@ def colorize(sheet_content):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
from pygments.lexers import BashLexer
|
from pygments.lexers import get_lexer_by_name
|
||||||
from pygments.formatters import TerminalFormatter
|
from pygments.formatters import TerminalFormatter
|
||||||
|
|
||||||
# if pygments can't load, just return the uncolorized text
|
# if pygments can't load, just return the uncolorized text
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return sheet_content
|
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):
|
def die(message):
|
||||||
|
|
Loading…
Reference in a new issue