2 if (typeof exports
== "object" && typeof module
== "object") // CommonJS
3 mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"));
4 else if (typeof define
== "function" && define
.amd
) // AMD
5 define(["../../lib/codemirror", "../htmlmixed/htmlmixed"], mod
);
6 else // Plain browser env
8 })(function(CodeMirror
) {
11 CodeMirror
.defineMode("htmlembedded", function(config
, parserConfig
) {
14 var scriptStartRegex
= parserConfig
.scriptStartRegex
|| /^<%/i,
15 scriptEndRegex
= parserConfig
.scriptEndRegex
|| /^%>/i;
18 var scriptingMode
, htmlMixedMode
;
20 //tokenizer when in html mode
21 function htmlDispatch(stream
, state
) {
22 if (stream
.match(scriptStartRegex
, false)) {
23 state
.token
=scriptingDispatch
;
24 return scriptingMode
.token(stream
, state
.scriptState
);
27 return htmlMixedMode
.token(stream
, state
.htmlState
);
30 //tokenizer when in scripting mode
31 function scriptingDispatch(stream
, state
) {
32 if (stream
.match(scriptEndRegex
, false)) {
33 state
.token
=htmlDispatch
;
34 return htmlMixedMode
.token(stream
, state
.htmlState
);
37 return scriptingMode
.token(stream
, state
.scriptState
);
42 startState: function() {
43 scriptingMode
= scriptingMode
|| CodeMirror
.getMode(config
, parserConfig
.scriptingModeSpec
);
44 htmlMixedMode
= htmlMixedMode
|| CodeMirror
.getMode(config
, "htmlmixed");
46 token
: parserConfig
.startOpen
? scriptingDispatch
: htmlDispatch
,
47 htmlState
: CodeMirror
.startState(htmlMixedMode
),
48 scriptState
: CodeMirror
.startState(scriptingMode
)
52 token: function(stream
, state
) {
53 return state
.token(stream
, state
);
56 indent: function(state
, textAfter
) {
57 if (state
.token
== htmlDispatch
)
58 return htmlMixedMode
.indent(state
.htmlState
, textAfter
);
59 else if (scriptingMode
.indent
)
60 return scriptingMode
.indent(state
.scriptState
, textAfter
);
63 copyState: function(state
) {
66 htmlState
: CodeMirror
.copyState(htmlMixedMode
, state
.htmlState
),
67 scriptState
: CodeMirror
.copyState(scriptingMode
, state
.scriptState
)
71 innerMode: function(state
) {
72 if (state
.token
== scriptingDispatch
) return {state
: state
.scriptState
, mode
: scriptingMode
};
73 else return {state
: state
.htmlState
, mode
: htmlMixedMode
};
78 CodeMirror
.defineMIME("application/x-ejs", { name
: "htmlembedded", scriptingModeSpec
:"javascript"});
79 CodeMirror
.defineMIME("application/x-aspx", { name
: "htmlembedded", scriptingModeSpec
:"text/x-csharp"});
80 CodeMirror
.defineMIME("application/x-jsp", { name
: "htmlembedded", scriptingModeSpec
:"text/x-java"});
81 CodeMirror
.defineMIME("application/x-erb", { name
: "htmlembedded", scriptingModeSpec
:"ruby"});