mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-28 08:23:32 +01:00
Add cheap CSS highlighting which is unfortunately far to slow to make any use of.
This commit is contained in:
@@ -341,7 +341,7 @@ var Styles = Module("Styles", {
|
|||||||
(?:
|
(?:
|
||||||
<space>* : \s* (?P<value>
|
<space>* : \s* (?P<value>
|
||||||
(?:
|
(?:
|
||||||
[-\w]
|
[-\w]+
|
||||||
(?:
|
(?:
|
||||||
\s* \( \s*
|
\s* \( \s*
|
||||||
(?: <string> | [^)]* )
|
(?: <string> | [^)]* )
|
||||||
@@ -360,7 +360,60 @@ var Styles = Module("Styles", {
|
|||||||
{
|
{
|
||||||
space: /(?: \s | \/\* .*? \*\/ )/,
|
space: /(?: \s | \/\* .*? \*\/ )/,
|
||||||
string: /(?:" (?:[^\\"]|\\.)* (?:"|$) | '(?:[^\\']|\\.)* (?:'|$) )/
|
string: /(?:" (?:[^\\"]|\\.)* (?:"|$) | '(?:[^\\']|\\.)* (?:'|$) )/
|
||||||
})
|
}),
|
||||||
|
|
||||||
|
patterns: memoize({
|
||||||
|
iter: function (pattern, str) {
|
||||||
|
pattern = this[pattern];
|
||||||
|
pattern.lastIndex = 0;
|
||||||
|
|
||||||
|
let match;
|
||||||
|
while ((match = pattern.exec(str)) && match[0].length)
|
||||||
|
yield match;
|
||||||
|
},
|
||||||
|
|
||||||
|
get property() util.regexp(<![CDATA[
|
||||||
|
(?:
|
||||||
|
(?P<preSpace> <space>*)
|
||||||
|
(?P<name> [-a-z]*)
|
||||||
|
(?:
|
||||||
|
<space>* : \s* (?P<value>
|
||||||
|
<token>*
|
||||||
|
)
|
||||||
|
)?
|
||||||
|
)
|
||||||
|
(?P<postSpace> <space>* (?: ; | $) )
|
||||||
|
]]>, "gi", this),
|
||||||
|
|
||||||
|
get function() util.regexp(<![CDATA[
|
||||||
|
(?P<function>
|
||||||
|
\s* \( \s*
|
||||||
|
(?: <string> | [^)]* )
|
||||||
|
\s* (?: \) | $)
|
||||||
|
)
|
||||||
|
]]>, "g", this),
|
||||||
|
|
||||||
|
space: /(?: \s | \/\* .*? \*\/ )/,
|
||||||
|
|
||||||
|
get string() util.regexp(<![CDATA[
|
||||||
|
(?P<string>
|
||||||
|
" (?:[^\\"]|\\.)* (?:"|$) |
|
||||||
|
' (?:[^\\']|\\.)* (?:'|$)
|
||||||
|
)
|
||||||
|
]]>, "g", this),
|
||||||
|
|
||||||
|
get token() util.regexp(<![CDATA[
|
||||||
|
(?P<token>
|
||||||
|
(?P<word> [-\w]+)
|
||||||
|
<function>?
|
||||||
|
\s*
|
||||||
|
| (?P<important> !important\b)
|
||||||
|
| \s* <string> \s*
|
||||||
|
| <space>+
|
||||||
|
| [^;}\s]+
|
||||||
|
)
|
||||||
|
]]>, "gi", this)
|
||||||
|
})
|
||||||
}, {
|
}, {
|
||||||
commands: function (dactyl, modules, window) {
|
commands: function (dactyl, modules, window) {
|
||||||
const commands = modules.commands;
|
const commands = modules.commands;
|
||||||
@@ -545,7 +598,34 @@ var Styles = Module("Styles", {
|
|||||||
null,
|
null,
|
||||||
function (context, obj, args) this.sheets
|
function (context, obj, args) this.sheets
|
||||||
]);
|
]);
|
||||||
}
|
},
|
||||||
|
template: function () {
|
||||||
|
let patterns = Styles.patterns;
|
||||||
|
|
||||||
|
template.highlightCSS = function highlightCSS(css) {
|
||||||
|
XML.prettyPrinting = XML.ignoreWhitespace = false;
|
||||||
|
|
||||||
|
return this.highlightRegexp(css, patterns.property, function (match) <>{
|
||||||
|
match.preSpace}{template.filter(match.name)}: {
|
||||||
|
|
||||||
|
template.highlightRegexp(match.value, patterns.token, function (match) {
|
||||||
|
if (match.function)
|
||||||
|
return <>{template.filter(match.word)}{
|
||||||
|
template.highlightRegexp(match.function, patterns.string,
|
||||||
|
function (match) <span highlight="String">{match.string}</span>)
|
||||||
|
}</>;
|
||||||
|
if (match.important == "!important")
|
||||||
|
return <span highlight="String">{match.important}</span>;
|
||||||
|
if (match.string)
|
||||||
|
return <span highlight="String">{match.string}</span>;
|
||||||
|
return template.highlightRegexp(match.wholeMatch, /^(\d+)(em|ex|px|in|cm|mm|pt|pc)?/g,
|
||||||
|
function (m, n, u) <><span highlight="Number">{n}</span><span highlight="Object">{u || ""}</span></>);
|
||||||
|
})
|
||||||
|
|
||||||
|
}{ match.postSpace }</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
endModule();
|
endModule();
|
||||||
|
|||||||
@@ -161,14 +161,15 @@ var Template = Module("Template", {
|
|||||||
|
|
||||||
highlightRegexp: function highlightRegexp(str, re, highlight) {
|
highlightRegexp: function highlightRegexp(str, re, highlight) {
|
||||||
return this.highlightSubstrings(str, (function () {
|
return this.highlightSubstrings(str, (function () {
|
||||||
|
re.lastIndex = 0;
|
||||||
let res;
|
let res;
|
||||||
while ((res = re.exec(str)) && res[0].length)
|
while ((res = re.exec(str)) && res[0].length)
|
||||||
yield [res.index, res[0].length, res];
|
yield [res.index, res[0].length, res.wholeMatch ? [res] : res];
|
||||||
})(), highlight || template.filter);
|
})(), highlight || template.filter);
|
||||||
},
|
},
|
||||||
|
|
||||||
highlightSubstrings: function highlightSubstrings(str, iter, highlight) {
|
highlightSubstrings: function highlightSubstrings(str, iter, highlight) {
|
||||||
XML.ignoreWhitespace = false; XML.prettyPrinting = false;
|
XML.ignoreWhitespace = XML.prettyPrinting = false;
|
||||||
if (typeof str == "xml")
|
if (typeof str == "xml")
|
||||||
return str;
|
return str;
|
||||||
if (str == "")
|
if (str == "")
|
||||||
|
|||||||
@@ -1220,12 +1220,13 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
expr = expr.source;
|
expr = expr.source;
|
||||||
|
|
||||||
if (tokens)
|
if (tokens)
|
||||||
expr = String.replace(expr, /<(\w+)>/g, function (m, n1) set.has(tokens, n1) ? tokens[n1].source || tokens[n1] : m);
|
expr = String.replace(expr, /(\(?P)?<(\w+)>/g, function (m, n1, n2) !n1 && set.has(tokens, n2) ? tokens[n2].dactylSource || tokens[n2].source || tokens[n2] : m);
|
||||||
|
|
||||||
expr = String.replace(expr, /\/\/[^\n]*|\/\*[^]*?\*\//gm, "")
|
expr = String.replace(expr, /\/\/[^\n]*|\/\*[^]*?\*\//gm, "")
|
||||||
.replace(/\s+/g, "");
|
.replace(/\s+/g, "");
|
||||||
|
|
||||||
if (/\(\?P</.test(expr)) {
|
if (/\(\?P</.test(expr)) {
|
||||||
|
var source = expr;
|
||||||
let groups = ["wholeMatch"];
|
let groups = ["wholeMatch"];
|
||||||
expr = expr.replace(/((?:[^[(\\]|\\.|\[(?:[^\]]|\\.)*\])*)\((?:\?P<([^>]+)>|(\?))?/gy,
|
expr = expr.replace(/((?:[^[(\\]|\\.|\[(?:[^\]]|\\.)*\])*)\((?:\?P<([^>]+)>|(\?))?/gy,
|
||||||
function (m0, m1, m2, m3) {
|
function (m0, m1, m2, m3) {
|
||||||
@@ -1234,7 +1235,6 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
return m1 + "(" + (m3 || "");
|
return m1 + "(" + (m3 || "");
|
||||||
});
|
});
|
||||||
var struct = Struct.apply(null, groups);
|
var struct = Struct.apply(null, groups);
|
||||||
var source = expr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = update(RegExp(expr, flags), {
|
let res = update(RegExp(expr, flags), {
|
||||||
@@ -1244,7 +1244,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
if (struct)
|
if (struct)
|
||||||
update(res, {
|
update(res, {
|
||||||
exec: function exec() let (match = exec.superapply(this, arguments)) match && struct.fromArray(match),
|
exec: function exec() let (match = exec.superapply(this, arguments)) match && struct.fromArray(match),
|
||||||
struct: struct
|
dactylSource: source, struct: struct
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
Reference in New Issue
Block a user