8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.txt text
*.js text
*.html text
*.md text
*.json text
*.yml text
*.css text
*.svg text
70 changes: 70 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# How to contribute

- [Getting help](#getting-help-)
- [Submitting bug reports](#submitting-bug-reports-)
- [Contributing code](#contributing-code-)

## Getting help [^](#how-to-contribute)

Community discussion, questions, and informal bug reporting is done on the
[CodeMirror Google group](http://groups.google.com/group/codemirror).

## Submitting bug reports [^](#how-to-contribute)

The preferred way to report bugs is to use the
[GitHub issue tracker](http://github.com/marijnh/CodeMirror/issues). Before
reporting a bug, read these pointers.

**Note:** The issue tracker is for *bugs*, not requests for help. Questions
should be asked on the
[CodeMirror Google group](http://groups.google.com/group/codemirror) instead.

### Reporting bugs effectively

- CodeMirror is maintained by volunteers. They don't owe you anything, so be
polite. Reports with an indignant or belligerent tone tend to be moved to the
bottom of the pile.

- Include information about **the browser in which the problem occurred**. Even
if you tested several browsers, and the problem occurred in all of them,
mention this fact in the bug report. Also include browser version numbers and
the operating system that you're on.

- Mention which release of CodeMirror you're using. Preferably, try also with
the current development snapshot, to ensure the problem has not already been
fixed.

- Mention very precisely what went wrong. "X is broken" is not a good bug
report. What did you expect to happen? What happened instead? Describe the
exact steps a maintainer has to take to make the problem occur. We can not
fix something that we can not observe.

- If the problem can not be reproduced in any of the demos included in the
CodeMirror distribution, please provide an HTML document that demonstrates
the problem. The best way to do this is to go to
[jsbin.com](http://jsbin.com/ihunin/edit), enter it there, press save, and
include the resulting link in your bug report.

## Contributing code [^](#how-to-contribute)

- Make sure you have a [GitHub Account](https://github.com/signup/free)
- Fork [CodeMirror](https://github.com/marijnh/CodeMirror/)
([how to fork a repo](https://help.github.com/articles/fork-a-repo))
- Make your changes
- If your changes are easy to test or likely to regress, add tests.
Tests for the core go into `test/test.js`, some modes have their own
test suite under `mode/XXX/test.js`. Feel free to add new test
suites to modes that don't have one yet (be sure to link the new
tests into `test/index.html`).
- Make sure all tests pass. Visit `test/index.html` in your browser to
run them.
- Submit a pull request
([how to create a pull request](https://help.github.com/articles/fork-a-repo))

### Coding standards

- 2 spaces per indentation level, no tabs.
- Include semicolons after statements.
- Note that the linter (`test/lint/lint.js`) which is run after each
commit complains about unused variables and functions. Prefix their
names with an underscore to muffle it.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ CodeMirror is a JavaScript component that provides a code editor in
the browser. When a mode is available for the language you are coding
in, it will color your code, and optionally help with indentation.

The project page is http://codemirror.net
The manual is at http://codemirror.net/doc/manual.html
The project page is http://codemirror.net
The manual is at http://codemirror.net/doc/manual.html
The contributing guidelines are in the CONTRIBUTING.md file
13 changes: 12 additions & 1 deletion demo/vim.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<title>CodeMirror: Vim bindings demo</title>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/codemirror.js"></script>
<script src="../lib/util/dialog.js"></script>
<script src="../lib/util/searchcursor.js"></script>
<script src="../mode/clike/clike.js"></script>
<script src="../keymap/vim.js"></script>
<script src="../lib/util/dialog.js"></script>
<link rel="stylesheet" href="../doc/docs.css">
<link rel="stylesheet" href="../lib/util/dialog.css">

Expand All @@ -34,6 +35,10 @@ <h1>CodeMirror: Vim bindings demo</h1>
}
</textarea></form>

<form><textarea id="code2" name="code2">
I am another file! You can yank from my neighbor and paste here.
</textarea></form>

<p>The vim keybindings are enabled by
including <a href="../keymap/vim.js">keymap/vim.js</a> and setting
the <code>keyMap</code> option to <code>"vim"</code>. Because
Expand All @@ -48,6 +53,12 @@ <h1>CodeMirror: Vim bindings demo</h1>
keyMap: "vim",
showCursorWhenSelecting: true
});
var editor2 = CodeMirror.fromTextArea(document.getElementById("code2"), {
lineNumbers: true,
mode: "text/x-csrc",
keyMap: "vim",
showCursorWhenSelecting: true
});
</script>

</body>
Expand Down
1 change: 1 addition & 0 deletions doc/compress.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<input type="hidden" id="download" name="download" value="codemirror-compressed.js"/>
<p>Version: <select id="version" onchange="setVersion(this);" style="padding: 1px">
<option value="http://codemirror.net/">HEAD</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=v3.0;f=">3.0</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=v3.0rc2;f=">3.0rc2</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=v3.0rc1;f=">3.0rc1</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=v3.0beta2;f=">3.0beta2</option>
Expand Down
24 changes: 18 additions & 6 deletions doc/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/>
<link rel="stylesheet" type="text/css" href="docs.css"/>
<style>dl dl {margin: 0;}</style>
<script src="../lib/codemirror.js"></script>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/util/runmode.js"></script>
<script src="../lib/util/colorize.js"></script>
<script src="../mode/javascript/javascript.js"></script>
<script src="../mode/xml/xml.js"></script>
<script src="../mode/css/css.js"></script>
<script src="../mode/htmlmixed/htmlmixed.js"></script>
</head>
<body>

Expand Down Expand Up @@ -48,21 +56,21 @@ <h2 id="usage">Basic Usage</h2>
(See <a href="compress.html">the compression helper</a> for an
easy way to combine scripts.) For example:</p>

<pre>&lt;script src="lib/codemirror.js">&lt;/script>
<pre data-lang="text/html">&lt;script src="lib/codemirror.js">&lt;/script>
&lt;link rel="stylesheet" href="../lib/codemirror.css">
&lt;script src="mode/javascript/javascript.js">&lt;/script></pre>

<p>Having done this, an editor instance can be created like
this:</p>

<pre>var myCodeMirror = CodeMirror(document.body);</pre>
<pre data-lang="javascript">var myCodeMirror = CodeMirror(document.body);</pre>

<p>The editor will be appended to the document body, will start
empty, and will use the mode that we loaded. To have more control
over the new editor, a configuration object can be passed
to <code>CodeMirror</code> as a second argument:</p>

<pre>var myCodeMirror = CodeMirror(document.body, {
<pre data-lang="javascript">var myCodeMirror = CodeMirror(document.body, {
value: "function myScript(){return 100;}\n",
mode: "javascript"
});</pre>
Expand All @@ -80,15 +88,15 @@ <h2 id="usage">Basic Usage</h2>
document somewhere. This could be used to, for example, replace a
textarea with a real editor:</p>

<pre>var myCodeMirror = CodeMirror(function(elt) {
<pre data-lang="javascript">var myCodeMirror = CodeMirror(function(elt) {
myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});</pre>

<p>However, for this use case, which is a common way to use
CodeMirror, the library provides a much more powerful
shortcut:</p>

<pre>var myCodeMirror = CodeMirror.fromTextArea(myTextArea);</pre>
<pre data-lang="javascript">var myCodeMirror = CodeMirror.fromTextArea(myTextArea);</pre>

<p>This will, among other things, ensure that the textarea's value
is updated with the editor's contents when the form (if it is part
Expand Down Expand Up @@ -1150,6 +1158,8 @@ <h2 id="addons">Add-ons</h2>
the <code>open</code> fields of the passed objects. When in a
sub-mode, it will go back to the top mode again when
the <code>close</code> string is encountered.
Pass <code>"\n"</code> for <code>open</code> or <code>close</code>
if you want to switch on a blank line.
When <code>delimStyle</code> is specified, it will be the token
style returned for the delimiter tokens. The outer mode will not
see the content between the delimiters.
Expand Down Expand Up @@ -1221,7 +1231,7 @@ <h2 id="modeapi">Writing CodeMirror Modes</h2>
CodeMirror. This function takes two arguments. The first should be
the name of the mode, for which you should use a lowercase string,
preferably one that is also the name of the files that define the
mode (i.e. <code>"xml"</code> is defined <code>xml.js</code>). The
mode (i.e. <code>"xml"</code> is defined in <code>xml.js</code>). The
second argument should be a function that, given a CodeMirror
configuration object (the thing passed to
the <code>CodeMirror</code> function) and an optional mode
Expand Down Expand Up @@ -1447,5 +1457,7 @@ <h2>Contents</h2>

<div style="height: 2em">&nbsp;</div>

<script>setTimeout(function(){CodeMirror.colorize();}, 20);</script>

</body>
</html>
2 changes: 2 additions & 0 deletions doc/realworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
<li><a href="http://tour.golang.org">Go language tour</a></li>
<li><a href="https://github.com/github/android">GitHub's Android app</a></li>
<li><a href="https://script.google.com/">Google Apps Script</a></li>
<li><a href="http://web.uvic.ca/~siefkenj/graphit/graphit.html">Graphit</a> (function graphing)</li>
<li><a href="http://try.haxe.org">Haxe</a> (Haxe Playground) </li>
<li><a href="http://haxpad.com/">HaxPad</a> (editor for Win RT)</li>
<li><a href="http://megafonweblab.github.com/histone-javascript/">Histone template engine playground</a></li>
<li><a href="http://icecoder.net">ICEcoder</a> (web IDE)</li>
<li><a href="http://extensions.joomla.org/extensions/edition/editors/8723">Joomla plugin</a></li>
Expand Down
66 changes: 63 additions & 3 deletions doc/upgrade_v3.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<title>CodeMirror: Upgrading to v3</title>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/>
<link rel="stylesheet" type="text/css" href="docs.css"/>
<script src="../lib/codemirror.js"></script>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/util/runmode.js"></script>
<script src="../lib/util/colorize.js"></script>
<script src="../mode/javascript/javascript.js"></script>
<script src="../mode/xml/xml.js"></script>
<script src="../mode/css/css.js"></script>
<script src="../mode/htmlmixed/htmlmixed.js"></script>
</head>
<body>

Expand Down Expand Up @@ -35,9 +43,9 @@ <h2 id=dom>DOM structure</h2>
structure of the editor has changed quite a lot, mostly to implement a
new scrolling model.</p>

<p>Editor height is now set on the outer wrapper (CSS
class <code>CodeMirror</code>) element, not on the scroller
(<code>CodeMirror-scroll</code>) element.</p>
<p>Editor height is now set on the outer wrapper element (CSS
class <code>CodeMirror</code>), not on the scroller element
(<code>CodeMirror-scroll</code>).</p>

<p>Other nodes were moved, dropped, and added. If you have any code
that makes assumptions about the internal DOM structure of the editor,
Expand All @@ -64,6 +72,22 @@ <h2 id=gutters>Gutter model</h2>
The <code>fixedGutter</code> option was removed (since it is now the
only behavior).</p>

<pre data-lang="text/html">
&lt;style>
/* Define a gutter style */
.note-gutter { width: 3em; background: cyan; }
&lt;/style>
&lt;script>
// Create an instance with two gutters -- line numbers and notes
var cm = new CodeMirror(document.body, {
gutters: ["note-gutter", "CodeMirror-linenumbers"],
lineNumbers: true
});
// Add a note to line 0
cm.setGutterMarker(0, "note-gutter", document.createTextNode("hi"));
&lt;/script>
</pre>

<h2 id=events>Event handling</h2>

<p>Most of the <code>onXYZ</code> options have been removed. The same
Expand All @@ -78,6 +102,12 @@ <h2 id=events>Event handling</h2>
which act more as hooks than as event handlers, are still there in
their old form.)</p>

<pre data-lang="javascript">
cm.on("change", function(cm, change) {
console.log("something changed! (" + change.origin + ")");
});
</pre>

<h2 id=marktext>markText method arguments</h2>

<p>The <a href="manual.html#markText"><code>markText</code></a> method
Expand All @@ -86,6 +116,15 @@ <h2 id=marktext>markText method arguments</h2>
takes the CSS class name as a separate argument, but makes it an
optional field in the options object instead.</p>

<pre data-lang="javascript">
// Style first ten lines, and forbid the cursor from entering them
cm.markText({line: 0, ch: 0}, {line: 10, ch: 0}, {
className: "magic-text",
inclusiveLeft: true,
atomic: true
});
</pre>

<h2 id=folding>Line folding</h2>

<p>The interface for hiding lines has been
Expand All @@ -95,13 +134,33 @@ <h2 id=folding>Line folding</h2>
<p>The <a href="../demo/folding.html">folding script</a> has been
updated to use the new interface, and should now be more robust.</p>

<pre data-lang="javascript">
// Fold a range, replacing it with the text "??"
var range = cm.markText({line: 4, ch: 2}, {line: 8, ch: 1}, {
replacedWith: document.createTextNode("??"),
// Auto-unfold when cursor moves into the range
clearOnEnter: true
});
// Get notified when auto-unfolding
CodeMirror.on(range, "clear", function() {
console.log("boom");
});
</pre>

<h2 id=lineclass>Line CSS classes</h2>

<p>The <code>setLineClass</code> method has been replaced
by <a href="manual.html#addLineClass"><code>addLineClass</code></a>
and <a href="manual.html#removeLineClass"><code>removeLineClass</code></a>,
which allow more modular control over the classes attached to a line.</p>

<pre data-lang="javascript">
var marked = cm.addLineClass(10, "background", "highlighted-line");
setTimeout(function() {
cm.removeLineClass(marked, "background", "highlighted-line");
});
</pre>

<h2 id=positions>Position properties</h2>

<p>All methods that take or return objects that represent screen
Expand Down Expand Up @@ -163,5 +222,6 @@ <h2>Contents</h2>

</div></div>

<script>setTimeout(function(){CodeMirror.colorize();}, 20);</script>
</body>
</html>
16 changes: 13 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ <h2 id="supported">Supported browsers</h2>
<p>The following <em>desktop</em> browsers are able to run CodeMirror:</p>

<ul>
<li>Firefox 2 or higher</li>
<li>Firefox 3 or higher</li>
<li>Chrome, any version</li>
<li>Safari 5.2 or higher</li>
<li>Opera 9 or higher (with some key-handling problems on OS X)</li>
Expand Down Expand Up @@ -292,12 +292,22 @@ <h2>Reading material</h2>

<h2 id=releases>Releases</h2>

<p class="rel">20-11-2012: <a href="http://codemirror.net/codemirror-3.0rc2.zip">Version 3.0, release candidate 2</a>:</p>
<p class="rel">20-11-2012: <a href="http://codemirror.net/codemirror-3.0.zip">Version 3.0</a>:</p>

<p class="rel-note"><strong>New major version</strong>. Only
partially backwards-compatible. See
the <a href="doc/upgrade_v3.html">upgrading guide</a> for more
information. Changes since release candidate 1:</p>
information. Changes since release candidate 2:</p>

<ul class="rel-note">
<li>Rewritten VIM mode.</li>
<li>Fix a few minor scrolling and sizing issues.</li>
<li>Work around Safari segfault when dragging.</li>
<li>Full <a href="https://github.com/marijnh/CodeMirror/compare/v3.0rc2...v3.0">list of patches</a>.</li>
</ul>


<p class="rel">20-11-2012: <a href="http://codemirror.net/codemirror-3.0rc2.zip">Version 3.0, release candidate 2</a>:</p>

<ul class="rel-note">
<li>New mode: <a href="mode/http/index.html">HTTP</a>.</li>
Expand Down
Loading