mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-04 08:17:24 -05: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
110 lines
3.7 KiB
JavaScript
110 lines
3.7 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("rpm-changes", function() {
|
|
var headerSeperator = /^-+$/;
|
|
var headerLine = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ?\d{1,2} \d{2}:\d{2}(:\d{2})? [A-Z]{3,4} \d{4} - /;
|
|
var simpleEmail = /^[\w+.-]+@[\w.-]+/;
|
|
|
|
return {
|
|
token: function(stream) {
|
|
if (stream.sol()) {
|
|
if (stream.match(headerSeperator)) { return 'tag'; }
|
|
if (stream.match(headerLine)) { return 'tag'; }
|
|
}
|
|
if (stream.match(simpleEmail)) { return 'string'; }
|
|
stream.next();
|
|
return null;
|
|
}
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-rpm-changes", "rpm-changes");
|
|
|
|
// Quick and dirty spec file highlighting
|
|
|
|
CodeMirror.defineMode("rpm-spec", function() {
|
|
var arch = /^(i386|i586|i686|x86_64|ppc64le|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;
|
|
|
|
var preamble = /^[a-zA-Z0-9()]+:/;
|
|
var section = /^%(debug_package|package|description|prep|build|install|files|clean|changelog|preinstall|preun|postinstall|postun|pretrans|posttrans|pre|post|triggerin|triggerun|verifyscript|check|triggerpostun|triggerprein|trigger)/;
|
|
var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros
|
|
var control_flow_simple = /^%(else|endif)/; // rpm control flow macros
|
|
var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros
|
|
|
|
return {
|
|
startState: function () {
|
|
return {
|
|
controlFlow: false,
|
|
macroParameters: false,
|
|
section: false
|
|
};
|
|
},
|
|
token: function (stream, state) {
|
|
var ch = stream.peek();
|
|
if (ch == "#") { stream.skipToEnd(); return "comment"; }
|
|
|
|
if (stream.sol()) {
|
|
if (stream.match(preamble)) { return "header"; }
|
|
if (stream.match(section)) { return "atom"; }
|
|
}
|
|
|
|
if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'
|
|
if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'
|
|
|
|
if (stream.match(control_flow_simple)) { return "keyword"; }
|
|
if (stream.match(control_flow_complex)) {
|
|
state.controlFlow = true;
|
|
return "keyword";
|
|
}
|
|
if (state.controlFlow) {
|
|
if (stream.match(operators)) { return "operator"; }
|
|
if (stream.match(/^(\d+)/)) { return "number"; }
|
|
if (stream.eol()) { state.controlFlow = false; }
|
|
}
|
|
|
|
if (stream.match(arch)) {
|
|
if (stream.eol()) { state.controlFlow = false; }
|
|
return "number";
|
|
}
|
|
|
|
// Macros like '%make_install' or '%attr(0775,root,root)'
|
|
if (stream.match(/^%[\w]+/)) {
|
|
if (stream.match(/^\(/)) { state.macroParameters = true; }
|
|
return "keyword";
|
|
}
|
|
if (state.macroParameters) {
|
|
if (stream.match(/^\d+/)) { return "number";}
|
|
if (stream.match(/^\)/)) {
|
|
state.macroParameters = false;
|
|
return "keyword";
|
|
}
|
|
}
|
|
|
|
// Macros like '%{defined fedora}'
|
|
if (stream.match(/^%\{\??[\w \-\:\!]+\}/)) {
|
|
if (stream.eol()) { state.controlFlow = false; }
|
|
return "def";
|
|
}
|
|
|
|
//TODO: Include bash script sub-parser (CodeMirror supports that)
|
|
stream.next();
|
|
return null;
|
|
}
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("text/x-rpm-spec", "rpm-spec");
|
|
|
|
});
|