mirror of
https://github.com/neocities/neocities.git
synced 2025-05-13 16:07:19 +02:00
improve underline links, update ace, add more ace themes
This commit is contained in:
parent
37cac9d1bd
commit
7788437c33
467 changed files with 324936 additions and 321 deletions
|
@ -1,4 +1,188 @@
|
|||
define("ace/ext/whitespace",["require","exports","module","ace/lib/lang"],function(e,t,n){"use strict";var r=e("../lib/lang");t.$detectIndentation=function(e,t){function c(e){var t=0;for(var r=e;r<n.length;r+=e)t+=n[r]||0;return t}var n=[],r=[],i=0,s=0,o=Math.min(e.length,1e3);for(var u=0;u<o;u++){var a=e[u];if(!/^\s*[^*+\-\s]/.test(a))continue;if(a[0]==" ")i++,s=-Number.MAX_VALUE;else{var f=a.match(/^ */)[0].length;if(f&&a[f]!=" "){var l=f-s;l>0&&!(s%l)&&!(f%l)&&(r[l]=(r[l]||0)+1),n[f]=(n[f]||0)+1}s=f}while(u<o&&a[a.length-1]=="\\")a=e[u++]}var h=r.reduce(function(e,t){return e+t},0),p={score:0,length:0},d=0;for(var u=1;u<12;u++){var v=c(u);u==1?(d=v,v=n[1]?.9:.8,n.length||(v=0)):v/=d,r[u]&&(v+=r[u]/h),v>p.score&&(p={score:v,length:u})}if(p.score&&p.score>1.4)var m=p.length;if(i>d+1){if(m==1||d<i/4||p.score<1.8)m=undefined;return{ch:" ",length:m}}if(d>i+1)return{ch:" ",length:m}},t.detectIndentation=function(e){var n=e.getLines(0,1e3),r=t.$detectIndentation(n)||{};return r.ch&&e.setUseSoftTabs(r.ch==" "),r.length&&e.setTabSize(r.length),r},t.trimTrailingSpace=function(e,t){var n=e.getDocument(),r=n.getAllLines(),i=t&&t.trimEmpty?-1:0,s=[],o=-1;t&&t.keepCursorPosition&&(e.selection.rangeCount?e.selection.rangeList.ranges.forEach(function(e,t,n){var r=n[t+1];if(r&&r.cursor.row==e.cursor.row)return;s.push(e.cursor)}):s.push(e.selection.getCursor()),o=0);var u=s[o]&&s[o].row;for(var a=0,f=r.length;a<f;a++){var l=r[a],c=l.search(/\s+$/);a==u&&(c<s[o].column&&c>i&&(c=s[o].column),o++,u=s[o]?s[o].row:-1),c>i&&n.removeInLine(a,c,l.length)}},t.convertIndentation=function(e,t,n){var i=e.getTabString()[0],s=e.getTabSize();n||(n=s),t||(t=i);var o=t==" "?t:r.stringRepeat(t,n),u=e.doc,a=u.getAllLines(),f={},l={};for(var c=0,h=a.length;c<h;c++){var p=a[c],d=p.match(/^\s*/)[0];if(d){var v=e.$getStringScreenWidth(d)[0],m=Math.floor(v/s),g=v%s,y=f[m]||(f[m]=r.stringRepeat(o,m));y+=l[g]||(l[g]=r.stringRepeat(" ",g)),y!=d&&(u.removeInLine(c,0,d.length),u.insertInLine({row:c,column:0},y))}}e.setTabSize(n),e.setUseSoftTabs(t==" ")},t.$parseStringArg=function(e){var t={};/t/.test(e)?t.ch=" ":/s/.test(e)&&(t.ch=" ");var n=e.match(/\d+/);return n&&(t.length=parseInt(n[0],10)),t},t.$parseArg=function(e){return e?typeof e=="string"?t.$parseStringArg(e):typeof e.text=="string"?t.$parseStringArg(e.text):e:{}},t.commands=[{name:"detectIndentation",description:"Detect indentation from content",exec:function(e){t.detectIndentation(e.session)}},{name:"trimTrailingSpace",description:"Trim trailing whitespace",exec:function(e,n){t.trimTrailingSpace(e.session,n)}},{name:"convertIndentation",description:"Convert indentation to ...",exec:function(e,n){var r=t.$parseArg(n);t.convertIndentation(e.session,r.ch,r.length)}},{name:"setIndentation",description:"Set indentation",exec:function(e,n){var r=t.$parseArg(n);r.length&&e.session.setTabSize(r.length),r.ch&&e.session.setUseSoftTabs(r.ch==" ")}}]}); (function() {
|
||||
define("ace/ext/whitespace",["require","exports","module","ace/lib/lang"], function(require, exports, module){"use strict";
|
||||
var lang = require("../lib/lang");
|
||||
exports.$detectIndentation = function (lines, fallback) {
|
||||
var stats = [];
|
||||
var changes = [];
|
||||
var tabIndents = 0;
|
||||
var prevSpaces = 0;
|
||||
var max = Math.min(lines.length, 1000);
|
||||
for (var i = 0; i < max; i++) {
|
||||
var line = lines[i];
|
||||
if (!/^\s*[^*+\-\s]/.test(line))
|
||||
continue;
|
||||
if (line[0] == "\t") {
|
||||
tabIndents++;
|
||||
prevSpaces = -Number.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
var spaces = line.match(/^ */)[0].length;
|
||||
if (spaces && line[spaces] != "\t") {
|
||||
var diff = spaces - prevSpaces;
|
||||
if (diff > 0 && !(prevSpaces % diff) && !(spaces % diff))
|
||||
changes[diff] = (changes[diff] || 0) + 1;
|
||||
stats[spaces] = (stats[spaces] || 0) + 1;
|
||||
}
|
||||
prevSpaces = spaces;
|
||||
}
|
||||
while (i < max && line[line.length - 1] == "\\")
|
||||
line = lines[i++];
|
||||
}
|
||||
function getScore(indent) {
|
||||
var score = 0;
|
||||
for (var i = indent; i < stats.length; i += indent)
|
||||
score += stats[i] || 0;
|
||||
return score;
|
||||
}
|
||||
var changesTotal = changes.reduce(function (a, b) { return a + b; }, 0);
|
||||
var first = { score: 0, length: 0 };
|
||||
var spaceIndents = 0;
|
||||
for (var i = 1; i < 12; i++) {
|
||||
var score = getScore(i);
|
||||
if (i == 1) {
|
||||
spaceIndents = score;
|
||||
score = stats[1] ? 0.9 : 0.8;
|
||||
if (!stats.length)
|
||||
score = 0;
|
||||
}
|
||||
else
|
||||
score /= spaceIndents;
|
||||
if (changes[i])
|
||||
score += changes[i] / changesTotal;
|
||||
if (score > first.score)
|
||||
first = { score: score, length: i };
|
||||
}
|
||||
if (first.score && first.score > 1.4)
|
||||
var tabLength = first.length;
|
||||
if (tabIndents > spaceIndents + 1) {
|
||||
if (tabLength == 1 || spaceIndents < tabIndents / 4 || first.score < 1.8)
|
||||
tabLength = undefined;
|
||||
return { ch: "\t", length: tabLength };
|
||||
}
|
||||
if (spaceIndents > tabIndents + 1)
|
||||
return { ch: " ", length: tabLength };
|
||||
};
|
||||
exports.detectIndentation = function (session) {
|
||||
var lines = session.getLines(0, 1000);
|
||||
var indent = exports.$detectIndentation(lines) || {};
|
||||
if (indent.ch)
|
||||
session.setUseSoftTabs(indent.ch == " ");
|
||||
if (indent.length)
|
||||
session.setTabSize(indent.length);
|
||||
return indent;
|
||||
};
|
||||
exports.trimTrailingSpace = function (session, options) {
|
||||
var doc = session.getDocument();
|
||||
var lines = doc.getAllLines();
|
||||
var min = options && options.trimEmpty ? -1 : 0;
|
||||
var cursors = [], ci = -1;
|
||||
if (options && options.keepCursorPosition) {
|
||||
if (session.selection.rangeCount) {
|
||||
session.selection.rangeList.ranges.forEach(function (x, i, ranges) {
|
||||
var next = ranges[i + 1];
|
||||
if (next && next.cursor.row == x.cursor.row)
|
||||
return;
|
||||
cursors.push(x.cursor);
|
||||
});
|
||||
}
|
||||
else {
|
||||
cursors.push(session.selection.getCursor());
|
||||
}
|
||||
ci = 0;
|
||||
}
|
||||
var cursorRow = cursors[ci] && cursors[ci].row;
|
||||
for (var i = 0, l = lines.length; i < l; i++) {
|
||||
var line = lines[i];
|
||||
var index = line.search(/\s+$/);
|
||||
if (i == cursorRow) {
|
||||
if (index < cursors[ci].column && index > min)
|
||||
index = cursors[ci].column;
|
||||
ci++;
|
||||
cursorRow = cursors[ci] ? cursors[ci].row : -1;
|
||||
}
|
||||
if (index > min)
|
||||
doc.removeInLine(i, index, line.length);
|
||||
}
|
||||
};
|
||||
exports.convertIndentation = function (session, ch, len) {
|
||||
var oldCh = session.getTabString()[0];
|
||||
var oldLen = session.getTabSize();
|
||||
if (!len)
|
||||
len = oldLen;
|
||||
if (!ch)
|
||||
ch = oldCh;
|
||||
var tab = ch == "\t" ? ch : lang.stringRepeat(ch, len);
|
||||
var doc = session.doc;
|
||||
var lines = doc.getAllLines();
|
||||
var cache = {};
|
||||
var spaceCache = {};
|
||||
for (var i = 0, l = lines.length; i < l; i++) {
|
||||
var line = lines[i];
|
||||
var match = line.match(/^\s*/)[0];
|
||||
if (match) {
|
||||
var w = session.$getStringScreenWidth(match)[0];
|
||||
var tabCount = Math.floor(w / oldLen);
|
||||
var reminder = w % oldLen;
|
||||
var toInsert = cache[tabCount] || (cache[tabCount] = lang.stringRepeat(tab, tabCount));
|
||||
toInsert += spaceCache[reminder] || (spaceCache[reminder] = lang.stringRepeat(" ", reminder));
|
||||
if (toInsert != match) {
|
||||
doc.removeInLine(i, 0, match.length);
|
||||
doc.insertInLine({ row: i, column: 0 }, toInsert);
|
||||
}
|
||||
}
|
||||
}
|
||||
session.setTabSize(len);
|
||||
session.setUseSoftTabs(ch == " ");
|
||||
};
|
||||
exports.$parseStringArg = function (text) {
|
||||
var indent = {};
|
||||
if (/t/.test(text))
|
||||
indent.ch = "\t";
|
||||
else if (/s/.test(text))
|
||||
indent.ch = " ";
|
||||
var m = text.match(/\d+/);
|
||||
if (m)
|
||||
indent.length = parseInt(m[0], 10);
|
||||
return indent;
|
||||
};
|
||||
exports.$parseArg = function (arg) {
|
||||
if (!arg)
|
||||
return {};
|
||||
if (typeof arg == "string")
|
||||
return exports.$parseStringArg(arg);
|
||||
if (typeof arg.text == "string")
|
||||
return exports.$parseStringArg(arg.text);
|
||||
return arg;
|
||||
};
|
||||
exports.commands = [{
|
||||
name: "detectIndentation",
|
||||
description: "Detect indentation from content",
|
||||
exec: function (editor) {
|
||||
exports.detectIndentation(editor.session);
|
||||
}
|
||||
}, {
|
||||
name: "trimTrailingSpace",
|
||||
description: "Trim trailing whitespace",
|
||||
exec: function (editor, args) {
|
||||
exports.trimTrailingSpace(editor.session, args);
|
||||
}
|
||||
}, {
|
||||
name: "convertIndentation",
|
||||
description: "Convert indentation to ...",
|
||||
exec: function (editor, arg) {
|
||||
var indent = exports.$parseArg(arg);
|
||||
exports.convertIndentation(editor.session, indent.ch, indent.length);
|
||||
}
|
||||
}, {
|
||||
name: "setIndentation",
|
||||
description: "Set indentation",
|
||||
exec: function (editor, arg) {
|
||||
var indent = exports.$parseArg(arg);
|
||||
indent.length && editor.session.setTabSize(indent.length);
|
||||
indent.ch && editor.session.setUseSoftTabs(indent.ch == " ");
|
||||
}
|
||||
}];
|
||||
|
||||
}); (function() {
|
||||
window.require(["ace/ext/whitespace"], function(m) {
|
||||
if (typeof module == "object" && typeof exports == "object" && module) {
|
||||
module.exports = m;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue