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