diff options
Diffstat (limited to 'imports/codemirror/mode/properties')
-rwxr-xr-x | imports/codemirror/mode/properties/index.html | 40 | ||||
-rwxr-xr-x | imports/codemirror/mode/properties/properties.css | 3 | ||||
-rwxr-xr-x | imports/codemirror/mode/properties/properties.js | 57 |
3 files changed, 100 insertions, 0 deletions
diff --git a/imports/codemirror/mode/properties/index.html b/imports/codemirror/mode/properties/index.html new file mode 100755 index 00000000..3df6a3ae --- /dev/null +++ b/imports/codemirror/mode/properties/index.html | |||
@@ -0,0 +1,40 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: Properties files mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="properties.js"></script> | ||
8 | <link rel="stylesheet" href="properties.css"> | ||
9 | <style>.CodeMirror {border-top: 1px solid #ddd; border-bottom: 1px solid #ddd;}</style> | ||
10 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
11 | </head> | ||
12 | <body> | ||
13 | <h1>CodeMirror: Properties files mode</h1> | ||
14 | <form><textarea id="code" name="code"> | ||
15 | # This is a properties file | ||
16 | a.key = A value | ||
17 | another.key = http://example.com | ||
18 | ! Exclamation mark as comment | ||
19 | but.not=Within ! A value # indeed | ||
20 | # Spaces at the beginning of a line | ||
21 | spaces.before.key=value | ||
22 | backslash=Used for multi\ | ||
23 | line entries,\ | ||
24 | that's convenient. | ||
25 | # Unicode sequences | ||
26 | unicode.key=This is \u0020 Unicode | ||
27 | no.multiline=here | ||
28 | # Colons | ||
29 | colons : can be used too | ||
30 | # Spaces | ||
31 | spaces\ in\ keys=Not very common... | ||
32 | </textarea></form> | ||
33 | <script> | ||
34 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | ||
35 | </script> | ||
36 | |||
37 | <p><strong>MIME types defined:</strong> <code>text/x-properties</code>.</p> | ||
38 | |||
39 | </body> | ||
40 | </html> | ||
diff --git a/imports/codemirror/mode/properties/properties.css b/imports/codemirror/mode/properties/properties.css new file mode 100755 index 00000000..d975375c --- /dev/null +++ b/imports/codemirror/mode/properties/properties.css | |||
@@ -0,0 +1,3 @@ | |||
1 | span.cm-key {color: #00c;} | ||
2 | span.cm-equals {color: #a11;} | ||
3 | span.cm-value {color: #170;} | ||
diff --git a/imports/codemirror/mode/properties/properties.js b/imports/codemirror/mode/properties/properties.js new file mode 100755 index 00000000..2529505b --- /dev/null +++ b/imports/codemirror/mode/properties/properties.js | |||
@@ -0,0 +1,57 @@ | |||
1 | CodeMirror.defineMode("properties", function() { | ||
2 | return { | ||
3 | token: function(stream, state) { | ||
4 | var sol = stream.sol(); | ||
5 | var eol = stream.eol(); | ||
6 | |||
7 | if (sol) { | ||
8 | if (state.nextMultiline) { | ||
9 | state.inMultiline = true; | ||
10 | state.nextMultiline = false; | ||
11 | } else { | ||
12 | state.position = "key"; | ||
13 | } | ||
14 | } | ||
15 | |||
16 | if (eol && ! state.nextMultiline) { | ||
17 | state.inMultiline = false; | ||
18 | state.position = "key"; | ||
19 | } | ||
20 | |||
21 | if (sol) { | ||
22 | while(stream.eatSpace()); | ||
23 | } | ||
24 | |||
25 | var ch = stream.next(); | ||
26 | |||
27 | if (sol && (ch === "#" || ch === "!")) { | ||
28 | state.position = "comment"; | ||
29 | stream.skipToEnd(); | ||
30 | return "comment"; | ||
31 | |||
32 | } else if (ch === "=" || ch === ":") { | ||
33 | state.position = "value"; | ||
34 | return "equals"; | ||
35 | |||
36 | } else if (ch === "\\" && state.position === "value") { | ||
37 | if (stream.next() !== "u") { // u = Unicode sequence \u1234 | ||
38 | // Multiline value | ||
39 | state.nextMultiline = true; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | return state.position; | ||
44 | }, | ||
45 | |||
46 | startState: function() { | ||
47 | return { | ||
48 | position : "key", // Current position, "key", "value" or "comment" | ||
49 | nextMultiline : false, // Is the next line multiline value | ||
50 | inMultiline : false // Is the current line a multiline value | ||
51 | }; | ||
52 | } | ||
53 | |||
54 | }; | ||
55 | }); | ||
56 | |||
57 | CodeMirror.defineMIME("text/x-properties", "properties"); | ||