1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """Pygments lexer for our custom shell example sessions.
23
24 The lexer support the following custom markup:
25
26 - comments: # this is a comment
27 - command lines: '$ ' at the beginning of a line denotes a command
28 - variable input: %input% (works in both commands and screen output)
29 - otherwise, regular text output from commands will be plain
30
31 """
32
33 from pygments.lexer import RegexLexer, bygroups, include
34 from pygments.token import Name, Text, Generic, Comment
35
36
38 name = "ShellExampleLexer"
39 aliases = "shell-example"
40 filenames = []
41
42 tokens = {
43 "root": [
44 include("comments"),
45 include("userinput"),
46
47 (r"^\$ ", Text, "input"),
48 (r"\s+", Text),
49 (r"[^#%\s\\]+", Text),
50 (r"\\", Text),
51 ],
52 "input": [
53 include("comments"),
54 include("userinput"),
55 (r"[^#%\s\\]+", Generic.Strong),
56 (r"\\\n", Generic.Strong),
57 (r"\\", Generic.Strong),
58
59 (r"\n", Text, "#pop"),
60 (r"\s+", Text),
61 ],
62 "comments": [
63 (r"#.*\n", Comment.Single),
64 ],
65 "userinput": [
66 (r"(\\)(%)", bygroups(None, Text)),
67 (r"(%)([^%]*)(%)", bygroups(None, Name.Variable, None)),
68 ],
69 }
70
71
74