diff options
author | Armen Kesablyan | 2012-02-22 16:26:41 -0800 |
---|---|---|
committer | Armen Kesablyan | 2012-02-22 16:26:41 -0800 |
commit | 0bd1cefea2ab350fad1a891bdc926053b799aafc (patch) | |
tree | 962f559fcc02a3dfeb297d59907e40fa153453f3 /imports/codemirror/mode/htmlembedded/htmlembedded.js | |
parent | 695bc5082f48dddf66ce31480a4faefc067b38bd (diff) | |
parent | 2d2b1af8b5c0d506fe6a1cf65614101fec145970 (diff) | |
download | ninja-0bd1cefea2ab350fad1a891bdc926053b799aafc.tar.gz |
Merge branch 'refs/heads/master' into new-tool-icons
Diffstat (limited to 'imports/codemirror/mode/htmlembedded/htmlembedded.js')
-rwxr-xr-x | imports/codemirror/mode/htmlembedded/htmlembedded.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/imports/codemirror/mode/htmlembedded/htmlembedded.js b/imports/codemirror/mode/htmlembedded/htmlembedded.js new file mode 100755 index 00000000..08e170ea --- /dev/null +++ b/imports/codemirror/mode/htmlembedded/htmlembedded.js | |||
@@ -0,0 +1,68 @@ | |||
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.scriptingModeSpec); | ||
34 | htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed"); | ||
35 | return { | ||
36 | token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch, | ||
37 | htmlState : htmlMixedMode.startState(), | ||
38 | scriptState : scriptingMode.startState() | ||
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 | ||
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 | |||
62 | electricChars: "/{}:" | ||
63 | } | ||
64 | }); | ||
65 | |||
66 | CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"}); | ||
67 | CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"}); | ||
68 | CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"}); | ||