1 CodeMirror
.defineMode("htmlembedded", function(config
, parserConfig
) {
4 var scriptStartRegex
= parserConfig
.scriptStartRegex
|| /^<%/i,
5 scriptEndRegex
= parserConfig
.scriptEndRegex
|| /^%>/i;
8 var scriptingMode
, htmlMixedMode
;
10 //tokenizer when in html mode
11 function htmlDispatch(stream
, state
) {
12 if (stream
.match(scriptStartRegex
, false)) {
13 state
.token
=scriptingDispatch
;
14 return scriptingMode
.token(stream
, state
.scriptState
);
17 return htmlMixedMode
.token(stream
, state
.htmlState
);
20 //tokenizer when in scripting mode
21 function scriptingDispatch(stream
, state
) {
22 if (stream
.match(scriptEndRegex
, false)) {
23 state
.token
=htmlDispatch
;
24 return htmlMixedMode
.token(stream
, state
.htmlState
);
27 return scriptingMode
.token(stream
, state
.scriptState
);
32 startState: function() {
33 scriptingMode
= scriptingMode
|| CodeMirror
.getMode(config
, parserConfig
.scriptingModeSpec
);
34 htmlMixedMode
= htmlMixedMode
|| CodeMirror
.getMode(config
, "htmlmixed");
36 token
: parserConfig
.startOpen
? scriptingDispatch
: htmlDispatch
,
37 htmlState
: CodeMirror
.startState(htmlMixedMode
),
38 scriptState
: CodeMirror
.startState(scriptingMode
)
42 token: function(stream
, state
) {
43 return state
.token(stream
, state
);
46 indent: function(state
, textAfter
) {
47 if (state
.token
== htmlDispatch
)
48 return htmlMixedMode
.indent(state
.htmlState
, textAfter
);
49 else if (scriptingMode
.indent
)
50 return scriptingMode
.indent(state
.scriptState
, textAfter
);
53 copyState: function(state
) {
56 htmlState
: CodeMirror
.copyState(htmlMixedMode
, state
.htmlState
),
57 scriptState
: CodeMirror
.copyState(scriptingMode
, state
.scriptState
)
61 electricChars
: "/{}:",
63 innerMode: function(state
) {
64 if (state
.token
== scriptingDispatch
) return {state
: state
.scriptState
, mode
: scriptingMode
};
65 else return {state
: state
.htmlState
, mode
: htmlMixedMode
};
70 CodeMirror
.defineMIME("application/x-ejs", { name
: "htmlembedded", scriptingModeSpec
:"javascript"});
71 CodeMirror
.defineMIME("application/x-aspx", { name
: "htmlembedded", scriptingModeSpec
:"text/x-csharp"});
72 CodeMirror
.defineMIME("application/x-jsp", { name
: "htmlembedded", scriptingModeSpec
:"text/x-java"});
73 CodeMirror
.defineMIME("application/x-erb", { name
: "htmlembedded", scriptingModeSpec
:"ruby"});