35
30
'JavascriptDjangoLexer', 'GenshiLexer', 'HtmlGenshiLexer',
36
31
'GenshiTextLexer', 'CssGenshiLexer', 'JavascriptGenshiLexer',
37
32
'MyghtyLexer', 'MyghtyHtmlLexer', 'MyghtyXmlLexer',
38
'MyghtyCssLexer', 'MyghtyJavascriptLexer', 'MakoLexer',
33
'MyghtyCssLexer', 'MyghtyJavascriptLexer', 'MasonLexer', 'MakoLexer',
39
34
'MakoHtmlLexer', 'MakoXmlLexer', 'MakoJavascriptLexer',
40
35
'MakoCssLexer', 'JspLexer', 'CheetahLexer', 'CheetahHtmlLexer',
41
'CheetahXmlLexer', 'CheetahJavascriptLexer']
36
'CheetahXmlLexer', 'CheetahJavascriptLexer',
37
'EvoqueLexer', 'EvoqueHtmlLexer', 'EvoqueXmlLexer',
38
'ColdfusionLexer', 'ColdfusionHtmlLexer',
39
'VelocityLexer', 'VelocityHtmlLexer', 'VelocityXmlLexer',
44
43
class ErbLexer(Lexer):
193
class VelocityLexer(RegexLexer):
195
Generic `Velocity <http://velocity.apache.org/>`_ template lexer.
197
Just highlights velocity directives and variable references, other
198
data is left untouched by the lexer.
202
aliases = ['velocity']
203
filenames = ['*.vm','*.fhtml']
205
flags = re.MULTILINE | re.DOTALL
207
identifier = r'[a-zA-Z_][a-zA-Z0-9_]*'
213
bygroups(Comment.Preproc, Comment, Comment.Preproc)),
215
bygroups(Comment.Preproc, Comment)),
216
(r'(#\{?)(' + identifier + r')(\}?)(\s?\()',
217
bygroups(Comment.Preproc, Name.Function, Comment.Preproc, Punctuation),
219
(r'(#\{?)(' + identifier + r')(\}|\b)',
220
bygroups(Comment.Preproc, Name.Function, Comment.Preproc)),
221
(r'\$\{?', Punctuation, 'variable')
224
(identifier, Name.Variable),
225
(r'\(', Punctuation, 'funcparams'),
226
(r'(\.)(' + identifier + r')', bygroups(Punctuation, Name.Variable), '#push'),
227
(r'\}', Punctuation, '#pop'),
231
(r'(&&|\|\||==?|!=?|[-<>+*%&\|\^/])|\b(eq|ne|gt|lt|ge|le|not|in)\b', Operator),
232
(r'\[', Operator, 'rangeoperator'),
233
(r'\b' + identifier + r'\b', Name.Function),
234
include('funcparams')
238
include('funcparams'),
239
(r'\]', Operator, '#pop')
242
(r'\$\{?', Punctuation, 'variable'),
245
(r'"(\\\\|\\"|[^"])*"', String.Double),
246
(r"'(\\\\|\\'|[^'])*'", String.Single),
247
(r"0[xX][0-9a-fA-F]+[Ll]?", Number),
248
(r"\b[0-9]+\b", Number),
249
(r'(true|false|null)\b', Keyword.Constant),
250
(r'\(', Punctuation, '#push'),
251
(r'\)', Punctuation, '#pop')
255
def analyse_text(text):
257
if re.search(r'#\{?macro\}?\(.*?\).*?#\{?end\}?', text):
259
if re.search(r'#\{?if\}?\(.+?\).*?#\{?end\}?', text):
261
if re.search(r'#\{?foreach\}?\(.+?\).*?#\{?end\}?', text):
263
if re.search(r'\$\{?[a-zA-Z_][a-zA-Z0-9_]*(\([^)]*\))?(\.[a-zA-Z0-9_]+(\([^)]*\))?)*\}?', text):
268
class VelocityHtmlLexer(DelegatingLexer):
270
Subclass of the `VelocityLexer` that highlights unlexer data
271
with the `HtmlLexer`.
275
name = 'HTML+Velocity'
276
aliases = ['html+velocity']
277
alias_filenames = ['*.html','*.fhtml']
278
mimetypes = ['text/html+velocity']
280
def __init__(self, **options):
281
super(VelocityHtmlLexer, self).__init__(HtmlLexer, VelocityLexer,
285
class VelocityXmlLexer(DelegatingLexer):
287
Subclass of the `VelocityLexer` that highlights unlexer data
292
name = 'XML+Velocity'
293
aliases = ['xml+velocity']
294
alias_filenames = ['*.xml','*.vm']
295
mimetypes = ['application/xml+velocity']
297
def __init__(self, **options):
298
super(VelocityXmlLexer, self).__init__(XmlLexer, VelocityLexer,
301
def analyse_text(text):
302
rv = VelocityLexer.analyse_text(text) - 0.01
303
if looks_like_xml(text):
194
308
class DjangoLexer(RegexLexer):
196
310
Generic `django <http://www.djangoproject.com/documentation/templates/>`_
239
353
bygroups(Keyword, Text, Keyword, Text, Name.Function)),
240
354
(r'(_|true|false|none|True|False|None)\b', Keyword.Pseudo),
241
355
(r'(in|as|reversed|recursive|not|and|or|is|if|else|import|'
242
r'with(?:(?:out)?\s*context)?)\b', Keyword),
356
r'with(?:(?:out)?\s*context)?|scoped|ignore\s+missing)\b',
243
358
(r'(loop|block|super|forloop)\b', Name.Builtin),
244
(r'[a-zA-Z][a-zA-Z0-9_]*', Name.Variable),
359
(r'[a-zA-Z][a-zA-Z0-9_-]*', Name.Variable),
245
360
(r'\.[a-zA-Z0-9_]+', Name.Variable),
246
361
(r':?"(\\\\|\\"|[^"])*"', String.Double),
247
362
(r":?'(\\\\|\\'|[^'])*'", String.Single),
248
(r'([{}()\[\]+\-*/,:]|[><=]=?)', Operator),
363
(r'([{}()\[\]+\-*/,:~]|[><=]=?)', Operator),
249
364
(r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
250
365
r"0[xX][0-9a-fA-F]+[Ll]?", Number),
509
class MasonLexer(RegexLexer):
511
Generic `mason templates`_ lexer. Stolen from Myghty lexer. Code that isn't
512
Mason markup is HTML.
514
.. _mason templates: http://www.masonhq.com/
516
*New in Pygments 1.4.*
520
filenames = ['*.m', '*.mhtml', '*.mc', '*.mi', 'autohandler', 'dhandler']
521
mimetypes = ['application/x-mason']
526
(r'(<%doc>)(.*?)(</%doc>)(?s)',
527
bygroups(Name.Tag, Comment.Multiline, Name.Tag)),
528
(r'(<%(def|method))(\s*)(.*?)(>)(.*?)(</%\2\s*>)(?s)',
529
bygroups(Name.Tag, None, Text, Name.Function, Name.Tag,
530
using(this), Name.Tag)),
531
(r'(<%(\w+))(.*?)(>)(.*?)(</%\2\s*>)(?s)',
532
bygroups(Name.Tag, None, Name.Function, Name.Tag,
533
using(PerlLexer), Name.Tag)),
534
(r'(<&[^|])(.*?)(,.*?)?(&>)(?s)',
535
bygroups(Name.Tag, Name.Function, using(PerlLexer), Name.Tag)),
536
(r'(<&\|)(.*?)(,.*?)?(&>)(?s)',
537
bygroups(Name.Tag, Name.Function, using(PerlLexer), Name.Tag)),
539
(r'(<%!?)(.*?)(%>)(?s)',
540
bygroups(Name.Tag, using(PerlLexer), Name.Tag)),
541
(r'(?<=^)#[^\n]*(\n|\Z)', Comment),
542
(r'(?<=^)(%)([^\n]*)(\n|\Z)',
543
bygroups(Name.Tag, using(PerlLexer), Other)),
545
(.+?) # anything, followed by:
547
(?<=\n)(?=[%#]) | # an eval or comment line
548
(?=</?[%&]) | # a substitution or block or
551
(\\\n) | # an escaped newline
553
)""", bygroups(using(HtmlLexer), Operator)),
557
def analyse_text(text):
559
if re.search('<&', text) is not None:
394
564
class MakoLexer(RegexLexer):
396
566
Generic `mako templates`_ lexer. Code that isn't Mako
412
582
bygroups(Text, Comment.Preproc, Keyword, Other)),
413
583
(r'(\s*)(%)([^\n]*)(\n|\Z)',
414
584
bygroups(Text, Comment.Preproc, using(PythonLexer), Other)),
415
(r'(\s*)(#[^\n]*)(\n|\Z)',
416
bygroups(Text, Comment.Preproc, Other)),
417
(r'(<%)(def|call|namespace|text)',
585
(r'(\s*)(##[^\n]*)(\n|\Z)',
586
bygroups(Text, Comment.Preproc, Other)),
587
(r'(?s)<%doc>.*?</%doc>', Comment.Preproc),
418
589
bygroups(Comment.Preproc, Name.Builtin), 'tag'),
419
(r'(</%)(def|call|namespace|text)(>)',
590
(r'(</%)([\w\.\:]+)(>)',
420
591
bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc)),
421
(r'<%(?=(include|inherit|namespace|page))', Comment.Preproc, 'ondeftags'),
592
(r'<%(?=([\w\.\:]+))', Comment.Preproc, 'ondeftags'),
422
593
(r'(<%(?:!?))(.*?)(%>)(?s)',
423
594
bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
424
(r'(\$\{!?)(.*?)(\})(?s)',
425
596
bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
427
(.+?) # anything, followed by:
598
(.+?) # anything, followed by:
429
(?<=\n)(?=[%#]) | # an eval or comment line
430
(?=</?%) | # a python block
432
(?=\$\{) | # a substitution
600
(?<=\n)(?=%|\#\#) | # an eval or comment line
601
(?=\#\*) | # multiline comment
602
(?=</?%) | # a python block
604
(?=\$\{) | # a substitution
433
605
(?<=\n)(?=\s*%) |
435
(\\\n) | # an escaped newline
607
(\\\n) | # an escaped newline
438
610
''', bygroups(Other, Operator)),
1206
1378
if '<%' in text and '%>' in text:
1383
class EvoqueLexer(RegexLexer):
1385
For files using the Evoque templating system.
1387
*New in Pygments 1.1.*
1390
aliases = ['evoque']
1391
filenames = ['*.evoque']
1392
mimetypes = ['application/x-evoque']
1399
(r'#\[', Comment.Multiline, 'comment'),
1402
(r'\$\w+:[^$\n]*\$', Comment.Multiline),
1403
# directives: begin, end
1404
(r'(\$)(begin|end)(\{(%)?)(.*?)((?(4)%)\})',
1405
bygroups(Punctuation, Name.Builtin, Punctuation, None,
1406
String, Punctuation, None)),
1407
# directives: evoque, overlay
1408
# see doc for handling first name arg: /directives/evoque/
1409
#+ minor inconsistency: the "name" in e.g. $overlay{name=site_base}
1410
# should be using(PythonLexer), not passed out as String
1411
(r'(\$)(evoque|overlay)(\{(%)?)(\s*[#\w\-"\'.]+[^=,%}]+?)?'
1412
r'(.*?)((?(4)%)\})',
1413
bygroups(Punctuation, Name.Builtin, Punctuation, None,
1414
String, using(PythonLexer), Punctuation, None)),
1415
# directives: if, for, prefer, test
1416
(r'(\$)(\w+)(\{(%)?)(.*?)((?(4)%)\})',
1417
bygroups(Punctuation, Name.Builtin, Punctuation, None,
1418
using(PythonLexer), Punctuation, None)),
1419
# directive clauses (no {} expression)
1420
(r'(\$)(else|rof|fi)', bygroups(Punctuation, Name.Builtin)),
1422
(r'(\$\{(%)?)(.*?)((!)(.*?))?((?(2)%)\})',
1423
bygroups(Punctuation, None, using(PythonLexer),
1424
Name.Builtin, None, None, Punctuation, None)),
1428
(r'[^\]#]', Comment.Multiline),
1429
(r'#\[', Comment.Multiline, '#push'),
1430
(r'\]#', Comment.Multiline, '#pop'),
1431
(r'[\]#]', Comment.Multiline)
1435
class EvoqueHtmlLexer(DelegatingLexer):
1437
Subclass of the `EvoqueLexer` that highlights unlexed data with the
1440
*New in Pygments 1.1.*
1442
name = 'HTML+Evoque'
1443
aliases = ['html+evoque']
1444
filenames = ['*.html']
1445
mimetypes = ['text/html+evoque']
1447
def __init__(self, **options):
1448
super(EvoqueHtmlLexer, self).__init__(HtmlLexer, EvoqueLexer,
1451
class EvoqueXmlLexer(DelegatingLexer):
1453
Subclass of the `EvoqueLexer` that highlights unlexed data with the
1456
*New in Pygments 1.1.*
1459
aliases = ['xml+evoque']
1460
filenames = ['*.xml']
1461
mimetypes = ['application/xml+evoque']
1463
def __init__(self, **options):
1464
super(EvoqueXmlLexer, self).__init__(XmlLexer, EvoqueLexer,
1467
class ColdfusionLexer(RegexLexer):
1469
Coldfusion statements
1471
name = 'cfstatement'
1475
flags = re.IGNORECASE | re.MULTILINE
1480
(r'\+\+|--', Operator),
1481
(r'[-+*/^&=!]', Operator),
1482
(r'<=|>=|<|>', Operator),
1483
(r'mod\b', Operator),
1484
(r'(eq|lt|gt|lte|gte|not|is|and|or)\b', Operator),
1485
(r'\|\||&&', Operator),
1486
(r'"', String.Double, 'string'),
1487
# There is a special rule for allowing html in single quoted
1488
# strings, evidently.
1489
(r"'.*?'", String.Single),
1491
(r'(if|else|len|var|case|default|break|switch)\b', Keyword),
1492
(r'([A-Za-z_$][A-Za-z0-9_.]*)\s*(\()', bygroups(Name.Function, Punctuation)),
1493
(r'[A-Za-z_$][A-Za-z0-9_.]*', Name.Variable),
1494
(r'[()\[\]{};:,.\\]', Punctuation),
1498
(r'""', String.Double),
1499
(r'#.+?#', String.Interp),
1500
(r'[^"#]+', String.Double),
1501
(r'#', String.Double),
1502
(r'"', String.Double, '#pop'),
1506
class ColdfusionMarkupLexer(RegexLexer):
1508
Coldfusion markup only
1519
(r'<[^<>]*', Other),
1522
(r'(?s)<!---.*?--->', Comment.Multiline),
1523
(r'(?s)<!--.*?-->', Comment),
1524
(r'<cfoutput.*?>', Name.Builtin, 'cfoutput'),
1525
(r'(?s)(<cfscript.*?>)(.+?)(</cfscript.*?>)',
1526
bygroups(Name.Builtin, using(ColdfusionLexer), Name.Builtin)),
1527
# negative lookbehind is for strings with embedded >
1528
(r'(?s)(</?cf(?:component|include|if|else|elseif|loop|return|'
1529
r'dbinfo|dump|abort|location|invoke|throw|file|savecontent|'
1530
r'mailpart|mail|header|content|zip|image|lock|argument|try|'
1531
r'catch|break|directory|http|set|function|param)\b)(.*?)((?<!\\)>)',
1532
bygroups(Name.Builtin, using(ColdfusionLexer), Name.Builtin)),
1536
(r'(#)(.*?)(#)', bygroups(Punctuation, using(ColdfusionLexer),
1538
#(r'<cfoutput.*?>', Name.Builtin, '#push'),
1539
(r'</cfoutput.*?>', Name.Builtin, '#pop'),
1541
(r'(?s)<[^<>]*', Other),
1547
class ColdfusionHtmlLexer(DelegatingLexer):
1549
Coldfusion markup in html
1551
name = 'Coldfusion HTML'
1553
filenames = ['*.cfm', '*.cfml', '*.cfc']
1554
mimetypes = ['application/x-coldfusion']
1556
def __init__(self, **options):
1557
super(ColdfusionHtmlLexer, self).__init__(HtmlLexer, ColdfusionMarkupLexer,
1561
class SspLexer(DelegatingLexer):
1563
Lexer for Scalate Server Pages.
1565
*New in Pygments 1.4.*
1567
name = 'Scalate Server Page'
1569
filenames = ['*.ssp']
1570
mimetypes = ['application/x-ssp']
1572
def __init__(self, **options):
1573
super(SspLexer, self).__init__(XmlLexer, JspRootLexer, **options)
1575
def analyse_text(text):
1577
if re.search('val \w+\s*:', text):
1579
if looks_like_xml(text):
1581
if '<%' in text and '%>' in text: