Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50665 views
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: http://codemirror.net/LICENSE
3
4
(function(mod) {
5
if (typeof exports == "object" && typeof module == "object") // CommonJS
6
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"));
7
else if (typeof define == "function" && define.amd) // AMD
8
define(["../../lib/codemirror", "../htmlmixed/htmlmixed"], mod);
9
else // Plain browser env
10
mod(CodeMirror);
11
})(function(CodeMirror) {
12
"use strict";
13
14
CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
15
16
//config settings
17
var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
18
scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;
19
20
//inner modes
21
var scriptingMode, htmlMixedMode;
22
23
//tokenizer when in html mode
24
function htmlDispatch(stream, state) {
25
if (stream.match(scriptStartRegex, false)) {
26
state.token=scriptingDispatch;
27
return scriptingMode.token(stream, state.scriptState);
28
}
29
else
30
return htmlMixedMode.token(stream, state.htmlState);
31
}
32
33
//tokenizer when in scripting mode
34
function scriptingDispatch(stream, state) {
35
if (stream.match(scriptEndRegex, false)) {
36
state.token=htmlDispatch;
37
return htmlMixedMode.token(stream, state.htmlState);
38
}
39
else
40
return scriptingMode.token(stream, state.scriptState);
41
}
42
43
44
return {
45
startState: function() {
46
scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
47
htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
48
return {
49
token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
50
htmlState : CodeMirror.startState(htmlMixedMode),
51
scriptState : CodeMirror.startState(scriptingMode)
52
};
53
},
54
55
token: function(stream, state) {
56
return state.token(stream, state);
57
},
58
59
indent: function(state, textAfter) {
60
if (state.token == htmlDispatch)
61
return htmlMixedMode.indent(state.htmlState, textAfter);
62
else if (scriptingMode.indent)
63
return scriptingMode.indent(state.scriptState, textAfter);
64
},
65
66
copyState: function(state) {
67
return {
68
token : state.token,
69
htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
70
scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
71
};
72
},
73
74
innerMode: function(state) {
75
if (state.token == scriptingDispatch) return {state: state.scriptState, mode: scriptingMode};
76
else return {state: state.htmlState, mode: htmlMixedMode};
77
}
78
};
79
}, "htmlmixed");
80
81
CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
82
CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
83
CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
84
CodeMirror.defineMIME("application/x-erb", { name: "htmlembedded", scriptingModeSpec:"ruby"});
85
86
});
87
88