Merge pull request #850 from fperez/codemirror

Update codemirror to 2.15 and make the code internally more version-agnostic.

Added our own README file with information about what changes we carry to upstream CodeMirror and what version we currently use.
This commit is contained in:
Fernando Perez 2011-10-14 13:30:55 -07:00
commit df43150509
2 changed files with 48 additions and 43 deletions

View File

@ -1,11 +1,15 @@
CodeMirror.defineMode("python", function(conf) {
CodeMirror.defineMode("python", function(conf, parserConf) {
var ERRORCLASS = 'error';
function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
}
// IPython-specific changes: add '?' as recognized character.
//var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]");
// End IPython changes.
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
@ -29,7 +33,7 @@ CodeMirror.defineMode("python", function(conf) {
'open', 'range', 'zip'],
'keywords': ['nonlocal']};
if (!!conf.mode.version && parseInt(conf.mode.version, 10) === 3) {
if (!!parserConf.version && parseInt(parserConf.version, 10) === 3) {
commonkeywords = commonkeywords.concat(py3.keywords);
commontypes = commontypes.concat(py3.types);
var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i");
@ -65,15 +69,15 @@ CodeMirror.defineMode("python", function(conf) {
if (stream.eatSpace()) {
return null;
}
var ch = stream.peek();
// Handle Comments
if (ch === '#') {
stream.skipToEnd();
return 'comment';
}
// Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) {
var floatLiteral = false;
@ -109,13 +113,13 @@ CodeMirror.defineMode("python", function(conf) {
return 'number';
}
}
// Handle Strings
if (stream.match(stringPrefixes)) {
state.tokenize = tokenStringFactory(stream.current());
return state.tokenize(stream, state);
}
// Handle operators and Delimiters
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
return null;
@ -128,32 +132,31 @@ CodeMirror.defineMode("python", function(conf) {
if (stream.match(singleDelimiters)) {
return null;
}
if (stream.match(types)) {
return 'builtin';
}
if (stream.match(keywords)) {
return 'keyword';
}
if (stream.match(identifiers)) {
return 'variable';
}
// Handle non-detected items
stream.next();
return ERRORCLASS;
}
function tokenStringFactory(delimiter) {
while ('rub'.indexOf(delimiter[0].toLowerCase()) >= 0) {
while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
delimiter = delimiter.substr(1);
}
var delim_re = new RegExp(delimiter);
var singleline = delimiter.length == 1;
var OUTCLASS = 'string';
return function tokenString(stream, state) {
while (!stream.eol()) {
stream.eatWhile(/[^'"\\]/);
@ -162,7 +165,7 @@ CodeMirror.defineMode("python", function(conf) {
if (singleline && stream.eol()) {
return OUTCLASS;
}
} else if (stream.match(delim_re)) {
} else if (stream.match(delimiter)) {
state.tokenize = tokenBase;
return OUTCLASS;
} else {
@ -170,8 +173,8 @@ CodeMirror.defineMode("python", function(conf) {
}
}
if (singleline) {
if (conf.mode.singleLineStringErrors) {
OUTCLASS = ERRORCLASS
if (parserConf.singleLineStringErrors) {
return ERRORCLASS;
} else {
state.tokenize = tokenBase;
}
@ -179,7 +182,7 @@ CodeMirror.defineMode("python", function(conf) {
return OUTCLASS;
};
}
function indent(stream, state, type) {
type = type || 'py';
var indentUnit = 0;
@ -198,7 +201,7 @@ CodeMirror.defineMode("python", function(conf) {
type: type
});
}
function dedent(stream, state) {
if (state.scopes.length == 1) return;
if (state.scopes[0].type === 'py') {
@ -238,7 +241,7 @@ CodeMirror.defineMode("python", function(conf) {
return ERRORCLASS;
}
}
// Handle decorators
if (current === '@') {
style = state.tokenize(stream, state);
@ -251,7 +254,7 @@ CodeMirror.defineMode("python", function(conf) {
return ERRORCLASS;
}
}
// Handle scope changes.
if (current === 'pass' || current === 'return') {
state.dedent += 1;
@ -279,7 +282,7 @@ CodeMirror.defineMode("python", function(conf) {
if (state.scopes.length > 1) state.scopes.shift();
state.dedent -= 1;
}
return style;
}
@ -293,27 +296,27 @@ CodeMirror.defineMode("python", function(conf) {
dedent: 0
};
},
token: function(stream, state) {
var style = tokenLexer(stream, state);
state.lastToken = {style:style, content: stream.current()};
if (stream.eol() && stream.lambda) {
state.lambda = false;
}
return style;
},
indent: function(state, textAfter) {
if (state.tokenize != tokenBase) {
return 0;
}
return state.scopes[0].offset;
}
};
return external;
});

View File

@ -21,10 +21,11 @@
}
</script>
<link rel="stylesheet" href="static/codemirror-2.12/lib/codemirror.css">
<link rel="stylesheet" href="static/codemirror-2.12/mode/rst/rst.css">
<link rel="stylesheet" href="static/codemirror-2.12/theme/ipython.css">
<link rel="stylesheet" href="static/codemirror-2.12/theme/default.css">
<link rel="stylesheet" href="static/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="static/codemirror/mode/markdown/markdown.css">
<link rel="stylesheet" href="static/codemirror/mode/rst/rst.css">
<link rel="stylesheet" href="static/codemirror/theme/ipython.css">
<link rel="stylesheet" href="static/codemirror/theme/default.css">
<link rel="stylesheet" href="static/prettify/prettify.css"/>
@ -208,13 +209,14 @@
<script src="static/jquery/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"></script>
<script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script>
<script src="static/codemirror-2.12/lib/codemirror.js" charset="utf-8"></script>
<script src="static/codemirror-2.12/mode/python/python.js" charset="utf-8"></script>
<script src="static/codemirror-2.12/mode/htmlmixed/htmlmixed.js" charset="utf-8"></script>
<script src="static/codemirror-2.12/mode/xml/xml.js" charset="utf-8"></script>
<script src="static/codemirror-2.12/mode/javascript/javascript.js" charset="utf-8"></script>
<script src="static/codemirror-2.12/mode/css/css.js" charset="utf-8"></script>
<script src="static/codemirror-2.12/mode/rst/rst.js" charset="utf-8"></script>
<script src="static/codemirror/lib/codemirror.js" charset="utf-8"></script>
<script src="static/codemirror/mode/python/python.js" charset="utf-8"></script>
<script src="static/codemirror/mode/htmlmixed/htmlmixed.js" charset="utf-8"></script>
<script src="static/codemirror/mode/xml/xml.js" charset="utf-8"></script>
<script src="static/codemirror/mode/javascript/javascript.js" charset="utf-8"></script>
<script src="static/codemirror/mode/css/css.js" charset="utf-8"></script>
<script src="static/codemirror/mode/rst/rst.js" charset="utf-8"></script>
<script src="static/codemirror/mode/markdown/markdown.js" charset="utf-8"></script>
<script src="static/pagedown/Markdown.Converter.js" charset="utf-8"></script>