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/,
  21. inside: {
  22. 'punctuation': /^('|")|('|")$/
  23. }
  24. },
  25. 'keyword': /\b(if)\b/,
  26. 'boolean': /\b(true|false|null)\b/,
  27. 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
  28. 'operator': /==|=|!=|<|>|>=|<=|\+|\-|~|\*|\/|\/\/|%|\*\*|\|/,
  29. 'space-operator': {
  30. pattern: /(\s)(\b(not|b\-and|b\-xor|b\-or|and|or|in|matches|starts with|ends with|is)\b|\?|:|\?:)(?=\s)/,
  31. lookbehind: true,
  32. inside: {
  33. 'operator': /.*/
  34. }
  35. },
  36. 'property': /\b[a-zA-Z_][a-zA-Z0-9_]*\b/,
  37. 'punctuation': /\(|\)|\[\]|\[|\]|\{|\}|:|\.|,/
  38. }
  39. },
  40. // The rest can be parsed as HTML
  41. 'other': {
  42. pattern: /[\s\S]*/,
  43. inside: Prism.languages.markup
  44. }
  45. };