prism-handlebars.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. (function (Prism) {
  2. Prism.languages.handlebars = {
  3. 'comment': /\{\{![\s\S]*?\}\}/,
  4. 'delimiter': {
  5. pattern: /^\{\{\{?|\}\}\}?$/,
  6. alias: 'punctuation'
  7. },
  8. 'string': /(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  9. 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][+-]?\d+)?/,
  10. 'boolean': /\b(?:false|true)\b/,
  11. 'block': {
  12. pattern: /^(\s*(?:~\s*)?)[#\/]\S+?(?=\s*(?:~\s*)?$|\s)/,
  13. lookbehind: true,
  14. alias: 'keyword'
  15. },
  16. 'brackets': {
  17. pattern: /\[[^\]]+\]/,
  18. inside: {
  19. punctuation: /\[|\]/,
  20. variable: /[\s\S]+/
  21. }
  22. },
  23. 'punctuation': /[!"#%&':()*+,.\/;<=>@\[\\\]^`{|}~]/,
  24. 'variable': /[^!"#%&'()*+,\/;<=>@\[\\\]^`{|}~\s]+/
  25. };
  26. Prism.hooks.add('before-tokenize', function (env) {
  27. var handlebarsPattern = /\{\{\{[\s\S]+?\}\}\}|\{\{[\s\S]+?\}\}/g;
  28. Prism.languages['markup-templating'].buildPlaceholders(env, 'handlebars', handlebarsPattern);
  29. });
  30. Prism.hooks.add('after-tokenize', function (env) {
  31. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'handlebars');
  32. });
  33. Prism.languages.hbs = Prism.languages.handlebars;
  34. Prism.languages.mustache = Prism.languages.handlebars;
  35. }(Prism));