[d24f17c] | 1 | /*
|
---|
| 2 | Language: Twig
|
---|
| 3 | Requires: xml.js
|
---|
| 4 | Author: Luke Holder <lukemh@gmail.com>
|
---|
| 5 | Description: Twig is a templating language for PHP
|
---|
| 6 | Website: https://twig.symfony.com
|
---|
| 7 | Category: template
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | function twig(hljs) {
|
---|
| 11 | var PARAMS = {
|
---|
| 12 | className: 'params',
|
---|
| 13 | begin: '\\(', end: '\\)'
|
---|
| 14 | };
|
---|
| 15 |
|
---|
| 16 | var FUNCTION_NAMES = 'attribute block constant cycle date dump include ' +
|
---|
| 17 | 'max min parent random range source template_from_string';
|
---|
| 18 |
|
---|
| 19 | var FUNCTIONS = {
|
---|
| 20 | beginKeywords: FUNCTION_NAMES,
|
---|
| 21 | keywords: {name: FUNCTION_NAMES},
|
---|
| 22 | relevance: 0,
|
---|
| 23 | contains: [
|
---|
| 24 | PARAMS
|
---|
| 25 | ]
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | var FILTER = {
|
---|
| 29 | begin: /\|[A-Za-z_]+:?/,
|
---|
| 30 | keywords:
|
---|
| 31 | 'abs batch capitalize column convert_encoding date date_modify default ' +
|
---|
| 32 | 'escape filter first format inky_to_html inline_css join json_encode keys last ' +
|
---|
| 33 | 'length lower map markdown merge nl2br number_format raw reduce replace ' +
|
---|
| 34 | 'reverse round slice sort spaceless split striptags title trim upper url_encode',
|
---|
| 35 | contains: [
|
---|
| 36 | FUNCTIONS
|
---|
| 37 | ]
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | var TAGS = 'apply autoescape block deprecated do embed extends filter flush for from ' +
|
---|
| 41 | 'if import include macro sandbox set use verbatim with';
|
---|
| 42 |
|
---|
| 43 | TAGS = TAGS + ' ' + TAGS.split(' ').map(function(t){return 'end' + t}).join(' ');
|
---|
| 44 |
|
---|
| 45 | return {
|
---|
| 46 | name: 'Twig',
|
---|
| 47 | aliases: ['craftcms'],
|
---|
| 48 | case_insensitive: true,
|
---|
| 49 | subLanguage: 'xml',
|
---|
| 50 | contains: [
|
---|
| 51 | hljs.COMMENT(/\{#/, /#\}/),
|
---|
| 52 | {
|
---|
| 53 | className: 'template-tag',
|
---|
| 54 | begin: /\{%/, end: /%\}/,
|
---|
| 55 | contains: [
|
---|
| 56 | {
|
---|
| 57 | className: 'name',
|
---|
| 58 | begin: /\w+/,
|
---|
| 59 | keywords: TAGS,
|
---|
| 60 | starts: {
|
---|
| 61 | endsWithParent: true,
|
---|
| 62 | contains: [FILTER, FUNCTIONS],
|
---|
| 63 | relevance: 0
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | ]
|
---|
| 67 | },
|
---|
| 68 | {
|
---|
| 69 | className: 'template-variable',
|
---|
| 70 | begin: /\{\{/, end: /\}\}/,
|
---|
| 71 | contains: ['self', FILTER, FUNCTIONS]
|
---|
| 72 | }
|
---|
| 73 | ]
|
---|
| 74 | };
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | module.exports = twig;
|
---|