1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-30 18:49:43 +02:00

upgraded libs and improved Markdown editing experience

This commit is contained in:
Harvey Kandola 2017-03-13 15:40:28 +00:00
parent 2e146cf767
commit ea1a8000ee
165 changed files with 15930 additions and 19013 deletions

View file

@ -11,64 +11,87 @@
})(function(CodeMirror) {
"use strict";
CodeMirror.defineMode("julia", function(_conf, parserConf) {
var ERRORCLASS = 'error';
function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
CodeMirror.defineMode("julia", function(config, parserConf) {
function wordRegexp(words, end) {
if (typeof end === "undefined") { end = "\\b"; }
return new RegExp("^((" + words.join(")|(") + "))" + end);
}
var operators = parserConf.operators || /^\.?[|&^\\%*+\-<>!=\/]=?|\?|~|:|\$|\.[<>]|<<=?|>>>?=?|\.[<>=]=|->?|\/\/|\bin\b/;
var octChar = "\\\\[0-7]{1,3}";
var hexChar = "\\\\x[A-Fa-f0-9]{1,2}";
var sChar = "\\\\[abefnrtv0%?'\"\\\\]";
var uChar = "([^\\u0027\\u005C\\uD800-\\uDFFF]|[\\uD800-\\uDFFF][\\uDC00-\\uDFFF])";
var operators = parserConf.operators || wordRegexp([
"\\.?[\\\\%*+\\-<>!=\\/^]=?", "\\.?[|&\\u00F7\\u2260\\u2264\\u2265]",
"\\u00D7", "\\u2208", "\\u2209", "\\u220B", "\\u220C", "\\u2229",
"\\u222A", "\\u2286", "\\u2288", "\\u228A", "\\u22c5", "\\?", "~", ":",
"\\$", "\\.[<>]", "<<=?", ">>>?=?", "\\.[<>=]=", "->?", "\\/\\/", "=>",
"<:", "\\bin\\b(?!\\()"], "");
var delimiters = parserConf.delimiters || /^[;,()[\]{}]/;
var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*!*/;
var blockOpeners = ["begin", "function", "type", "immutable", "let", "macro", "for", "while", "quote", "if", "else", "elseif", "try", "finally", "catch", "do"];
var blockClosers = ["end", "else", "elseif", "catch", "finally"];
var keywordList = ['if', 'else', 'elseif', 'while', 'for', 'begin', 'let', 'end', 'do', 'try', 'catch', 'finally', 'return', 'break', 'continue', 'global', 'local', 'const', 'export', 'import', 'importall', 'using', 'function', 'macro', 'module', 'baremodule', 'type', 'immutable', 'quote', 'typealias', 'abstract', 'bitstype', 'ccall'];
var builtinList = ['true', 'false', 'enumerate', 'open', 'close', 'nothing', 'NaN', 'Inf', 'print', 'println', 'Int', 'Int8', 'Uint8', 'Int16', 'Uint16', 'Int32', 'Uint32', 'Int64', 'Uint64', 'Int128', 'Uint128', 'Bool', 'Char', 'Float16', 'Float32', 'Float64', 'Array', 'Vector', 'Matrix', 'String', 'UTF8String', 'ASCIIString', 'error', 'warn', 'info', '@printf'];
var identifiers = parserConf.identifiers || /^[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/;
//var stringPrefixes = new RegExp("^[br]?('|\")")
var stringPrefixes = /^(`|'|"{3}|([br]?"))/;
var keywords = wordRegexp(keywordList);
var builtins = wordRegexp(builtinList);
var openers = wordRegexp(blockOpeners);
var closers = wordRegexp(blockClosers);
var macro = /^@[_A-Za-z][_A-Za-z0-9]*/;
var symbol = /^:[_A-Za-z][_A-Za-z0-9]*/;
var chars = wordRegexp([octChar, hexChar, sChar, uChar], "'");
var openers = wordRegexp(["begin", "function", "type", "immutable", "let",
"macro", "for", "while", "quote", "if", "else", "elseif", "try",
"finally", "catch", "do"]);
var closers = wordRegexp(["end", "else", "elseif", "catch", "finally"]);
var keywords = wordRegexp(["if", "else", "elseif", "while", "for", "begin",
"let", "end", "do", "try", "catch", "finally", "return", "break",
"continue", "global", "local", "const", "export", "import", "importall",
"using", "function", "macro", "module", "baremodule", "type",
"immutable", "quote", "typealias", "abstract", "bitstype"]);
var builtins = wordRegexp(["true", "false", "nothing", "NaN", "Inf"]);
function in_array(state) {
var ch = cur_scope(state);
if(ch=="[" || ch=="{") {
var macro = /^@[_A-Za-z][\w]*/;
var symbol = /^:[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/;
var stringPrefixes = /^(`|"{3}|([_A-Za-z\u00A1-\uFFFF]*"))/;
function inArray(state) {
return inGenerator(state, '[')
}
function inGenerator(state, bracket) {
var curr = currentScope(state),
prev = currentScope(state, 1);
if (typeof(bracket) === "undefined") { bracket = '('; }
if (curr === bracket || (prev === bracket && curr === "for")) {
return true;
}
else {
return false;
}
return false;
}
function cur_scope(state) {
if(state.scopes.length==0) {
function currentScope(state, n) {
if (typeof(n) === "undefined") { n = 0; }
if (state.scopes.length <= n) {
return null;
}
return state.scopes[state.scopes.length - 1];
return state.scopes[state.scopes.length - (n + 1)];
}
// tokenizers
function tokenBase(stream, state) {
// Handle multiline comments
if (stream.match(/^#=/, false)) {
state.tokenize = tokenComment;
return state.tokenize(stream, state);
}
// Handle scope changes
var leaving_expr = state.leaving_expr;
if(stream.sol()) {
leaving_expr = false;
var leavingExpr = state.leavingExpr;
if (stream.sol()) {
leavingExpr = false;
}
state.leaving_expr = false;
if(leaving_expr) {
if(stream.match(/^'+/)) {
return 'operator';
state.leavingExpr = false;
if (leavingExpr) {
if (stream.match(/^'+/)) {
return "operator";
}
}
if(stream.match(/^\.{2,3}/)) {
return 'operator';
if (stream.match(/^\.{2,3}/)) {
return "operator";
}
if (stream.eatSpace()) {
@ -76,106 +99,103 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
}
var ch = stream.peek();
// Handle Comments
// Handle single line comments
if (ch === '#') {
stream.skipToEnd();
return 'comment';
}
if(ch==='[') {
state.scopes.push("[");
stream.skipToEnd();
return "comment";
}
if(ch==='{') {
state.scopes.push("{");
if (ch === '[') {
state.scopes.push('[');
}
var scope=cur_scope(state);
if (ch === '(') {
state.scopes.push('(');
}
if(scope==='[' && ch===']') {
var scope = currentScope(state);
if (inArray(state) && ch === ']') {
if (scope === "for") { state.scopes.pop(); }
state.scopes.pop();
state.leaving_expr=true;
state.leavingExpr = true;
}
if(scope==='{' && ch==='}') {
if (inGenerator(state) && ch === ')') {
if (scope === "for") { state.scopes.pop(); }
state.scopes.pop();
state.leaving_expr=true;
}
if(ch===')') {
state.leaving_expr = true;
state.leavingExpr = true;
}
var match;
if(!in_array(state) && (match=stream.match(openers, false))) {
state.scopes.push(match);
if (match = stream.match(openers, false)) {
state.scopes.push(match[0]);
}
if(!in_array(state) && stream.match(closers, false)) {
if (stream.match(closers, false)) {
state.scopes.pop();
}
if(in_array(state)) {
if(stream.match(/^end/)) {
return 'number';
if (inArray(state)) {
if (state.lastToken == "end" && stream.match(/^:/)) {
return "operator";
}
}
if(stream.match(/^=>/)) {
return 'operator';
}
// Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) {
var imMatcher = RegExp(/^im\b/);
var floatLiteral = false;
// Floats
if (stream.match(/^\d*\.(?!\.)\d+([ef][\+\-]?\d+)?/i)) { floatLiteral = true; }
if (stream.match(/^\d+\.(?!\.)\d*/)) { floatLiteral = true; }
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
if (floatLiteral) {
// Float literals may be "imaginary"
stream.match(imMatcher);
state.leaving_expr = true;
return 'number';
}
// Integers
var intLiteral = false;
// Hex
if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
// Binary
if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
// Octal
if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
// Decimal
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
intLiteral = true;
}
// Zero by itself with no other piece of number.
if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
if (intLiteral) {
// Integer literals may be "long"
stream.match(imMatcher);
state.leaving_expr = true;
return 'number';
if (stream.match(/^end/)) {
return "number";
}
}
if(stream.match(/^(::)|(<:)/)) {
return 'operator';
// Handle type annotations
if (stream.match(/^::(?![:\$])/)) {
state.tokenize = tokenAnnotation;
return state.tokenize(stream, state);
}
// Handle symbols
if(!leaving_expr && stream.match(symbol)) {
return 'string';
if (!leavingExpr && stream.match(symbol) || stream.match(/:\./)) {
return "builtin";
}
// Handle parametric types
if (stream.match(/^{[^}]*}(?=\()/)) {
return "builtin";
}
// Handle operators and Delimiters
if (stream.match(operators)) {
return 'operator';
return "operator";
}
// Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) {
var imMatcher = RegExp(/^im\b/);
var numberLiteral = false;
// Floats
if (stream.match(/^\d*\.(?!\.)\d*([Eef][\+\-]?\d+)?/i)) { numberLiteral = true; }
if (stream.match(/^\d+\.(?!\.)\d*/)) { numberLiteral = true; }
if (stream.match(/^\.\d+/)) { numberLiteral = true; }
if (stream.match(/^0x\.[0-9a-f]+p[\+\-]?\d+/i)) { numberLiteral = true; }
// Integers
if (stream.match(/^0x[0-9a-f]+/i)) { numberLiteral = true; } // Hex
if (stream.match(/^0b[01]+/i)) { numberLiteral = true; } // Binary
if (stream.match(/^0o[0-7]+/i)) { numberLiteral = true; } // Octal
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) { numberLiteral = true; } // Decimal
// Zero by itself with no other piece of number.
if (stream.match(/^0(?![\dx])/i)) { numberLiteral = true; }
if (numberLiteral) {
// Integer literals may be "long"
stream.match(imMatcher);
state.leavingExpr = true;
return "number";
}
}
// Handle Chars
if (stream.match(/^'/)) {
state.tokenize = tokenChar;
return state.tokenize(stream, state);
}
// Handle Strings
if (stream.match(stringPrefixes)) {
@ -184,111 +204,202 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
}
if (stream.match(macro)) {
return 'meta';
return "meta";
}
if (stream.match(delimiters)) {
return null;
}
if (stream.match(keywords)) {
return 'keyword';
return "keyword";
}
if (stream.match(builtins)) {
return 'builtin';
return "builtin";
}
var isDefinition = state.isDefinition || state.lastToken == "function" ||
state.lastToken == "macro" || state.lastToken == "type" ||
state.lastToken == "immutable";
if (stream.match(identifiers)) {
state.leaving_expr=true;
return 'variable';
if (isDefinition) {
if (stream.peek() === '.') {
state.isDefinition = true;
return "variable";
}
state.isDefinition = false;
return "def";
}
if (stream.match(/^({[^}]*})*\(/, false)) {
return callOrDef(stream, state);
}
state.leavingExpr = true;
return "variable";
}
// Handle non-detected items
stream.next();
return ERRORCLASS;
return "error";
}
function callOrDef(stream, state) {
var match = stream.match(/^(\(\s*)/);
if (match) {
if (state.firstParenPos < 0)
state.firstParenPos = state.scopes.length;
state.scopes.push('(');
state.charsAdvanced += match[1].length;
}
if (currentScope(state) == '(' && stream.match(/^\)/)) {
state.scopes.pop();
state.charsAdvanced += 1;
if (state.scopes.length <= state.firstParenPos) {
var isDefinition = stream.match(/^\s*?=(?!=)/, false);
stream.backUp(state.charsAdvanced);
state.firstParenPos = -1;
state.charsAdvanced = 0;
if (isDefinition)
return "def";
return "builtin";
}
}
// Unfortunately javascript does not support multiline strings, so we have
// to undo anything done upto here if a function call or definition splits
// over two or more lines.
if (stream.match(/^$/g, false)) {
stream.backUp(state.charsAdvanced);
while (state.scopes.length > state.firstParenPos)
state.scopes.pop();
state.firstParenPos = -1;
state.charsAdvanced = 0;
return "builtin";
}
state.charsAdvanced += stream.match(/^([^()]*)/)[1].length;
return callOrDef(stream, state);
}
function tokenAnnotation(stream, state) {
stream.match(/.*?(?=,|;|{|}|\(|\)|=|$|\s)/);
if (stream.match(/^{/)) {
state.nestedLevels++;
} else if (stream.match(/^}/)) {
state.nestedLevels--;
}
if (state.nestedLevels > 0) {
stream.match(/.*?(?={|})/);
} else if (state.nestedLevels == 0) {
state.tokenize = tokenBase;
}
return "builtin";
}
function tokenComment(stream, state) {
if (stream.match(/^#=/)) {
state.nestedLevels++;
}
if (!stream.match(/.*?(?=(#=|=#))/)) {
stream.skipToEnd();
}
if (stream.match(/^=#/)) {
state.nestedLevels--;
if (state.nestedLevels == 0)
state.tokenize = tokenBase;
}
return "comment";
}
function tokenChar(stream, state) {
var isChar = false, match;
if (stream.match(chars)) {
isChar = true;
} else if (match = stream.match(/\\u([a-f0-9]{1,4})(?=')/i)) {
var value = parseInt(match[1], 16);
if (value <= 55295 || value >= 57344) { // (U+0,U+D7FF), (U+E000,U+FFFF)
isChar = true;
stream.next();
}
} else if (match = stream.match(/\\U([A-Fa-f0-9]{5,8})(?=')/)) {
var value = parseInt(match[1], 16);
if (value <= 1114111) { // U+10FFFF
isChar = true;
stream.next();
}
}
if (isChar) {
state.leavingExpr = true;
state.tokenize = tokenBase;
return "string";
}
if (!stream.match(/^[^']+(?=')/)) { stream.skipToEnd(); }
if (stream.match(/^'/)) { state.tokenize = tokenBase; }
return "error";
}
function tokenStringFactory(delimiter) {
while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
delimiter = delimiter.substr(1);
}
var singleline = delimiter.length == 1;
var OUTCLASS = 'string';
delimiter = (delimiter === '`' || delimiter === '"""') ? delimiter : '"';
function tokenString(stream, state) {
while (!stream.eol()) {
stream.eatWhile(/[^'"\\]/);
if (stream.eat('\\')) {
stream.next();
if (singleline && stream.eol()) {
return OUTCLASS;
}
} else if (stream.match(delimiter)) {
state.tokenize = tokenBase;
return OUTCLASS;
} else {
stream.eat(/['"]/);
}
if (stream.eat('\\')) {
stream.next();
} else if (stream.match(delimiter)) {
state.tokenize = tokenBase;
state.leavingExpr = true;
return "string";
} else {
stream.eat(/[`"]/);
}
if (singleline) {
if (parserConf.singleLineStringErrors) {
return ERRORCLASS;
} else {
state.tokenize = tokenBase;
}
}
return OUTCLASS;
stream.eatWhile(/[^\\`"]/);
return "string";
}
tokenString.isString = true;
return tokenString;
}
function tokenLexer(stream, state) {
var style = state.tokenize(stream, state);
var current = stream.current();
// Handle '.' connected identifiers
if (current === '.') {
style = stream.match(identifiers, false) ? null : ERRORCLASS;
if (style === null && state.lastStyle === 'meta') {
// Apply 'meta' style to '.' connected identifiers when
// appropriate.
style = 'meta';
}
return style;
}
return style;
}
var external = {
startState: function() {
return {
tokenize: tokenBase,
scopes: [],
leaving_expr: false
lastToken: null,
leavingExpr: false,
isDefinition: false,
nestedLevels: 0,
charsAdvanced: 0,
firstParenPos: -1
};
},
token: function(stream, state) {
var style = tokenLexer(stream, state);
state.lastStyle = style;
var style = state.tokenize(stream, state);
var current = stream.current();
if (current && style) {
state.lastToken = current;
}
// Handle '.' connected identifiers
if (current === '.') {
style = stream.match(identifiers, false) || stream.match(macro, false) ||
stream.match(/\(/, false) ? "operator" : "error";
}
return style;
},
indent: function(state, textAfter) {
var delta = 0;
if(textAfter=="end" || textAfter=="]" || textAfter=="}" || textAfter=="else" || textAfter=="elseif" || textAfter=="catch" || textAfter=="finally") {
if ( textAfter === ']' || textAfter === ')' || textAfter === "end" ||
textAfter === "else" || textAfter === "catch" || textAfter === "elseif" ||
textAfter === "finally" ) {
delta = -1;
}
return (state.scopes.length + delta) * _conf.indentUnit;
return (state.scopes.length + delta) * config.indentUnit;
},
electricInput: /\b(end|else|catch|finally)\b/,
blockCommentStart: "#=",
blockCommentEnd: "=#",
lineComment: "#",
fold: "indent",
electricChars: "edlsifyh]}"
fold: "indent"
};
return external;
});