mirror of https://github.com/gorhill/uBlock.git
fine tuning syntax highlighter
This commit is contained in:
parent
ed8c9ac04e
commit
7a90a69347
|
@ -20,9 +20,10 @@
|
||||||
|
|
||||||
.cm-s-default .cm-comment { color: #777; }
|
.cm-s-default .cm-comment { color: #777; }
|
||||||
.cm-staticext { color: #008; }
|
.cm-staticext { color: #008; }
|
||||||
.cm-staticextA { font-weight: bold; }
|
.cm-staticextAnchor { font-weight: bold; }
|
||||||
.cm-staticnet.cm-block { color: #800; }
|
.cm-staticnetBlock { color: #800; }
|
||||||
.cm-staticnet.cm-allow { color: #004f00; }
|
.cm-staticnetAllow { color: #004f00; }
|
||||||
|
.cm-staticnetOpt { font-weight: bold; }
|
||||||
|
|
||||||
.cm-search-widget {
|
.cm-search-widget {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
|
@ -27,21 +27,25 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
|
||||||
var reComment1 = /^\s*!/;
|
var reComment1 = /^\s*!/;
|
||||||
var reComment2 = /^\s*#/;
|
var reComment2 = /^\s*#/;
|
||||||
var reExt = /^(\s*[^#]*)(#(?:#|@#|\$#|@\$#|\?#|@\?#))(.+)$/;
|
var reExt = /^(\s*[^#]*)(#(?:#|@#|\$#|@\$#|\?#|@\?#))(.+)$/;
|
||||||
|
var reNet = /^(.*?)(?:(\$)([^$]+)?)?$/;
|
||||||
var reNetAllow = /^\s*@@/;
|
var reNetAllow = /^\s*@@/;
|
||||||
var lineStyle = null;
|
var lineStyle = null;
|
||||||
var lineMatches = null;
|
var lineMatches = null;
|
||||||
|
|
||||||
var lineStyles = {
|
var lineStyles = new Map([
|
||||||
staticext: [ '', 'staticextA', '' ]
|
[ 'staticext', [ '', 'staticextAnchor', '' ] ],
|
||||||
};
|
[ 'staticnetAllow', [ '', 'staticnetOpt', '' ] ],
|
||||||
|
[ 'staticnetBlock', [ '', 'staticnetOpt', '' ] ],
|
||||||
|
]);
|
||||||
|
|
||||||
var styleFromStream = function(stream) {
|
var styleFromStream = function(stream) {
|
||||||
for ( var i = 1, l = 0; i < lineMatches.length; i++ ) {
|
for ( var i = 1, l = 0; i < lineMatches.length; i++ ) {
|
||||||
|
if ( typeof lineMatches[i] !== 'string' ) { continue; }
|
||||||
l += lineMatches[i].length;
|
l += lineMatches[i].length;
|
||||||
if ( stream.pos < l ) {
|
if ( stream.pos < l ) {
|
||||||
stream.pos = l;
|
stream.pos = l;
|
||||||
var style = lineStyle;
|
var style = lineStyle;
|
||||||
var xstyle = lineStyles[style][i-1];
|
var xstyle = lineStyles.get(style)[i-1];
|
||||||
if ( xstyle !== '' ) { style += ' ' + xstyle; }
|
if ( xstyle !== '' ) { style += ' ' + xstyle; }
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
@ -76,12 +80,15 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
|
||||||
return 'comment';
|
return 'comment';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( reNetAllow.test(stream.string) ) {
|
lineMatches = reNet.exec(stream.string);
|
||||||
stream.skipToEnd();
|
if ( lineMatches !== null ) {
|
||||||
return 'staticnet allow';
|
lineStyle = reNetAllow.test(stream.string) ?
|
||||||
|
'staticnetAllow' :
|
||||||
|
'staticnetBlock';
|
||||||
|
return styleFromStream(stream);
|
||||||
}
|
}
|
||||||
stream.skipToEnd();
|
stream.skipToEnd();
|
||||||
return 'staticnet block';
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue