42 'ColdfusionHtmlLexer', 'ColdfusionCFCLexer', 'VelocityLexer', |
42 'ColdfusionHtmlLexer', 'ColdfusionCFCLexer', 'VelocityLexer', |
43 'VelocityHtmlLexer', 'VelocityXmlLexer', 'SspLexer', |
43 'VelocityHtmlLexer', 'VelocityXmlLexer', 'SspLexer', |
44 'TeaTemplateLexer', 'LassoHtmlLexer', 'LassoXmlLexer', |
44 'TeaTemplateLexer', 'LassoHtmlLexer', 'LassoXmlLexer', |
45 'LassoCssLexer', 'LassoJavascriptLexer', 'HandlebarsLexer', |
45 'LassoCssLexer', 'LassoJavascriptLexer', 'HandlebarsLexer', |
46 'HandlebarsHtmlLexer', 'YamlJinjaLexer', 'LiquidLexer', |
46 'HandlebarsHtmlLexer', 'YamlJinjaLexer', 'LiquidLexer', |
47 'TwigLexer', 'TwigHtmlLexer'] |
47 'TwigLexer', 'TwigHtmlLexer', 'Angular2Lexer', 'Angular2HtmlLexer'] |
48 |
48 |
49 |
49 |
50 class ErbLexer(Lexer): |
50 class ErbLexer(Lexer): |
51 """ |
51 """ |
52 Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating) |
52 Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating) |
1812 (r'\s+', Text), |
1812 (r'\s+', Text), |
1813 (r'\}\}\}', Comment.Special, '#pop'), |
1813 (r'\}\}\}', Comment.Special, '#pop'), |
1814 (r'\}\}', Comment.Preproc, '#pop'), |
1814 (r'\}\}', Comment.Preproc, '#pop'), |
1815 |
1815 |
1816 # Handlebars |
1816 # Handlebars |
1817 (r'([#/]*)(each|if|unless|else|with|log|in)', bygroups(Keyword, |
1817 (r'([#/]*)(each|if|unless|else|with|log|in(line)?)', bygroups(Keyword, |
1818 Keyword)), |
1818 Keyword)), |
|
1819 (r'#\*inline', Keyword), |
1819 |
1820 |
1820 # General {{#block}} |
1821 # General {{#block}} |
1821 (r'([#/])([\w-]+)', bygroups(Name.Function, Name.Function)), |
1822 (r'([#/])([\w-]+)', bygroups(Name.Function, Name.Function)), |
1822 |
1823 |
1823 # {{opt=something}} |
1824 # {{opt=something}} |
1824 (r'([\w-]+)(=)', bygroups(Name.Attribute, Operator)), |
1825 (r'([\w-]+)(=)', bygroups(Name.Attribute, Operator)), |
|
1826 |
|
1827 # Partials {{> ...}} |
|
1828 (r'(>)(\s*)(@partial-block)', bygroups(Keyword, Text, Keyword)), |
|
1829 (r'(#?>)(\s*)([\w-]+)', bygroups(Keyword, Text, Name.Variable)), |
|
1830 (r'(>)(\s*)(\()', bygroups(Keyword, Text, Punctuation), |
|
1831 'dynamic-partial'), |
|
1832 |
|
1833 include('generic'), |
|
1834 ], |
|
1835 'dynamic-partial': [ |
|
1836 (r'\s+', Text), |
|
1837 (r'\)', Punctuation, '#pop'), |
|
1838 |
|
1839 (r'(lookup)(\s+)(\.|this)(\s+)', bygroups(Keyword, Text, |
|
1840 Name.Variable, Text)), |
|
1841 (r'(lookup)(\s+)(\S+)', bygroups(Keyword, Text, |
|
1842 using(this, state='variable'))), |
|
1843 (r'[\w-]+', Name.Function), |
|
1844 |
|
1845 include('generic'), |
|
1846 ], |
|
1847 'variable': [ |
|
1848 (r'[a-zA-Z][\w-]*', Name.Variable), |
|
1849 (r'\.[\w-]+', Name.Variable), |
|
1850 (r'(this\/|\.\/|(\.\.\/)+)[\w-]+', Name.Variable), |
|
1851 ], |
|
1852 'generic': [ |
|
1853 include('variable'), |
1825 |
1854 |
1826 # borrowed from DjangoLexer |
1855 # borrowed from DjangoLexer |
1827 (r':?"(\\\\|\\"|[^"])*"', String.Double), |
1856 (r':?"(\\\\|\\"|[^"])*"', String.Double), |
1828 (r":?'(\\\\|\\'|[^'])*'", String.Single), |
1857 (r":?'(\\\\|\\'|[^'])*'", String.Single), |
1829 (r'[a-zA-Z][\w-]*', Name.Variable), |
|
1830 (r'\.[\w-]+', Name.Variable), |
|
1831 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" |
1858 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" |
1832 r"0[xX][0-9a-fA-F]+[Ll]?", Number), |
1859 r"0[xX][0-9a-fA-F]+[Ll]?", Number), |
1833 ] |
1860 ] |
1834 } |
1861 } |
1835 |
1862 |
2172 filenames = ['*.twig'] |
2199 filenames = ['*.twig'] |
2173 mimetypes = ['text/html+twig'] |
2200 mimetypes = ['text/html+twig'] |
2174 |
2201 |
2175 def __init__(self, **options): |
2202 def __init__(self, **options): |
2176 super(TwigHtmlLexer, self).__init__(HtmlLexer, TwigLexer, **options) |
2203 super(TwigHtmlLexer, self).__init__(HtmlLexer, TwigLexer, **options) |
|
2204 |
|
2205 |
|
2206 class Angular2Lexer(RegexLexer): |
|
2207 """ |
|
2208 Generic |
|
2209 `angular2 <http://victorsavkin.com/post/119943127151/angular-2-template-syntax>`_ |
|
2210 template lexer. |
|
2211 |
|
2212 Highlights only the Angular template tags (stuff between `{{` and `}}` and |
|
2213 special attributes: '(event)=', '[property]=', '[(twoWayBinding)]='). |
|
2214 Everything else is left for a delegating lexer. |
|
2215 |
|
2216 .. versionadded:: 2.1 |
|
2217 """ |
|
2218 |
|
2219 name = "Angular2" |
|
2220 aliases = ['ng2'] |
|
2221 |
|
2222 tokens = { |
|
2223 'root': [ |
|
2224 (r'[^{([*#]+', Other), |
|
2225 |
|
2226 # {{meal.name}} |
|
2227 (r'(\{\{)(\s*)', bygroups(Comment.Preproc, Text), 'ngExpression'), |
|
2228 |
|
2229 # (click)="deleteOrder()"; [value]="test"; [(twoWayTest)]="foo.bar" |
|
2230 (r'([([]+)([\w:.-]+)([\])]+)(\s*)(=)(\s*)', |
|
2231 bygroups(Punctuation, Name.Attribute, Punctuation, Text, Operator, Text), |
|
2232 'attr'), |
|
2233 (r'([([]+)([\w:.-]+)([\])]+)(\s*)', |
|
2234 bygroups(Punctuation, Name.Attribute, Punctuation, Text)), |
|
2235 |
|
2236 # *ngIf="..."; #f="ngForm" |
|
2237 (r'([*#])([\w:.-]+)(\s*)(=)(\s*)', |
|
2238 bygroups(Punctuation, Name.Attribute, Punctuation, Operator), 'attr'), |
|
2239 (r'([*#])([\w:.-]+)(\s*)', |
|
2240 bygroups(Punctuation, Name.Attribute, Punctuation)), |
|
2241 ], |
|
2242 |
|
2243 'ngExpression': [ |
|
2244 (r'\s+(\|\s+)?', Text), |
|
2245 (r'\}\}', Comment.Preproc, '#pop'), |
|
2246 |
|
2247 # Literals |
|
2248 (r':?(true|false)', String.Boolean), |
|
2249 (r':?"(\\\\|\\"|[^"])*"', String.Double), |
|
2250 (r":?'(\\\\|\\'|[^'])*'", String.Single), |
|
2251 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" |
|
2252 r"0[xX][0-9a-fA-F]+[Ll]?", Number), |
|
2253 |
|
2254 # Variabletext |
|
2255 (r'[a-zA-Z][\w-]*(\(.*\))?', Name.Variable), |
|
2256 (r'\.[\w-]+(\(.*\))?', Name.Variable), |
|
2257 |
|
2258 # inline If |
|
2259 (r'(\?)(\s*)([^}\s]+)(\s*)(:)(\s*)([^}\s]+)(\s*)', |
|
2260 bygroups(Operator, Text, String, Text, Operator, Text, String, Text)), |
|
2261 ], |
|
2262 'attr': [ |
|
2263 ('".*?"', String, '#pop'), |
|
2264 ("'.*?'", String, '#pop'), |
|
2265 (r'[^\s>]+', String, '#pop'), |
|
2266 ], |
|
2267 } |
|
2268 |
|
2269 |
|
2270 class Angular2HtmlLexer(DelegatingLexer): |
|
2271 """ |
|
2272 Subclass of the `Angular2Lexer` that highlights unlexed data with the |
|
2273 `HtmlLexer`. |
|
2274 |
|
2275 .. versionadded:: 2.0 |
|
2276 """ |
|
2277 |
|
2278 name = "HTML + Angular2" |
|
2279 aliases = ["html+ng2"] |
|
2280 filenames = ['*.ng2'] |
|
2281 |
|
2282 def __init__(self, **options): |
|
2283 super(Angular2HtmlLexer, self).__init__(HtmlLexer, Angular2Lexer, **options) |