forked from pygments/pygments-plugin-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_lexer.py
66 lines (60 loc) · 1.86 KB
/
example_lexer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""An example plugin lexer for Pygments."""
from pygments.lexer import RegexLexer
from pygments.token import Keyword, Text
class ExampleLexer(RegexLexer):
# This should be the human-readable name of the language. In this example,
# doing
#
# pygments.lexers.find_lexer_class("Pygments Plugin Example Language")
#
# will return the ExampleLexer class.
name = "Pygments Plugin Example Language"
# This is a list of names that can be used to select the language.
# In this example, we can call the pygmentize command as
#
# pygmentize -l example-lang
#
# Also, doing
#
# pygments.lexers.find_lexer_class_by_name("example-lang")
#
# in Python will find the lexer class. This is what many documentation or
# site generation tools implicitly do with code blocks, e.g., this in Sphinx
# reST:
#
# .. code-block:: example-lang
#
# your code here
#
# or this in Markdown:
#
# ```example-lang
# your code here
# ```
#
aliases = ["example-lang"]
# This is a list of file patterns that will automatically be highlighted
# with this lexer. In this example, calling
#
# pygmentize file.exmpl
#
# will automatically highlight file.exmpl with this lexer, without needing
# to pass `-l example-lang`. Similarly,
#
# pygments.lexers.find_lexer_class_for_filename("file.exmpl")
#
# will return the ExampleLexer class.
filenames = ["*.exmpl"]
# This is a list of MIME types for the language. In this example,
#
# pygments.lexers.get_lexer_for_mimetype("text/x-exmpl")
#
# will return the ExampleLexer class.
mimetypes = ["text/x-exmpl"]
# This lexer highlights lines that read "foo".
tokens = {
'root': [
(r'foo\n', Keyword),
(r'.*\n', Text),
]
}