| 776 |
lars |
1 |
<!doctype html>
|
|
|
2 |
<title>CodeMirror: JavaScript mode</title>
|
|
|
3 |
<meta charset="utf-8" />
|
|
|
4 |
<link rel=stylesheet href="../../doc/docs.css">
|
|
|
5 |
<link rel="stylesheet" href="../../lib/codemirror.css">
|
|
|
6 |
<script src="../../lib/codemirror.js"></script>
|
|
|
7 |
<script src="../../addon/edit/matchbrackets.js"></script>
|
|
|
8 |
<script src="../../addon/comment/continuecomment.js"></script>
|
|
|
9 |
<script src="../../addon/comment/comment.js"></script>
|
|
|
10 |
<script src="javascript.js"></script>
|
|
|
11 |
<style type="text/css">
|
|
|
12 |
.CodeMirror {
|
|
|
13 |
border-top: 1px solid black;
|
|
|
14 |
border-bottom: 1px solid black;
|
|
|
15 |
}
|
|
|
16 |
</style>
|
|
|
17 |
<div id=nav>
|
|
|
18 |
<a href="http://codemirror.net">
|
|
|
19 |
<h1>CodeMirror</h1>
|
|
|
20 |
<img id=logo src="../../doc/logo.png">
|
|
|
21 |
</a>
|
|
|
22 |
<ul>
|
|
|
23 |
<li>
|
|
|
24 |
<a href="../../index.html">Home</a>
|
|
|
25 |
<li>
|
|
|
26 |
<a href="../../doc/manual.html">Manual</a>
|
|
|
27 |
<li>
|
|
|
28 |
<a href="https://github.com/codemirror/codemirror">Code</a>
|
|
|
29 |
</ul>
|
|
|
30 |
<ul>
|
|
|
31 |
<li>
|
|
|
32 |
<a href="../index.html">Language modes</a>
|
|
|
33 |
<li>
|
|
|
34 |
<a class=active href="#">JavaScript</a>
|
|
|
35 |
</ul>
|
|
|
36 |
</div>
|
|
|
37 |
<article>
|
|
|
38 |
<h2>JavaScript mode</h2>
|
|
|
39 |
<div>
|
|
|
40 |
<textarea id="code" name="code"> // Demo code (the actual new parser character stream implementation) function StringStream(string) { this.pos = 0; this.string = string; } StringStream.prototype = { done: function() {return this.pos >= this.string.length;}, peek: function() {return
|
|
|
41 |
this.string.charAt(this.pos);}, next: function() { if (this.pos < this.string.length) return this.string.charAt(this.pos++); }, eat: function(match) { var ch = this.string.charAt(this.pos); if (typeof match == "string") var ok = ch == match;
|
|
|
42 |
else var ok = ch && match.test ? match.test(ch) : match(ch); if (ok) {this.pos++; return ch;} }, eatWhile: function(match) { var start = this.pos; while (this.eat(match)); if (this.pos > start) return this.string.slice(start, this.pos);
|
|
|
43 |
}, backUp: function(n) {this.pos -= n;}, column: function() {return this.pos;}, eatSpace: function() { var start = this.pos; while (/\s/.test(this.string.charAt(this.pos))) this.pos++; return this.pos - start; }, match: function(pattern, consume,
|
|
|
44 |
caseInsensitive) { if (typeof pattern == "string") { function cased(str) {return caseInsensitive ? str.toLowerCase() : str;} if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) { if (consume !== false) this.pos += str.length;
|
|
|
45 |
return true; } } else { var match = this.string.slice(this.pos).match(pattern); if (match && consume !== false) this.pos += match[0].length; return match; } } }; </textarea>
|
|
|
46 |
</div>
|
|
|
47 |
<script>
|
|
|
48 |
var editor = CodeMirror.fromTextArea(document.getElementById("code"),
|
|
|
49 |
{
|
|
|
50 |
lineNumbers: true,
|
|
|
51 |
matchBrackets: true,
|
|
|
52 |
continueComments: "Enter",
|
|
|
53 |
extraKeys:
|
|
|
54 |
{
|
|
|
55 |
"Ctrl-Q": "toggleComment"
|
|
|
56 |
}
|
|
|
57 |
});
|
|
|
58 |
</script>
|
|
|
59 |
<p> JavaScript mode supports several configuration options:
|
|
|
60 |
<ul>
|
|
|
61 |
<li><code>json</code> which will set the mode to expect JSON data rather than a JavaScript program.</li>
|
|
|
62 |
<li><code>jsonld</code> which will set the mode to expect
|
|
|
63 |
<a href="http://json-ld.org">JSON-LD</a> linked data rather than a JavaScript program (
|
|
|
64 |
<a href="json-ld.html">demo</a>).</li>
|
|
|
65 |
<li><code>typescript</code> which will activate additional syntax highlighting and some other things for TypeScript code (
|
|
|
66 |
<a href="typescript.html">demo</a>).</li>
|
|
|
67 |
<li><code>statementIndent</code> which (given a number) will determine the amount of indentation to use for statements continued on a new line.</li>
|
|
|
68 |
<li><code>wordCharacters</code>, a regexp that indicates which characters should be considered part of an identifier. Defaults to <code>/[\w$]/</code>, which does not handle non-ASCII identifiers. Can be set to something more elaborate to improve
|
|
|
69 |
Unicode support.</li>
|
|
|
70 |
</ul>
|
|
|
71 |
</p>
|
|
|
72 |
<p>
|
|
|
73 |
<strong>MIME types defined:</strong> <code>text/javascript</code>, <code>application/json</code>, <code>application/ld+json</code>, <code>text/typescript</code>, <code>application/typescript</code>.</p>
|
|
|
74 |
</article>
|