handlebars_highlight_rules.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* global define */
  2. define(function(require, exports, module) {
  3. "use strict";
  4. var oop = require("../lib/oop");
  5. var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
  6. function pop2(currentState, stack) {
  7. stack.splice(0, 3);
  8. return stack.shift() || "start";
  9. }
  10. var HandlebarsHighlightRules = function() {
  11. HtmlHighlightRules.call(this);
  12. var hbs = {
  13. regex : "(?={{)",
  14. push : "handlebars"
  15. };
  16. for (var key in this.$rules) {
  17. this.$rules[key].unshift(hbs);
  18. }
  19. this.$rules.handlebars = [{
  20. token : "comment.start",
  21. regex : "{{!--",
  22. push : [{
  23. token : "comment.end",
  24. regex : "--}}",
  25. next : pop2
  26. }, {
  27. defaultToken : "comment"
  28. }]
  29. }, {
  30. token : "comment.start",
  31. regex : "{{!",
  32. push : [{
  33. token : "comment.end",
  34. regex : "}}",
  35. next : pop2
  36. }, {
  37. defaultToken : "comment"
  38. }]
  39. }, {
  40. token : "support.function", // unescaped variable
  41. regex : "{{{",
  42. push : [{
  43. token : "support.function",
  44. regex : "}}}",
  45. next : pop2
  46. }, {
  47. token : "variable.parameter",
  48. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*"
  49. }]
  50. }, {
  51. token : "storage.type.start", // begin section
  52. regex : "{{[#\\^/&]?",
  53. push : [{
  54. token : "storage.type.end",
  55. regex : "}}",
  56. next : pop2
  57. }, {
  58. token : "variable.parameter",
  59. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*"
  60. }]
  61. }];
  62. this.normalizeRules();
  63. };
  64. oop.inherits(HandlebarsHighlightRules, HtmlHighlightRules);
  65. exports.HandlebarsHighlightRules = HandlebarsHighlightRules;
  66. });