OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / scripts / codemirror-3.1 / mode / javascript / index.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: JavaScript mode</title>
6     <link rel="stylesheet" href="../../lib/codemirror.css">
7     <script src="../../lib/codemirror.js"></script>
8     <script src="../../addon/edit/matchbrackets.js"></script>
9     <script src="../../addon/edit/continuecomment.js"></script>
10     <script src="javascript.js"></script>
11     <link rel="stylesheet" href="../../doc/docs.css">
12     <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
13   </head>
14   <body>
15     <h1>CodeMirror: JavaScript mode</h1>
16
17 <div><textarea id="code" name="code">
18 // Demo code (the actual new parser character stream implementation)
19
20 function StringStream(string) {
21   this.pos = 0;
22   this.string = string;
23 }
24
25 StringStream.prototype = {
26   done: function() {return this.pos >= this.string.length;},
27   peek: function() {return this.string.charAt(this.pos);},
28   next: function() {
29     if (this.pos &lt; this.string.length)
30       return this.string.charAt(this.pos++);
31   },
32   eat: function(match) {
33     var ch = this.string.charAt(this.pos);
34     if (typeof match == "string") var ok = ch == match;
35     else var ok = ch &amp;&amp; match.test ? match.test(ch) : match(ch);
36     if (ok) {this.pos++; return ch;}
37   },
38   eatWhile: function(match) {
39     var start = this.pos;
40     while (this.eat(match));
41     if (this.pos > start) return this.string.slice(start, this.pos);
42   },
43   backUp: function(n) {this.pos -= n;},
44   column: function() {return this.pos;},
45   eatSpace: function() {
46     var start = this.pos;
47     while (/\s/.test(this.string.charAt(this.pos))) this.pos++;
48     return this.pos - start;
49   },
50   match: function(pattern, consume, caseInsensitive) {
51     if (typeof pattern == "string") {
52       function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
53       if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
54         if (consume !== false) this.pos += str.length;
55         return true;
56       }
57     }
58     else {
59       var match = this.string.slice(this.pos).match(pattern);
60       if (match &amp;&amp; consume !== false) this.pos += match[0].length;
61       return match;
62     }
63   }
64 };
65 </textarea></div>
66
67     <script>
68       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
69         lineNumbers: true,
70         matchBrackets: true,
71         extraKeys: {"Enter": "newlineAndIndentContinueComment"}
72       });
73     </script>
74
75     <p>
76       JavaScript mode supports a two configuration
77       options:
78       <ul>
79         <li><code>json</code> which will set the mode to expect JSON data rather than a JavaScript program.</li>
80         <li>
81           <code>typescript</code> which will activate additional syntax highlighting and some other things for TypeScript code (<a href="typescript.html">demo</a>).
82         </li>
83       </ul>
84     </p>
85
86     <p><strong>MIME types defined:</strong> <code>text/javascript</code>, <code>application/json</code>, <code>text/typescript</code>, <code>application/typescript</code>.</p>
87   </body>
88 </html>