mirror of https://github.com/gorhill/uBlock.git
fine tuning syntax highlighter
This commit is contained in:
parent
9df0202a00
commit
9b803a2295
|
@ -18,10 +18,11 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cm-s-default .cm-comment {color: #777;}
|
.cm-s-default .cm-comment { color: #777; }
|
||||||
.cm-staticext {color: #008;}
|
.cm-staticext { color: #008; }
|
||||||
.cm-staticnet.cm-block {color: #800;}
|
.cm-staticextA { font-weight: bold; }
|
||||||
.cm-staticnet.cm-allow {color: #004f00;}
|
.cm-staticnet.cm-block { color: #800; }
|
||||||
|
.cm-staticnet.cm-allow { color: #004f00; }
|
||||||
|
|
||||||
.cm-search-widget {
|
.cm-search-widget {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
|
@ -24,29 +24,64 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
CodeMirror.defineMode("ubo-static-filtering", function() {
|
CodeMirror.defineMode("ubo-static-filtering", function() {
|
||||||
var reNotSpace = /\S/;
|
var reComment1 = /^\s*!/;
|
||||||
var reComment = /^(?:!|#[^#@]|#@[^#])/;
|
var reComment2 = /^\s*#/;
|
||||||
var reExt = /^[^#]*#(?:#[^#]|##[^#]|@#)/;
|
var reExt = /^(\s*[^#]*)(#(?:#|@#|\$#|@\$#|\?#|@\?#))(.+)$/;
|
||||||
var reNetAllow = /^@@/;
|
var reNetAllow = /^\s*@@/;
|
||||||
|
var lineStyle = null;
|
||||||
|
var lineMatches = null;
|
||||||
|
|
||||||
|
var lineStyles = {
|
||||||
|
staticext: [ '', 'staticextA', '' ]
|
||||||
|
};
|
||||||
|
|
||||||
|
var styleFromStream = function(stream) {
|
||||||
|
for ( var i = 1, l = 0; i < lineMatches.length; i++ ) {
|
||||||
|
l += lineMatches[i].length;
|
||||||
|
if ( stream.pos < l ) {
|
||||||
|
stream.pos = l;
|
||||||
|
var style = lineStyle;
|
||||||
|
var xstyle = lineStyles[style][i-1];
|
||||||
|
if ( xstyle !== '' ) { style += ' ' + xstyle; }
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stream.skipToEnd();
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
token: function(stream) {
|
token: function(stream) {
|
||||||
var style = null;
|
if ( stream.sol() ) {
|
||||||
var pos = stream.string.search(reNotSpace);
|
lineStyle = null;
|
||||||
if ( pos !== -1 ) {
|
lineMatches = null;
|
||||||
var s = stream.string.slice(pos);
|
} else if ( lineStyle !== null ) {
|
||||||
if ( reComment.test(s) ) {
|
return styleFromStream(stream);
|
||||||
style = 'comment';
|
}
|
||||||
} else if ( reExt.test(s) ) {
|
if ( reComment1.test(stream.string) ) {
|
||||||
style = 'staticext';
|
stream.skipToEnd();
|
||||||
} else if ( reNetAllow.test(s) ) {
|
return 'comment';
|
||||||
style = 'staticnet allow';
|
}
|
||||||
} else {
|
if ( stream.string.indexOf('#') !== -1 ) {
|
||||||
style = 'staticnet block';
|
lineMatches = reExt.exec(stream.string);
|
||||||
|
if (
|
||||||
|
lineMatches !== null &&
|
||||||
|
lineMatches[3].startsWith('##') === false
|
||||||
|
) {
|
||||||
|
lineStyle = 'staticext';
|
||||||
|
return styleFromStream(stream);
|
||||||
|
}
|
||||||
|
if ( reComment2.test(stream.string) ) {
|
||||||
|
stream.skipToEnd();
|
||||||
|
return 'comment';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( reNetAllow.test(stream.string) ) {
|
||||||
|
stream.skipToEnd();
|
||||||
|
return 'staticnet allow';
|
||||||
|
}
|
||||||
stream.skipToEnd();
|
stream.skipToEnd();
|
||||||
return style;
|
return 'staticnet block';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue