[d24f17c] | 1 | 'use strict'
|
---|
| 2 | var refractorMarkupTemplating = require('./markup-templating.js')
|
---|
| 3 | module.exports = liquid
|
---|
| 4 | liquid.displayName = 'liquid'
|
---|
| 5 | liquid.aliases = []
|
---|
| 6 | function liquid(Prism) {
|
---|
| 7 | Prism.register(refractorMarkupTemplating)
|
---|
| 8 | Prism.languages.liquid = {
|
---|
| 9 | comment: {
|
---|
| 10 | pattern: /(^\{%\s*comment\s*%\})[\s\S]+(?=\{%\s*endcomment\s*%\}$)/,
|
---|
| 11 | lookbehind: true
|
---|
| 12 | },
|
---|
| 13 | delimiter: {
|
---|
| 14 | pattern: /^\{(?:\{\{|[%\{])-?|-?(?:\}\}|[%\}])\}$/,
|
---|
| 15 | alias: 'punctuation'
|
---|
| 16 | },
|
---|
| 17 | string: {
|
---|
| 18 | pattern: /"[^"]*"|'[^']*'/,
|
---|
| 19 | greedy: true
|
---|
| 20 | },
|
---|
| 21 | keyword:
|
---|
| 22 | /\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/,
|
---|
| 23 | object:
|
---|
| 24 | /\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/,
|
---|
| 25 | function: [
|
---|
| 26 | {
|
---|
| 27 | pattern: /(\|\s*)\w+/,
|
---|
| 28 | lookbehind: true,
|
---|
| 29 | alias: 'filter'
|
---|
| 30 | },
|
---|
| 31 | {
|
---|
| 32 | // array functions
|
---|
| 33 | pattern: /(\.\s*)(?:first|last|size)/,
|
---|
| 34 | lookbehind: true
|
---|
| 35 | }
|
---|
| 36 | ],
|
---|
| 37 | boolean: /\b(?:false|nil|true)\b/,
|
---|
| 38 | range: {
|
---|
| 39 | pattern: /\.\./,
|
---|
| 40 | alias: 'operator'
|
---|
| 41 | },
|
---|
| 42 | // https://github.com/Shopify/liquid/blob/698f5e0d967423e013f6169d9111bd969bd78337/lib/liquid/lexer.rb#L21
|
---|
| 43 | number: /\b\d+(?:\.\d+)?\b/,
|
---|
| 44 | operator: /[!=]=|<>|[<>]=?|[|?:=-]|\b(?:and|contains(?=\s)|or)\b/,
|
---|
| 45 | punctuation: /[.,\[\]()]/,
|
---|
| 46 | empty: {
|
---|
| 47 | pattern: /\bempty\b/,
|
---|
| 48 | alias: 'keyword'
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | Prism.hooks.add('before-tokenize', function (env) {
|
---|
| 52 | var liquidPattern =
|
---|
| 53 | /\{%\s*comment\s*%\}[\s\S]*?\{%\s*endcomment\s*%\}|\{(?:%[\s\S]*?%|\{\{[\s\S]*?\}\}|\{[\s\S]*?\})\}/g
|
---|
| 54 | var insideRaw = false
|
---|
| 55 | Prism.languages['markup-templating'].buildPlaceholders(
|
---|
| 56 | env,
|
---|
| 57 | 'liquid',
|
---|
| 58 | liquidPattern,
|
---|
| 59 | function (match) {
|
---|
| 60 | var tagMatch = /^\{%-?\s*(\w+)/.exec(match)
|
---|
| 61 | if (tagMatch) {
|
---|
| 62 | var tag = tagMatch[1]
|
---|
| 63 | if (tag === 'raw' && !insideRaw) {
|
---|
| 64 | insideRaw = true
|
---|
| 65 | return true
|
---|
| 66 | } else if (tag === 'endraw') {
|
---|
| 67 | insideRaw = false
|
---|
| 68 | return true
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | return !insideRaw
|
---|
| 72 | }
|
---|
| 73 | )
|
---|
| 74 | })
|
---|
| 75 | Prism.hooks.add('after-tokenize', function (env) {
|
---|
| 76 | Prism.languages['markup-templating'].tokenizePlaceholders(env, 'liquid')
|
---|
| 77 | })
|
---|
| 78 | }
|
---|