prism-velocity.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. (function (Prism) {
  2. Prism.languages.velocity = Prism.languages.extend('markup', {});
  3. var velocity = {
  4. 'variable': {
  5. pattern: /(^|[^\\](?:\\\\)*)\$!?(?:[a-z][\w-]*(?:\([^)]*\))?(?:\.[a-z][\w-]*(?:\([^)]*\))?|\[[^\]]+\])*|\{[^}]+\})/i,
  6. lookbehind: true,
  7. inside: {} // See below
  8. },
  9. 'string': {
  10. pattern: /"[^"]*"|'[^']*'/,
  11. greedy: true
  12. },
  13. 'number': /\b\d+\b/,
  14. 'boolean': /\b(?:false|true)\b/,
  15. 'operator': /[=!<>]=?|[+*/%-]|&&|\|\||\.\.|\b(?:eq|g[et]|l[et]|n(?:e|ot))\b/,
  16. 'punctuation': /[(){}[\]:,.]/
  17. };
  18. velocity.variable.inside = {
  19. 'string': velocity['string'],
  20. 'function': {
  21. pattern: /([^\w-])[a-z][\w-]*(?=\()/,
  22. lookbehind: true
  23. },
  24. 'number': velocity['number'],
  25. 'boolean': velocity['boolean'],
  26. 'punctuation': velocity['punctuation']
  27. };
  28. Prism.languages.insertBefore('velocity', 'comment', {
  29. 'unparsed': {
  30. pattern: /(^|[^\\])#\[\[[\s\S]*?\]\]#/,
  31. lookbehind: true,
  32. greedy: true,
  33. inside: {
  34. 'punctuation': /^#\[\[|\]\]#$/
  35. }
  36. },
  37. 'velocity-comment': [
  38. {
  39. pattern: /(^|[^\\])#\*[\s\S]*?\*#/,
  40. lookbehind: true,
  41. greedy: true,
  42. alias: 'comment'
  43. },
  44. {
  45. pattern: /(^|[^\\])##.*/,
  46. lookbehind: true,
  47. greedy: true,
  48. alias: 'comment'
  49. }
  50. ],
  51. 'directive': {
  52. pattern: /(^|[^\\](?:\\\\)*)#@?(?:[a-z][\w-]*|\{[a-z][\w-]*\})(?:\s*\((?:[^()]|\([^()]*\))*\))?/i,
  53. lookbehind: true,
  54. inside: {
  55. 'keyword': {
  56. pattern: /^#@?(?:[a-z][\w-]*|\{[a-z][\w-]*\})|\bin\b/,
  57. inside: {
  58. 'punctuation': /[{}]/
  59. }
  60. },
  61. rest: velocity
  62. }
  63. },
  64. 'variable': velocity['variable']
  65. });
  66. Prism.languages.velocity['tag'].inside['attr-value'].inside.rest = Prism.languages.velocity;
  67. }(Prism));