prism-latte.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. (function (Prism) {
  2. Prism.languages.latte = {
  3. 'comment': /^\{\*[\s\S]*/,
  4. 'latte-tag': {
  5. // https://latte.nette.org/en/tags
  6. pattern: /(^\{(?:\/(?=[a-z]))?)(?:[=_]|[a-z]\w*\b(?!\())/i,
  7. lookbehind: true,
  8. alias: 'important'
  9. },
  10. 'delimiter': {
  11. pattern: /^\{\/?|\}$/,
  12. alias: 'punctuation'
  13. },
  14. 'php': {
  15. pattern: /\S(?:[\s\S]*\S)?/,
  16. alias: 'language-php',
  17. inside: Prism.languages.php
  18. }
  19. };
  20. var markupLatte = Prism.languages.extend('markup', {});
  21. Prism.languages.insertBefore('inside', 'attr-value', {
  22. 'n-attr': {
  23. pattern: /n:[\w-]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+))?/,
  24. inside: {
  25. 'attr-name': {
  26. pattern: /^[^\s=]+/,
  27. alias: 'important'
  28. },
  29. 'attr-value': {
  30. pattern: /=[\s\S]+/,
  31. inside: {
  32. 'punctuation': [
  33. /^=/,
  34. {
  35. pattern: /^(\s*)["']|["']$/,
  36. lookbehind: true
  37. }
  38. ],
  39. 'php': {
  40. pattern: /\S(?:[\s\S]*\S)?/,
  41. inside: Prism.languages.php
  42. }
  43. }
  44. },
  45. }
  46. },
  47. }, markupLatte.tag);
  48. Prism.hooks.add('before-tokenize', function (env) {
  49. if (env.language !== 'latte') {
  50. return;
  51. }
  52. var lattePattern = /\{\*[\s\S]*?\*\}|\{[^'"\s{}*](?:[^"'/{}]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|\/\*(?:[^*]|\*(?!\/))*\*\/)*\}/g;
  53. Prism.languages['markup-templating'].buildPlaceholders(env, 'latte', lattePattern);
  54. env.grammar = markupLatte;
  55. });
  56. Prism.hooks.add('after-tokenize', function (env) {
  57. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'latte');
  58. });
  59. }(Prism));