[d24f17c] | 1 | 'use strict'
|
---|
| 2 | var refractorMarkupTemplating = require('./markup-templating.js')
|
---|
| 3 | module.exports = twig
|
---|
| 4 | twig.displayName = 'twig'
|
---|
| 5 | twig.aliases = []
|
---|
| 6 | function twig(Prism) {
|
---|
| 7 | Prism.register(refractorMarkupTemplating)
|
---|
| 8 | Prism.languages.twig = {
|
---|
| 9 | comment: /^\{#[\s\S]*?#\}$/,
|
---|
| 10 | 'tag-name': {
|
---|
| 11 | pattern: /(^\{%-?\s*)\w+/,
|
---|
| 12 | lookbehind: true,
|
---|
| 13 | alias: 'keyword'
|
---|
| 14 | },
|
---|
| 15 | delimiter: {
|
---|
| 16 | pattern: /^\{[{%]-?|-?[%}]\}$/,
|
---|
| 17 | alias: 'punctuation'
|
---|
| 18 | },
|
---|
| 19 | string: {
|
---|
| 20 | pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
|
---|
| 21 | inside: {
|
---|
| 22 | punctuation: /^['"]|['"]$/
|
---|
| 23 | }
|
---|
| 24 | },
|
---|
| 25 | keyword: /\b(?:even|if|odd)\b/,
|
---|
| 26 | boolean: /\b(?:false|null|true)\b/,
|
---|
| 27 | number: /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/,
|
---|
| 28 | operator: [
|
---|
| 29 | {
|
---|
| 30 | pattern:
|
---|
| 31 | /(\s)(?:and|b-and|b-or|b-xor|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/,
|
---|
| 32 | lookbehind: true
|
---|
| 33 | },
|
---|
| 34 | /[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/
|
---|
| 35 | ],
|
---|
| 36 | punctuation: /[()\[\]{}:.,]/
|
---|
| 37 | }
|
---|
| 38 | Prism.hooks.add('before-tokenize', function (env) {
|
---|
| 39 | if (env.language !== 'twig') {
|
---|
| 40 | return
|
---|
| 41 | }
|
---|
| 42 | var pattern = /\{(?:#[\s\S]*?#|%[\s\S]*?%|\{[\s\S]*?\})\}/g
|
---|
| 43 | Prism.languages['markup-templating'].buildPlaceholders(env, 'twig', pattern)
|
---|
| 44 | })
|
---|
| 45 | Prism.hooks.add('after-tokenize', function (env) {
|
---|
| 46 | Prism.languages['markup-templating'].tokenizePlaceholders(env, 'twig')
|
---|
| 47 | })
|
---|
| 48 | }
|
---|