aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/htmlembedded
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-14 11:07:21 -0800
committerValerio Virgillito2012-02-14 11:07:21 -0800
commitf060190a3bffd9a16718f2ce0499699103d46372 (patch)
treea308fe7eacec2156c8212dff0892a3de925d5f9a /imports/codemirror/mode/htmlembedded
parentf766cc203f30ea43ae8b83cf4b65d45cc4435ee9 (diff)
parent33bc9d62b8e6694500bf14d5b18187bd99a520a3 (diff)
downloadninja-f060190a3bffd9a16718f2ce0499699103d46372.tar.gz
Merge branch 'FileIO' of https://github.com/joseeight/ninja-internal into integration
Diffstat (limited to 'imports/codemirror/mode/htmlembedded')
-rwxr-xr-ximports/codemirror/mode/htmlembedded/htmlembedded.js68
-rwxr-xr-ximports/codemirror/mode/htmlembedded/index.html49
2 files changed, 117 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 @@
1CodeMirror.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
66CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
67CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
68CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
diff --git a/imports/codemirror/mode/htmlembedded/index.html b/imports/codemirror/mode/htmlembedded/index.html
new file mode 100755
index 00000000..c1374e58
--- /dev/null
+++ b/imports/codemirror/mode/htmlembedded/index.html
@@ -0,0 +1,49 @@
1<!doctype html>
2<html>
3 <head>
4 <title>CodeMirror: Html Embedded Scripts mode</title>
5 <link rel="stylesheet" href="../../lib/codemirror.css">
6 <script src="../../lib/codemirror.js"></script>
7 <script src="../xml/xml.js"></script>
8 <script src="../javascript/javascript.js"></script>
9 <script src="../css/css.js"></script>
10 <script src="../htmlmixed/htmlmixed.js"></script>
11 <script src="htmlembedded.js"></script>
12 <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
13 <link rel="stylesheet" href="../../doc/docs.css">
14 </head>
15 <body>
16 <h1>CodeMirror: Html Embedded Scripts mode</h1>
17
18<form><textarea id="code" name="code">
19<%
20function hello(who) {
21 return "Hello " + who;
22}
23%>
24This is an example of EJS (embedded javascript)
25<p>The program says <%= hello("world") %>.</p>
26<script>
27 alert("And here is some normal JS code"); // also colored
28</script>
29</textarea></form>
30
31 <script>
32 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
33 lineNumbers: true,
34 matchBrackets: true,
35 mode: "application/x-ejs",
36 indentUnit: 4,
37 indentWithTabs: true,
38 enterMode: "keep",
39 tabMode: "shift"
40 });
41 </script>
42
43 <p>Mode for html embedded scripts like JSP and ASP.NET. Depends on HtmlMixed which in turn depends on
44 JavaScript, CSS and XML.<br />Other dependancies include those of the scriping language chosen.</p>
45
46 <p><strong>MIME types defined:</strong> <code>application/x-aspx</code> (ASP.NET),
47 <code>application/x-ejs</code> (Embedded Javascript), <code>application/x-jsp</code> (JavaServer Pages)</p>
48 </body>
49</html>