Skip to content
Snippets Groups Projects
Commit 88a02578 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[handlebars mode] Make it easier to wrap around a base mode

Issue #3624
parent 49b5d223
No related branches found
No related tags found
No related merge requests found
......@@ -3,15 +3,15 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
mod(require("../../lib/codemirror"), require("../../addon/mode/simple"), require("../../addon/mode/multiplex"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
define(["../../lib/codemirror", "../../addon/mode/simple", "../../addon/mode/multiplex"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineSimpleMode("handlebars", {
CodeMirror.defineSimpleMode("handlebars-tags", {
start: [
{ regex: /\{\{!--/, push: "dash_comment", token: "comment" },
{ regex: /\{\{!/, push: "comment", token: "comment" },
......@@ -49,5 +49,14 @@
]
});
CodeMirror.defineMode("handlebars", function(config, parserConfig) {
var handlebars = CodeMirror.getMode(config, "handlebars-tags");
if (!parserConfig || !parserConfig.base) return handlebars;
return CodeMirror.multiplexingMode(
CodeMirror.getMode(config, parserConfig.base),
{open: "{{", close: "}}", mode: handlebars, parseDelimiters: true}
);
});
CodeMirror.defineMIME("text/x-handlebars-template", "handlebars");
});
......@@ -61,18 +61,10 @@
</textarea></form>
<script>
CodeMirror.defineMode("htmlhandlebars", function(config) {
return CodeMirror.multiplexingMode(
CodeMirror.getMode(config, "text/html"),
{open: "{{", close: "}}",
mode: CodeMirror.getMode(config, "handlebars"),
parseDelimiters: true});
});
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
mode: "htmlhandlebars"
mode: {name: "handlebars", base: "text/html"}
});
</script>
</script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment