mirror of
https://github.com/documize/community.git
synced 2025-07-24 23:59:47 +02:00
upgraded libs and improved Markdown editing experience
This commit is contained in:
parent
2e146cf767
commit
ea1a8000ee
165 changed files with 15930 additions and 19013 deletions
119
app/public/codemirror/mode/python/python.js
vendored
119
app/public/codemirror/mode/python/python.js
vendored
|
@ -32,13 +32,6 @@
|
|||
"sorted", "staticmethod", "str", "sum", "super", "tuple",
|
||||
"type", "vars", "zip", "__import__", "NotImplemented",
|
||||
"Ellipsis", "__debug__"];
|
||||
var py2 = {builtins: ["apply", "basestring", "buffer", "cmp", "coerce", "execfile",
|
||||
"file", "intern", "long", "raw_input", "reduce", "reload",
|
||||
"unichr", "unicode", "xrange", "False", "True", "None"],
|
||||
keywords: ["exec", "print"]};
|
||||
var py3 = {builtins: ["ascii", "bytes", "exec", "print"],
|
||||
keywords: ["nonlocal", "False", "True", "None", "async", "await"]};
|
||||
|
||||
CodeMirror.registerHelper("hintWords", "python", commonKeywords.concat(commonBuiltins));
|
||||
|
||||
function top(state) {
|
||||
|
@ -53,46 +46,46 @@
|
|||
var doubleDelimiters = parserConf.doubleDelimiters || /^(\+=|\-=|\*=|%=|\/=|&=|\|=|\^=)/;
|
||||
var tripleDelimiters = parserConf.tripleDelimiters || /^(\/\/=|>>=|<<=|\*\*=)/;
|
||||
|
||||
if (parserConf.version && parseInt(parserConf.version, 10) == 3){
|
||||
// since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator
|
||||
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!@]/;
|
||||
var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*/;
|
||||
} else {
|
||||
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!]/;
|
||||
var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*/;
|
||||
}
|
||||
|
||||
var hangingIndent = parserConf.hangingIndent || conf.indentUnit;
|
||||
|
||||
var myKeywords = commonKeywords, myBuiltins = commonBuiltins;
|
||||
if(parserConf.extra_keywords != undefined){
|
||||
if (parserConf.extra_keywords != undefined)
|
||||
myKeywords = myKeywords.concat(parserConf.extra_keywords);
|
||||
}
|
||||
if(parserConf.extra_builtins != undefined){
|
||||
|
||||
if (parserConf.extra_builtins != undefined)
|
||||
myBuiltins = myBuiltins.concat(parserConf.extra_builtins);
|
||||
}
|
||||
if (parserConf.version && parseInt(parserConf.version, 10) == 3) {
|
||||
myKeywords = myKeywords.concat(py3.keywords);
|
||||
myBuiltins = myBuiltins.concat(py3.builtins);
|
||||
var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i");
|
||||
|
||||
var py3 = !(parserConf.version && Number(parserConf.version) < 3)
|
||||
if (py3) {
|
||||
// since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator
|
||||
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!@]/;
|
||||
var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*/;
|
||||
myKeywords = myKeywords.concat(["nonlocal", "False", "True", "None", "async", "await"]);
|
||||
myBuiltins = myBuiltins.concat(["ascii", "bytes", "exec", "print"]);
|
||||
var stringPrefixes = new RegExp("^(([rbuf]|(br))?('{3}|\"{3}|['\"]))", "i");
|
||||
} else {
|
||||
myKeywords = myKeywords.concat(py2.keywords);
|
||||
myBuiltins = myBuiltins.concat(py2.builtins);
|
||||
var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
|
||||
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!]/;
|
||||
var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*/;
|
||||
myKeywords = myKeywords.concat(["exec", "print"]);
|
||||
myBuiltins = myBuiltins.concat(["apply", "basestring", "buffer", "cmp", "coerce", "execfile",
|
||||
"file", "intern", "long", "raw_input", "reduce", "reload",
|
||||
"unichr", "unicode", "xrange", "False", "True", "None"]);
|
||||
var stringPrefixes = new RegExp("^(([rubf]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
|
||||
}
|
||||
var keywords = wordRegexp(myKeywords);
|
||||
var builtins = wordRegexp(myBuiltins);
|
||||
|
||||
// tokenizers
|
||||
function tokenBase(stream, state) {
|
||||
if (stream.sol()) state.indent = stream.indentation()
|
||||
// Handle scope changes
|
||||
if (stream.sol() && top(state).type == "py") {
|
||||
var scopeOffset = top(state).offset;
|
||||
if (stream.eatSpace()) {
|
||||
var lineOffset = stream.indentation();
|
||||
if (lineOffset > scopeOffset)
|
||||
pushScope(stream, state, "py");
|
||||
else if (lineOffset < scopeOffset && dedent(stream, state))
|
||||
pushPyScope(state);
|
||||
else if (lineOffset < scopeOffset && dedent(stream, state) && stream.peek() != "#")
|
||||
state.errorToken = true;
|
||||
return null;
|
||||
} else {
|
||||
|
@ -120,8 +113,8 @@
|
|||
if (stream.match(/^[0-9\.]/, false)) {
|
||||
var floatLiteral = false;
|
||||
// Floats
|
||||
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
|
||||
if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
|
||||
if (stream.match(/^[\d_]*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
|
||||
if (stream.match(/^[\d_]+\.\d*/)) { floatLiteral = true; }
|
||||
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
|
||||
if (floatLiteral) {
|
||||
// Float literals may be "imaginary"
|
||||
|
@ -131,13 +124,13 @@
|
|||
// Integers
|
||||
var intLiteral = false;
|
||||
// Hex
|
||||
if (stream.match(/^0x[0-9a-f]+/i)) intLiteral = true;
|
||||
if (stream.match(/^0x[0-9a-f_]+/i)) intLiteral = true;
|
||||
// Binary
|
||||
if (stream.match(/^0b[01]+/i)) intLiteral = true;
|
||||
if (stream.match(/^0b[01_]+/i)) intLiteral = true;
|
||||
// Octal
|
||||
if (stream.match(/^0o[0-7]+/i)) intLiteral = true;
|
||||
if (stream.match(/^0o[0-7_]+/i)) intLiteral = true;
|
||||
// Decimal
|
||||
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
|
||||
if (stream.match(/^[1-9][\d_]*(e[\+\-]?[\d_]+)?/)) {
|
||||
// Decimal literals may be "imaginary"
|
||||
stream.eat(/J/i);
|
||||
// TODO - Can you have imaginary longs?
|
||||
|
@ -192,7 +185,7 @@
|
|||
}
|
||||
|
||||
function tokenStringFactory(delimiter) {
|
||||
while ("rub".indexOf(delimiter.charAt(0).toLowerCase()) >= 0)
|
||||
while ("rubf".indexOf(delimiter.charAt(0).toLowerCase()) >= 0)
|
||||
delimiter = delimiter.substr(1);
|
||||
|
||||
var singleline = delimiter.length == 1;
|
||||
|
@ -224,21 +217,23 @@
|
|||
return tokenString;
|
||||
}
|
||||
|
||||
function pushScope(stream, state, type) {
|
||||
var offset = 0, align = null;
|
||||
if (type == "py") {
|
||||
while (top(state).type != "py")
|
||||
state.scopes.pop();
|
||||
}
|
||||
offset = top(state).offset + (type == "py" ? conf.indentUnit : hangingIndent);
|
||||
if (type != "py" && !stream.match(/^(\s|#.*)*$/, false))
|
||||
align = stream.column() + 1;
|
||||
state.scopes.push({offset: offset, type: type, align: align});
|
||||
function pushPyScope(state) {
|
||||
while (top(state).type != "py") state.scopes.pop()
|
||||
state.scopes.push({offset: top(state).offset + conf.indentUnit,
|
||||
type: "py",
|
||||
align: null})
|
||||
}
|
||||
|
||||
function pushBracketScope(stream, state, type) {
|
||||
var align = stream.match(/^([\s\[\{\(]|#.*)*$/, false) ? null : stream.column() + 1
|
||||
state.scopes.push({offset: state.indent + hangingIndent,
|
||||
type: type,
|
||||
align: align})
|
||||
}
|
||||
|
||||
function dedent(stream, state) {
|
||||
var indented = stream.indentation();
|
||||
while (top(state).offset > indented) {
|
||||
while (state.scopes.length > 1 && top(state).offset > indented) {
|
||||
if (top(state).type != "py") return true;
|
||||
state.scopes.pop();
|
||||
}
|
||||
|
@ -246,17 +241,16 @@
|
|||
}
|
||||
|
||||
function tokenLexer(stream, state) {
|
||||
if (stream.sol()) state.beginningOfLine = true;
|
||||
|
||||
var style = state.tokenize(stream, state);
|
||||
var current = stream.current();
|
||||
|
||||
// Handle decorators
|
||||
if (current == "@"){
|
||||
if(parserConf.version && parseInt(parserConf.version, 10) == 3){
|
||||
return stream.match(identifiers, false) ? "meta" : "operator";
|
||||
} else {
|
||||
return stream.match(identifiers, false) ? "meta" : ERRORCLASS;
|
||||
}
|
||||
}
|
||||
if (state.beginningOfLine && current == "@")
|
||||
return stream.match(identifiers, false) ? "meta" : py3 ? "operator" : ERRORCLASS;
|
||||
|
||||
if (/\S/.test(current)) state.beginningOfLine = false;
|
||||
|
||||
if ((style == "variable" || style == "builtin")
|
||||
&& state.lastToken == "meta")
|
||||
|
@ -268,15 +262,15 @@
|
|||
|
||||
if (current == "lambda") state.lambda = true;
|
||||
if (current == ":" && !state.lambda && top(state).type == "py")
|
||||
pushScope(stream, state, "py");
|
||||
pushPyScope(state);
|
||||
|
||||
var delimiter_index = current.length == 1 ? "[({".indexOf(current) : -1;
|
||||
if (delimiter_index != -1)
|
||||
pushScope(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
|
||||
pushBracketScope(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
|
||||
|
||||
delimiter_index = "])}".indexOf(current);
|
||||
if (delimiter_index != -1) {
|
||||
if (top(state).type == current) state.scopes.pop();
|
||||
if (top(state).type == current) state.indent = state.scopes.pop().offset - hangingIndent
|
||||
else return ERRORCLASS;
|
||||
}
|
||||
if (state.dedent > 0 && stream.eol() && top(state).type == "py") {
|
||||
|
@ -292,6 +286,7 @@
|
|||
return {
|
||||
tokenize: tokenBase,
|
||||
scopes: [{offset: basecolumn || 0, type: "py", align: null}],
|
||||
indent: basecolumn || 0,
|
||||
lastToken: null,
|
||||
lambda: false,
|
||||
dedent: 0
|
||||
|
@ -316,16 +311,14 @@
|
|||
if (state.tokenize != tokenBase)
|
||||
return state.tokenize.isString ? CodeMirror.Pass : 0;
|
||||
|
||||
var scope = top(state);
|
||||
var closing = textAfter && textAfter.charAt(0) == scope.type;
|
||||
var scope = top(state), closing = scope.type == textAfter.charAt(0)
|
||||
if (scope.align != null)
|
||||
return scope.align - (closing ? 1 : 0);
|
||||
else if (closing && state.scopes.length > 1)
|
||||
return state.scopes[state.scopes.length - 2].offset;
|
||||
return scope.align - (closing ? 1 : 0)
|
||||
else
|
||||
return scope.offset;
|
||||
return scope.offset - (closing ? hangingIndent : 0)
|
||||
},
|
||||
|
||||
electricInput: /^\s*[\}\]\)]$/,
|
||||
closeBrackets: {triples: "'\""},
|
||||
lineComment: "#",
|
||||
fold: "indent"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue