]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/twig.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / twig.js
1 /*! `twig` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: Twig
7 Requires: xml.js
8 Author: Luke Holder <lukemh@gmail.com>
9 Description: Twig is a templating language for PHP
10 Website: https://twig.symfony.com
11 Category: template
12 */
13
14 function twig(hljs) {
15 const regex = hljs.regex;
16 const FUNCTION_NAMES = [
17 "absolute_url",
18 "asset|0",
19 "asset_version",
20 "attribute",
21 "block",
22 "constant",
23 "controller|0",
24 "country_timezones",
25 "csrf_token",
26 "cycle",
27 "date",
28 "dump",
29 "expression",
30 "form|0",
31 "form_end",
32 "form_errors",
33 "form_help",
34 "form_label",
35 "form_rest",
36 "form_row",
37 "form_start",
38 "form_widget",
39 "html_classes",
40 "include",
41 "is_granted",
42 "logout_path",
43 "logout_url",
44 "max",
45 "min",
46 "parent",
47 "path|0",
48 "random",
49 "range",
50 "relative_path",
51 "render",
52 "render_esi",
53 "source",
54 "template_from_string",
55 "url|0"
56 ];
57
58 const FILTERS = [
59 "abs",
60 "abbr_class",
61 "abbr_method",
62 "batch",
63 "capitalize",
64 "column",
65 "convert_encoding",
66 "country_name",
67 "currency_name",
68 "currency_symbol",
69 "data_uri",
70 "date",
71 "date_modify",
72 "default",
73 "escape",
74 "file_excerpt",
75 "file_link",
76 "file_relative",
77 "filter",
78 "first",
79 "format",
80 "format_args",
81 "format_args_as_text",
82 "format_currency",
83 "format_date",
84 "format_datetime",
85 "format_file",
86 "format_file_from_text",
87 "format_number",
88 "format_time",
89 "html_to_markdown",
90 "humanize",
91 "inky_to_html",
92 "inline_css",
93 "join",
94 "json_encode",
95 "keys",
96 "language_name",
97 "last",
98 "length",
99 "locale_name",
100 "lower",
101 "map",
102 "markdown",
103 "markdown_to_html",
104 "merge",
105 "nl2br",
106 "number_format",
107 "raw",
108 "reduce",
109 "replace",
110 "reverse",
111 "round",
112 "slice",
113 "slug",
114 "sort",
115 "spaceless",
116 "split",
117 "striptags",
118 "timezone_name",
119 "title",
120 "trans",
121 "transchoice",
122 "trim",
123 "u|0",
124 "upper",
125 "url_encode",
126 "yaml_dump",
127 "yaml_encode"
128 ];
129
130 let TAG_NAMES = [
131 "apply",
132 "autoescape",
133 "block",
134 "cache",
135 "deprecated",
136 "do",
137 "embed",
138 "extends",
139 "filter",
140 "flush",
141 "for",
142 "form_theme",
143 "from",
144 "if",
145 "import",
146 "include",
147 "macro",
148 "sandbox",
149 "set",
150 "stopwatch",
151 "trans",
152 "trans_default_domain",
153 "transchoice",
154 "use",
155 "verbatim",
156 "with"
157 ];
158
159 TAG_NAMES = TAG_NAMES.concat(TAG_NAMES.map(t => `end${t}`));
160
161 const STRING = {
162 scope: 'string',
163 variants: [
164 {
165 begin: /'/,
166 end: /'/
167 },
168 {
169 begin: /"/,
170 end: /"/
171 },
172 ]
173 };
174
175 const NUMBER = {
176 scope: "number",
177 match: /\d+/
178 };
179
180 const PARAMS = {
181 begin: /\(/,
182 end: /\)/,
183 excludeBegin: true,
184 excludeEnd: true,
185 contains: [
186 STRING,
187 NUMBER
188 ]
189 };
190
191
192 const FUNCTIONS = {
193 beginKeywords: FUNCTION_NAMES.join(" "),
194 keywords: { name: FUNCTION_NAMES },
195 relevance: 0,
196 contains: [ PARAMS ]
197 };
198
199 const FILTER = {
200 match: /\|(?=[A-Za-z_]+:?)/,
201 beginScope: "punctuation",
202 relevance: 0,
203 contains: [
204 {
205 match: /[A-Za-z_]+:?/,
206 keywords: FILTERS
207 },
208 ]
209 };
210
211 const tagNamed = (tagnames, { relevance }) => {
212 return {
213 beginScope: {
214 1: 'template-tag',
215 3: 'name'
216 },
217 relevance: relevance || 2,
218 endScope: 'template-tag',
219 begin: [
220 /\{%/,
221 /\s*/,
222 regex.either(...tagnames)
223 ],
224 end: /%\}/,
225 keywords: "in",
226 contains: [
227 FILTER,
228 FUNCTIONS,
229 STRING,
230 NUMBER
231 ]
232 };
233 };
234
235 const CUSTOM_TAG_RE = /[a-z_]+/;
236 const TAG = tagNamed(TAG_NAMES, { relevance: 2 });
237 const CUSTOM_TAG = tagNamed([ CUSTOM_TAG_RE ], { relevance: 1 });
238
239 return {
240 name: 'Twig',
241 aliases: [ 'craftcms' ],
242 case_insensitive: true,
243 subLanguage: 'xml',
244 contains: [
245 hljs.COMMENT(/\{#/, /#\}/),
246 TAG,
247 CUSTOM_TAG,
248 {
249 className: 'template-variable',
250 begin: /\{\{/,
251 end: /\}\}/,
252 contains: [
253 'self',
254 FILTER,
255 FUNCTIONS,
256 STRING,
257 NUMBER
258 ]
259 }
260 ]
261 };
262 }
263
264 return twig;
265
266 })();
267 ;
268 export default hljsGrammar;