1
from pygments.lexers.web import \
2
HtmlLexer, XmlLexer, JavascriptLexer, CssLexer
3
from pygments.lexers.agile import PythonLexer
4
from pygments.lexer import DelegatingLexer, RegexLexer, bygroups, \
6
from pygments.token import \
7
Text, Comment, Operator, Keyword, Name, String, Other
9
class MakoLexer(RegexLexer):
16
(r'(\s*)(\%)(\s*end(?:\w+))(\n|\Z)',
17
bygroups(Text, Comment.Preproc, Keyword, Other)),
18
(r'(\s*)(\%)([^\n]*)(\n|\Z)',
19
bygroups(Text, Comment.Preproc, using(PythonLexer), Other)),
20
(r'(\s*)(##[^\n]*)(\n|\Z)',
21
bygroups(Text, Comment.Preproc, Other)),
22
(r'''(?s)<%doc>.*?</%doc>''', Comment.Preproc),
23
(r'(<%)(def|call|namespace|text)', bygroups(Comment.Preproc, Name.Builtin), 'tag'),
24
(r'(</%)(def|call|namespace|text)(>)', bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc)),
25
(r'<%(?=(include|inherit|namespace|page))', Comment.Preproc, 'ondeftags'),
26
(r'(<%(?:!?))(.*?)(%>)(?s)', bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
28
bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
30
(.+?) # anything, followed by:
32
(?<=\n)(?=%|\#\#) | # an eval or comment line
33
(?=\#\*) | # multiline comment
34
(?=</?%) | # a python block
36
(?=\$\{) | # a substitution
39
(\\\n) | # an escaped newline
42
''', bygroups(Other, Operator)),
46
(r'<%', Comment.Preproc),
47
(r'(?<=<%)(include|inherit|namespace|page)', Name.Builtin),
51
(r'((?:\w+)\s*=)\s*(".*?")',
52
bygroups(Name.Attribute, String)),
53
(r'/?\s*>', Comment.Preproc, '#pop'),
57
('".*?"', String, '#pop'),
58
("'.*?'", String, '#pop'),
59
(r'[^\s>]+', String, '#pop'),
64
class MakoHtmlLexer(DelegatingLexer):
66
aliases = ['html+mako']
68
def __init__(self, **options):
69
super(MakoHtmlLexer, self).__init__(HtmlLexer, MakoLexer,
72
class MakoXmlLexer(DelegatingLexer):
74
aliases = ['xml+mako']
76
def __init__(self, **options):
77
super(MakoXmlLexer, self).__init__(XmlLexer, MakoLexer,
80
class MakoJavascriptLexer(DelegatingLexer):
81
name = 'JavaScript+Mako'
82
aliases = ['js+mako', 'javascript+mako']
84
def __init__(self, **options):
85
super(MakoJavascriptLexer, self).__init__(JavascriptLexer,
88
class MakoCssLexer(DelegatingLexer):
90
aliases = ['css+mako']
92
def __init__(self, **options):
93
super(MakoCssLexer, self).__init__(CssLexer, MakoLexer,