3 pygments.lexers.css |
3 pygments.lexers.css |
4 ~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for CSS and related stylesheet formats. |
6 Lexers for CSS and related stylesheet formats. |
7 |
7 |
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 import copy |
13 import copy |
14 |
14 |
15 from pygments.lexer import ExtendedRegexLexer, RegexLexer, include, bygroups, \ |
15 from pygments.lexer import ExtendedRegexLexer, RegexLexer, include, bygroups, \ |
16 default, words |
16 default, words, inherit |
17 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
17 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
18 Number, Punctuation |
18 Number, Punctuation |
19 from pygments.util import iteritems |
19 from pygments.util import iteritems |
20 |
20 |
21 __all__ = ['CssLexer', 'SassLexer', 'ScssLexer'] |
21 __all__ = ['CssLexer', 'SassLexer', 'ScssLexer', 'LessCssLexer'] |
22 |
22 |
23 |
23 |
24 class CssLexer(RegexLexer): |
24 class CssLexer(RegexLexer): |
25 """ |
25 """ |
26 For CSS (Cascading Style Sheets). |
26 For CSS (Cascading Style Sheets). |
39 (r'\s+', Text), |
39 (r'\s+', Text), |
40 (r'/\*(?:.|\n)*?\*/', Comment), |
40 (r'/\*(?:.|\n)*?\*/', Comment), |
41 (r'\{', Punctuation, 'content'), |
41 (r'\{', Punctuation, 'content'), |
42 (r'\:[\w-]+', Name.Decorator), |
42 (r'\:[\w-]+', Name.Decorator), |
43 (r'\.[\w-]+', Name.Class), |
43 (r'\.[\w-]+', Name.Class), |
44 (r'\#[\w-]+', Name.Function), |
44 (r'\#[\w-]+', Name.Namespace), |
45 (r'@[\w-]+', Keyword, 'atrule'), |
45 (r'@[\w-]+', Keyword, 'atrule'), |
46 (r'[\w-]+', Name.Tag), |
46 (r'[\w-]+', Name.Tag), |
47 (r'[~^*!%&$\[\]()<>|+=@:;,./?-]', Operator), |
47 (r'[~^*!%&$\[\]()<>|+=@:;,./?-]', Operator), |
48 (r'"(\\\\|\\"|[^"])*"', String.Double), |
48 (r'"(\\\\|\\"|[^"])*"', String.Double), |
49 (r"'(\\\\|\\'|[^'])*'", String.Single) |
49 (r"'(\\\\|\\'|[^'])*'", String.Single) |
118 'table-row-group', 'text-bottom', 'text-top', 'text', 'thick', 'thin', |
118 'table-row-group', 'text-bottom', 'text-top', 'text', 'thick', 'thin', |
119 'transparent', 'ultra-condensed', 'ultra-expanded', 'underline', |
119 'transparent', 'ultra-condensed', 'ultra-expanded', 'underline', |
120 'upper-alpha', 'upper-latin', 'upper-roman', 'uppercase', 'url', |
120 'upper-alpha', 'upper-latin', 'upper-roman', 'uppercase', 'url', |
121 'visible', 'w-resize', 'wait', 'wider', 'x-fast', 'x-high', 'x-large', 'x-loud', |
121 'visible', 'w-resize', 'wait', 'wider', 'x-fast', 'x-high', 'x-large', 'x-loud', |
122 'x-low', 'x-small', 'x-soft', 'xx-large', 'xx-small', 'yes'), suffix=r'\b'), |
122 'x-low', 'x-small', 'x-soft', 'xx-large', 'xx-small', 'yes'), suffix=r'\b'), |
123 Keyword), |
123 Name.Builtin), |
124 (words(( |
124 (words(( |
125 'indigo', 'gold', 'firebrick', 'indianred', 'yellow', 'darkolivegreen', |
125 'indigo', 'gold', 'firebrick', 'indianred', 'yellow', 'darkolivegreen', |
126 'darkseagreen', 'mediumvioletred', 'mediumorchid', 'chartreuse', |
126 'darkseagreen', 'mediumvioletred', 'mediumorchid', 'chartreuse', |
127 'mediumslateblue', 'black', 'springgreen', 'crimson', 'lightsalmon', 'brown', |
127 'mediumslateblue', 'black', 'springgreen', 'crimson', 'lightsalmon', 'brown', |
128 'turquoise', 'olivedrab', 'cyan', 'silver', 'skyblue', 'gray', 'darkturquoise', |
128 'turquoise', 'olivedrab', 'cyan', 'silver', 'skyblue', 'gray', 'darkturquoise', |
473 (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), |
473 (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), |
474 (r'@extend', Keyword, 'selector'), |
474 (r'@extend', Keyword, 'selector'), |
475 (r'(@media)(\s+)', bygroups(Keyword, Text), 'value'), |
475 (r'(@media)(\s+)', bygroups(Keyword, Text), 'value'), |
476 (r'@[\w-]+', Keyword, 'selector'), |
476 (r'@[\w-]+', Keyword, 'selector'), |
477 (r'(\$[\w-]*\w)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'), |
477 (r'(\$[\w-]*\w)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'), |
478 (r'(?=[^;{}][;}])', Name.Attribute, 'attr'), |
478 # TODO: broken, and prone to infinite loops. |
479 (r'(?=[^;{}:]+:[^a-z])', Name.Attribute, 'attr'), |
479 #(r'(?=[^;{}][;}])', Name.Attribute, 'attr'), |
|
480 #(r'(?=[^;{}:]+:[^a-z])', Name.Attribute, 'attr'), |
480 default('selector'), |
481 default('selector'), |
481 ], |
482 ], |
482 |
483 |
483 'attr': [ |
484 'attr': [ |
484 (r'[^\s:="\[]+', Name.Attribute), |
485 (r'[^\s:="\[]+', Name.Attribute), |
485 (r'#\{', String.Interpol, 'interpolation'), |
486 (r'#\{', String.Interpol, 'interpolation'), |
486 (r'[ \t]*:', Operator, 'value'), |
487 (r'[ \t]*:', Operator, 'value'), |
|
488 default('#pop'), |
487 ], |
489 ], |
488 |
490 |
489 'inline-comment': [ |
491 'inline-comment': [ |
490 (r"(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+", Comment.Multiline), |
492 (r"(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+", Comment.Multiline), |
491 (r'#\{', String.Interpol, 'interpolation'), |
493 (r'#\{', String.Interpol, 'interpolation'), |
494 } |
496 } |
495 for group, common in iteritems(common_sass_tokens): |
497 for group, common in iteritems(common_sass_tokens): |
496 tokens[group] = copy.copy(common) |
498 tokens[group] = copy.copy(common) |
497 tokens['value'].extend([(r'\n', Text), (r'[;{}]', Punctuation, '#pop')]) |
499 tokens['value'].extend([(r'\n', Text), (r'[;{}]', Punctuation, '#pop')]) |
498 tokens['selector'].extend([(r'\n', Text), (r'[;{}]', Punctuation, '#pop')]) |
500 tokens['selector'].extend([(r'\n', Text), (r'[;{}]', Punctuation, '#pop')]) |
|
501 |
|
502 |
|
503 class LessCssLexer(CssLexer): |
|
504 """ |
|
505 For `LESS <http://lesscss.org/>`_ styleshets. |
|
506 |
|
507 .. versionadded:: 2.1 |
|
508 """ |
|
509 |
|
510 name = 'LessCss' |
|
511 aliases = ['less'] |
|
512 filenames = ['*.less'] |
|
513 mimetypes = ['text/x-less-css'] |
|
514 |
|
515 tokens = { |
|
516 'root': [ |
|
517 (r'@\w+', Name.Variable), |
|
518 inherit, |
|
519 ], |
|
520 'content': [ |
|
521 (r'{', Punctuation, '#push'), |
|
522 inherit, |
|
523 ], |
|
524 } |