Skip to content

Commit d65df64

Browse files
committed
Added custom TerminalLexer
1 parent c72dde0 commit d65df64

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from pygments.lexer import RegexLexer, bygroups, using
2+
from pygments.token import *
3+
from pygments.lexers.shell import BashLexer, BatchLexer
4+
5+
class TerminalLexer(RegexLexer):
6+
name = 'Terminal'
7+
aliases = ['terminal']
8+
filenames = []
9+
10+
tokens = {
11+
'root': [
12+
('^\$', Generic.Prompt, 'bash-prompt'),
13+
('^[^\n>]+>', Generic.Prompt, 'dos-prompt'),
14+
('^#.+$', Comment.Single),
15+
('^.+$', Generic.Output),
16+
],
17+
'bash-prompt': [
18+
('(.+)$', bygroups(using(BashLexer)), '#pop')
19+
],
20+
'dos-prompt': [
21+
('(.+)$', bygroups(using(BatchLexer)), '#pop')
22+
],
23+
}

_build/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pygments.lexers.special import TextLexer
2525
from pygments.lexers.text import RstLexer
2626
from pygments.lexers.web import PhpLexer
27+
from symfonycom.sphinx.lexer import TerminalLexer
2728

2829
# -- General configuration -----------------------------------------------------
2930

@@ -108,6 +109,7 @@
108109
lexers['rst'] = RstLexer()
109110
lexers['varnish3'] = CLexer()
110111
lexers['varnish4'] = CLexer()
112+
lexers['terminal'] = TerminalLexer()
111113

112114
config_block = {
113115
'markdown': 'Markdown',

0 commit comments

Comments
 (0)