OLD | NEW |
(Empty) | |
| 1 CodeMirror.defineMode("htmlembedded", function(config, parserConfig) { |
| 2 |
| 3 //config settings |
| 4 var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i, |
| 5 scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i; |
| 6 |
| 7 //inner modes |
| 8 var scriptingMode, htmlMixedMode; |
| 9 |
| 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); |
| 15 } |
| 16 else |
| 17 return htmlMixedMode.token(stream, state.htmlState); |
| 18 } |
| 19 |
| 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); |
| 25 } |
| 26 else |
| 27 return scriptingMode.token(stream, state.scriptState); |
| 28 } |
| 29 |
| 30 |
| 31 return { |
| 32 startState: function() { |
| 33 scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.s
criptingModeSpec); |
| 34 htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed"); |
| 35 return { |
| 36 token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch, |
| 37 htmlState : CodeMirror.startState(htmlMixedMode), |
| 38 scriptState : CodeMirror.startState(scriptingMode) |
| 39 }; |
| 40 }, |
| 41 |
| 42 token: function(stream, state) { |
| 43 return state.token(stream, state); |
| 44 }, |
| 45 |
| 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); |
| 51 }, |
| 52 |
| 53 copyState: function(state) { |
| 54 return { |
| 55 token : state.token, |
| 56 htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState), |
| 57 scriptState : CodeMirror.copyState(scriptingMode, state.scriptState) |
| 58 }; |
| 59 }, |
| 60 |
| 61 electricChars: "/{}:", |
| 62 |
| 63 innerMode: function(state) { |
| 64 if (state.token == scriptingDispatch) return {state: state.scriptState, mo
de: scriptingMode}; |
| 65 else return {state: state.htmlState, mode: htmlMixedMode}; |
| 66 } |
| 67 }; |
| 68 }, "htmlmixed"); |
| 69 |
| 70 CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingMode
Spec:"javascript"}); |
| 71 CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingMod
eSpec:"text/x-csharp"}); |
| 72 CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingMode
Spec:"text/x-java"}); |
| 73 CodeMirror.defineMIME("application/x-erb", { name: "htmlembedded", scriptingMode
Spec:"ruby"}); |
OLD | NEW |