overleaf/services/web/public/js/ace/mode/handlebars_highlight_rules.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
/* global define */
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var xmlUtil = require("./xml_util");
function pop2(currentState, stack) {
stack.splice(0, 3);
return stack.shift() || "start";
}
var HandlebarsHighlightRules = function() {
HtmlHighlightRules.call(this);
var hbs = {
regex : "(?={{)",
push : "handlebars"
}
for (var key in this.$rules) {
this.$rules[key].unshift(hbs);
}
this.$rules.handlebars = [{
token : "comment.start",
regex : "{{!--",
push : [{
token : "comment.end",
regex : "--}}",
next : pop2
}, {
defaultToken : "comment"
}]
}, {
token : "comment.start",
regex : "{{!",
push : [{
token : "comment.end",
regex : "}}",
next : pop2
}, {
defaultToken : "comment"
}]
}, {
token : "storage.type.start", // begin section
regex : "{{[#\\^/&]?",
push : [{
token : "storage.type.end",
regex : "}}",
next : pop2
}, {
token : "variable.parameter",
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*"
}]
}, {
token : "support.function", // unescaped variable
regex : "{{{",
push : [{
token : "support.function",
regex : "}}}",
next : pop2
}, {
token : "variable.parameter",
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*"
}]
}];
this.normalizeRules();
};
oop.inherits(HandlebarsHighlightRules, HtmlHighlightRules);
exports.HandlebarsHighlightRules = HandlebarsHighlightRules;
});