mirror of
https://github.com/go-gitea/gitea
synced 2024-11-15 14:44:41 +00:00
a915a09e4f
* Cleaning up public/ and documenting js/css libs. This commit mostly addresses #1484 by moving vendor'ed plugins into a vendor/ directory and documenting their upstream source and license in vendor/librejs.html. This also proves gitea is using only open source js/css libraries which helps toward reaching #1524. * Removing unused css file. The version of this file in use is located at: vendor/plugins/highlight/github.css * Cleaned up librejs.html and added javascript header A SafeJS function was added to templates/helper.go to allow keeping comments inside of javascript. A javascript comment was added in the header of templates/base/head.tmpl to mark all non-inline source as free. The librejs.html file was updated to meet the current librejs spec. I have now verified that the librejs plugin detects most of the scripts included in gitea and suspect the non-free detections are the result of a bug in the plugin. I believe this commit is enough to meet the C0.0 requirement of #1534. * Updating SafeJS function per lint suggestion * Added VERSIONS file, per request
124 lines
4.4 KiB
JavaScript
124 lines
4.4 KiB
JavaScript
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineMode("commonlisp", function (config) {
|
|
var specialForm = /^(block|let*|return-from|catch|load-time-value|setq|eval-when|locally|symbol-macrolet|flet|macrolet|tagbody|function|multiple-value-call|the|go|multiple-value-prog1|throw|if|progn|unwind-protect|labels|progv|let|quote)$/;
|
|
var assumeBody = /^with|^def|^do|^prog|case$|^cond$|bind$|when$|unless$/;
|
|
var numLiteral = /^(?:[+\-]?(?:\d+|\d*\.\d+)(?:[efd][+\-]?\d+)?|[+\-]?\d+(?:\/[+\-]?\d+)?|#b[+\-]?[01]+|#o[+\-]?[0-7]+|#x[+\-]?[\da-f]+)/;
|
|
var symbol = /[^\s'`,@()\[\]";]/;
|
|
var type;
|
|
|
|
function readSym(stream) {
|
|
var ch;
|
|
while (ch = stream.next()) {
|
|
if (ch == "\\") stream.next();
|
|
else if (!symbol.test(ch)) { stream.backUp(1); break; }
|
|
}
|
|
return stream.current();
|
|
}
|
|
|
|
function base(stream, state) {
|
|
if (stream.eatSpace()) {type = "ws"; return null;}
|
|
if (stream.match(numLiteral)) return "number";
|
|
var ch = stream.next();
|
|
if (ch == "\\") ch = stream.next();
|
|
|
|
if (ch == '"') return (state.tokenize = inString)(stream, state);
|
|
else if (ch == "(") { type = "open"; return "bracket"; }
|
|
else if (ch == ")" || ch == "]") { type = "close"; return "bracket"; }
|
|
else if (ch == ";") { stream.skipToEnd(); type = "ws"; return "comment"; }
|
|
else if (/['`,@]/.test(ch)) return null;
|
|
else if (ch == "|") {
|
|
if (stream.skipTo("|")) { stream.next(); return "symbol"; }
|
|
else { stream.skipToEnd(); return "error"; }
|
|
} else if (ch == "#") {
|
|
var ch = stream.next();
|
|
if (ch == "[") { type = "open"; return "bracket"; }
|
|
else if (/[+\-=\.']/.test(ch)) return null;
|
|
else if (/\d/.test(ch) && stream.match(/^\d*#/)) return null;
|
|
else if (ch == "|") return (state.tokenize = inComment)(stream, state);
|
|
else if (ch == ":") { readSym(stream); return "meta"; }
|
|
else return "error";
|
|
} else {
|
|
var name = readSym(stream);
|
|
if (name == ".") return null;
|
|
type = "symbol";
|
|
if (name == "nil" || name == "t" || name.charAt(0) == ":") return "atom";
|
|
if (state.lastType == "open" && (specialForm.test(name) || assumeBody.test(name))) return "keyword";
|
|
if (name.charAt(0) == "&") return "variable-2";
|
|
return "variable";
|
|
}
|
|
}
|
|
|
|
function inString(stream, state) {
|
|
var escaped = false, next;
|
|
while (next = stream.next()) {
|
|
if (next == '"' && !escaped) { state.tokenize = base; break; }
|
|
escaped = !escaped && next == "\\";
|
|
}
|
|
return "string";
|
|
}
|
|
|
|
function inComment(stream, state) {
|
|
var next, last;
|
|
while (next = stream.next()) {
|
|
if (next == "#" && last == "|") { state.tokenize = base; break; }
|
|
last = next;
|
|
}
|
|
type = "ws";
|
|
return "comment";
|
|
}
|
|
|
|
return {
|
|
startState: function () {
|
|
return {ctx: {prev: null, start: 0, indentTo: 0}, lastType: null, tokenize: base};
|
|
},
|
|
|
|
token: function (stream, state) {
|
|
if (stream.sol() && typeof state.ctx.indentTo != "number")
|
|
state.ctx.indentTo = state.ctx.start + 1;
|
|
|
|
type = null;
|
|
var style = state.tokenize(stream, state);
|
|
if (type != "ws") {
|
|
if (state.ctx.indentTo == null) {
|
|
if (type == "symbol" && assumeBody.test(stream.current()))
|
|
state.ctx.indentTo = state.ctx.start + config.indentUnit;
|
|
else
|
|
state.ctx.indentTo = "next";
|
|
} else if (state.ctx.indentTo == "next") {
|
|
state.ctx.indentTo = stream.column();
|
|
}
|
|
state.lastType = type;
|
|
}
|
|
if (type == "open") state.ctx = {prev: state.ctx, start: stream.column(), indentTo: null};
|
|
else if (type == "close") state.ctx = state.ctx.prev || state.ctx;
|
|
return style;
|
|
},
|
|
|
|
indent: function (state, _textAfter) {
|
|
var i = state.ctx.indentTo;
|
|
return typeof i == "number" ? i : state.ctx.start + 1;
|
|
},
|
|
|
|
closeBrackets: {pairs: "()[]{}\"\""},
|
|
lineComment: ";;",
|
|
blockCommentStart: "#|",
|
|
blockCommentEnd: "|#"
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-common-lisp", "commonlisp");
|
|
|
|
});
|