prism-twig.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. Prism.languages.twig = {
  2. 'comment': /\{#[\s\S]*?#\}/,
  3. 'tag': {
  4. pattern: /\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}/,
  5. inside: {
  6. 'ld': {
  7. pattern: /^(?:\{\{-?|\{%-?\s*\w+)/,
  8. inside: {
  9. 'punctuation': /^(?:\{\{|\{%)-?/,
  10. 'keyword': /\w+/
  11. }
  12. },
  13. 'rd': {
  14. pattern: /-?(?:%\}|\}\})$/,
  15. inside: {
  16. 'punctuation': /.+/
  17. }
  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(?:true|false|null)\b/,
  27. 'number': /\b0x[\dA-Fa-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][-+]?\d+)?/,
  28. 'operator': [
  29. {
  30. pattern: /(\s)(?:and|b-and|b-xor|b-or|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/,
  31. lookbehind: true
  32. },
  33. /[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/
  34. ],
  35. 'property': /\b[a-zA-Z_]\w*\b/,
  36. 'punctuation': /[()\[\]{}:.,]/
  37. }
  38. },
  39. // The rest can be parsed as HTML
  40. 'other': {
  41. // We want non-blank matches
  42. pattern: /\S(?:[\s\S]*\S)?/,
  43. inside: Prism.languages.markup
  44. }
  45. };