Skip to content

Commit a448b97

Browse files
TDaglismarijnh
authored andcommitted
[twig mode] Support a base mode option
1 parent 11f3d96 commit a448b97

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

mode/twig/twig.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
(function(mod) {
55
if (typeof exports == "object" && typeof module == "object") // CommonJS
6-
mod(require("../../lib/codemirror"));
6+
mod(require("../../lib/codemirror"), require("../../addon/mode/multiplex"));
77
else if (typeof define == "function" && define.amd) // AMD
8-
define(["../../lib/codemirror"], mod);
8+
define(["../../lib/codemirror", "../../addon/mode/multiplex"], mod);
99
else // Plain browser env
1010
mod(CodeMirror);
1111
})(function(CodeMirror) {
1212
"use strict";
1313

14-
CodeMirror.defineMode("twig", function() {
14+
CodeMirror.defineMode("twig:inner", function() {
1515
var keywords = ["and", "as", "autoescape", "endautoescape", "block", "do", "endblock", "else", "elseif", "extends", "for", "endfor", "embed", "endembed", "filter", "endfilter", "flush", "from", "if", "endif", "in", "is", "include", "import", "not", "or", "set", "spaceless", "endspaceless", "with", "endwith", "trans", "endtrans", "blocktrans", "endblocktrans", "macro", "endmacro", "use", "verbatim", "endverbatim"],
1616
operator = /^[+\-*&%=<>!?|~^]/,
1717
sign = /^[:\[\(\{]/,
@@ -128,5 +128,14 @@
128128
};
129129
});
130130

131+
CodeMirror.defineMode("twig", function(config, parserConfig) {
132+
var twigInner = CodeMirror.getMode(config, "twig:inner");
133+
if (!parserConfig || !parserConfig.base) return twigInner;
134+
return CodeMirror.multiplexingMode(
135+
CodeMirror.getMode(config, parserConfig.base), {
136+
open: /\{[{#%]/, close: /[}#%]\}/, mode: twigInner, parseDelimiters: true
137+
}
138+
);
139+
});
131140
CodeMirror.defineMIME("text/x-twig", "twig");
132141
});

0 commit comments

Comments
 (0)