Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
118 lines (102 sloc) 4.06 KB
<!doctype html>
<title>CodeMirror 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<script src="mode/javascript/javascript.js"></script>
<link rel="stylesheet" href="mode/javascript/javascript.css">
<body style="max-width: 70em; margin-left: 2em; font-family: tahoma, arial, sans-serif;">
<h1>CodeMirror 2</h1>
<form><div style="border-top: 1px solid black; border-bottom: 1px solid black;">
<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 this.string.charAt(this.pos);},
next: function() {
if (this.pos &lt; 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;
else var ok = ch &amp;&amp; match.test ? match.test(ch) : match(ch);
if (ok) {this.pos++; return ch;}
eatWhile: function(match) {
var start = this.pos;
while (;
if (this.pos > start) return this.string.slice(start, this.pos);
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, 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;
return true;
else {
var match = this.string.slice(this.pos).match(pattern);
if (match &amp;&amp; consume !== false) this.pos += match[0].length;
return match;
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true
<h3>Available modes:</h3>
<li><a href="mode/javascript/">JavaScript</a></li>
<li><a href="mode/xml/">XML/HTML</a></li>
<li><a href="mode/css/">CSS</a></li>
<li><a href="mode/htmlmixed/">Mixed-mode HTML</a></li>
<li><a href="mode/clike/">Simple mode for C-like languages (C, C++, Java)</a></li>
<li><a href="mode/diff/">Diff</a></li>
<h3>Usage demos:</h3>
<li><a href="demo/complete.html">Clever JS autocompletion</a></li>
<li><a href="demo/mustache.html">Parsing Mustache templates using an overlay</a></li>
<li><a href="demo/resize.html">Non-scrolling, resizing editor</a></li>
<li><a href="demo/marker.html">Setting breakpoints</a></li>
<h3>CodeMirror 2: beta 2</h3>
<p><a href="">Beta
2</a> was released on February 22th 2011. The code is somewhat
more well-tested, and the API has matured a bit since beta 1. The
main thing we need right now is more ports of CodeMirror 1
modes—you're invited to <a href="manual.html#modeapi">help</a>
with that!</p>
<h3>CodeMirror 2: beta 1</h3>
<p>Beta 1 was released on February 8th 2011. There are no release
files yet, just
a <a href="">git
<p>There is now a <a href="manual.html">manual</a>, and you are
encouraged to try the library out and leave bug reports at
the <a href="">github
issue tracker</a> (anything from the editor behaving badly to a
typo in the docs).</p>
<p>Code at <a href=""></a>.</p>
Jump to Line
Something went wrong with that request. Please try again.