prism-tt2.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. (function (Prism) {
  2. Prism.languages.tt2 = Prism.languages.extend('clike', {
  3. 'comment': /#.*|\[%#[\s\S]*?%\]/,
  4. 'keyword': /\b(?:BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|ELSE|ELSIF|END|FILTER|FINAL|FOREACH|GET|IF|IN|INCLUDE|INSERT|LAST|MACRO|META|NEXT|PERL|PROCESS|RAWPERL|RETURN|SET|STOP|SWITCH|TAGS|THROW|TRY|UNLESS|USE|WHILE|WRAPPER)\b/,
  5. 'punctuation': /[[\]{},()]/
  6. });
  7. Prism.languages.insertBefore('tt2', 'number', {
  8. 'operator': /=[>=]?|!=?|<=?|>=?|&&|\|\|?|\b(?:and|not|or)\b/,
  9. 'variable': {
  10. pattern: /\b[a-z]\w*(?:\s*\.\s*(?:\d+|\$?[a-z]\w*))*\b/i
  11. }
  12. });
  13. Prism.languages.insertBefore('tt2', 'keyword', {
  14. 'delimiter': {
  15. pattern: /^(?:\[%|%%)-?|-?%\]$/,
  16. alias: 'punctuation'
  17. }
  18. });
  19. Prism.languages.insertBefore('tt2', 'string', {
  20. 'single-quoted-string': {
  21. pattern: /'[^\\']*(?:\\[\s\S][^\\']*)*'/,
  22. greedy: true,
  23. alias: 'string'
  24. },
  25. 'double-quoted-string': {
  26. pattern: /"[^\\"]*(?:\\[\s\S][^\\"]*)*"/,
  27. greedy: true,
  28. alias: 'string',
  29. inside: {
  30. 'variable': {
  31. pattern: /\$(?:[a-z]\w*(?:\.(?:\d+|\$?[a-z]\w*))*)/i
  32. }
  33. }
  34. }
  35. });
  36. // The different types of TT2 strings "replace" the C-like standard string
  37. delete Prism.languages.tt2.string;
  38. Prism.hooks.add('before-tokenize', function (env) {
  39. var tt2Pattern = /\[%[\s\S]+?%\]/g;
  40. Prism.languages['markup-templating'].buildPlaceholders(env, 'tt2', tt2Pattern);
  41. });
  42. Prism.hooks.add('after-tokenize', function (env) {
  43. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'tt2');
  44. });
  45. }(Prism));