1 | Prism.languages.liquid = {
|
---|
2 | 'comment': {
|
---|
3 | pattern: /(^\{%\s*comment\s*%\})[\s\S]+(?=\{%\s*endcomment\s*%\}$)/,
|
---|
4 | lookbehind: true
|
---|
5 | },
|
---|
6 | 'delimiter': {
|
---|
7 | pattern: /^\{(?:\{\{|[%\{])-?|-?(?:\}\}|[%\}])\}$/,
|
---|
8 | alias: 'punctuation'
|
---|
9 | },
|
---|
10 | 'string': {
|
---|
11 | pattern: /"[^"]*"|'[^']*'/,
|
---|
12 | greedy: true
|
---|
13 | },
|
---|
14 | 'keyword': /\b(?:as|assign|break|(?:end)?(?:capture|case|comment|for|form|if|paginate|raw|style|tablerow|unless)|continue|cycle|decrement|echo|else|elsif|in|include|increment|limit|liquid|offset|range|render|reversed|section|when|with)\b/,
|
---|
15 | 'object': /\b(?:address|all_country_option_tags|article|block|blog|cart|checkout|collection|color|country|country_option_tags|currency|current_page|current_tags|customer|customer_address|date|discount_allocation|discount_application|external_video|filter|filter_value|font|forloop|fulfillment|generic_file|gift_card|group|handle|image|line_item|link|linklist|localization|location|measurement|media|metafield|model|model_source|order|page|page_description|page_image|page_title|part|policy|product|product_option|recommendations|request|robots|routes|rule|script|search|selling_plan|selling_plan_allocation|selling_plan_group|shipping_method|shop|shop_locale|sitemap|store_availability|tax_line|template|theme|transaction|unit_price_measurement|user_agent|variant|video|video_source)\b/,
|
---|
16 | 'function': [
|
---|
17 | {
|
---|
18 | pattern: /(\|\s*)\w+/,
|
---|
19 | lookbehind: true,
|
---|
20 | alias: 'filter'
|
---|
21 | },
|
---|
22 | {
|
---|
23 | // array functions
|
---|
24 | pattern: /(\.\s*)(?:first|last|size)/,
|
---|
25 | lookbehind: true
|
---|
26 | }
|
---|
27 | ],
|
---|
28 | 'boolean': /\b(?:false|nil|true)\b/,
|
---|
29 | 'range': {
|
---|
30 | pattern: /\.\./,
|
---|
31 | alias: 'operator'
|
---|
32 | },
|
---|
33 | // https://github.com/Shopify/liquid/blob/698f5e0d967423e013f6169d9111bd969bd78337/lib/liquid/lexer.rb#L21
|
---|
34 | 'number': /\b\d+(?:\.\d+)?\b/,
|
---|
35 | 'operator': /[!=]=|<>|[<>]=?|[|?:=-]|\b(?:and|contains(?=\s)|or)\b/,
|
---|
36 | 'punctuation': /[.,\[\]()]/,
|
---|
37 | 'empty': {
|
---|
38 | pattern: /\bempty\b/,
|
---|
39 | alias: 'keyword'
|
---|
40 | },
|
---|
41 | };
|
---|
42 |
|
---|
43 | Prism.hooks.add('before-tokenize', function (env) {
|
---|
44 | var liquidPattern = /\{%\s*comment\s*%\}[\s\S]*?\{%\s*endcomment\s*%\}|\{(?:%[\s\S]*?%|\{\{[\s\S]*?\}\}|\{[\s\S]*?\})\}/g;
|
---|
45 | var insideRaw = false;
|
---|
46 |
|
---|
47 | Prism.languages['markup-templating'].buildPlaceholders(env, 'liquid', liquidPattern, function (match) {
|
---|
48 | var tagMatch = /^\{%-?\s*(\w+)/.exec(match);
|
---|
49 | if (tagMatch) {
|
---|
50 | var tag = tagMatch[1];
|
---|
51 | if (tag === 'raw' && !insideRaw) {
|
---|
52 | insideRaw = true;
|
---|
53 | return true;
|
---|
54 | } else if (tag === 'endraw') {
|
---|
55 | insideRaw = false;
|
---|
56 | return true;
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | return !insideRaw;
|
---|
61 | });
|
---|
62 | });
|
---|
63 |
|
---|
64 | Prism.hooks.add('after-tokenize', function (env) {
|
---|
65 | Prism.languages['markup-templating'].tokenizePlaceholders(env, 'liquid');
|
---|
66 | });
|
---|