1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-06 02:59:39 +02:00

fine tuning syntax highlighter

This commit is contained in:
Raymond Hill 2018-03-05 11:25:45 -05:00
parent 9df0202a00
commit 9b803a2295
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 57 additions and 21 deletions

View File

@ -18,10 +18,11 @@
height: 100%;
}
.cm-s-default .cm-comment {color: #777;}
.cm-staticext {color: #008;}
.cm-staticnet.cm-block {color: #800;}
.cm-staticnet.cm-allow {color: #004f00;}
.cm-s-default .cm-comment { color: #777; }
.cm-staticext { color: #008; }
.cm-staticextA { font-weight: bold; }
.cm-staticnet.cm-block { color: #800; }
.cm-staticnet.cm-allow { color: #004f00; }
.cm-search-widget {
align-items: center;

View File

@ -24,29 +24,64 @@
'use strict';
CodeMirror.defineMode("ubo-static-filtering", function() {
var reNotSpace = /\S/;
var reComment = /^(?:!|#[^#@]|#@[^#])/;
var reExt = /^[^#]*#(?:#[^#]|##[^#]|@#)/;
var reNetAllow = /^@@/;
var reComment1 = /^\s*!/;
var reComment2 = /^\s*#/;
var reExt = /^(\s*[^#]*)(#(?:#|@#|\$#|@\$#|\?#|@\?#))(.+)$/;
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 {
token: function(stream) {
var style = null;
var pos = stream.string.search(reNotSpace);
if ( pos !== -1 ) {
var s = stream.string.slice(pos);
if ( reComment.test(s) ) {
style = 'comment';
} else if ( reExt.test(s) ) {
style = 'staticext';
} else if ( reNetAllow.test(s) ) {
style = 'staticnet allow';
} else {
style = 'staticnet block';
if ( stream.sol() ) {
lineStyle = null;
lineMatches = null;
} else if ( lineStyle !== null ) {
return styleFromStream(stream);
}
if ( reComment1.test(stream.string) ) {
stream.skipToEnd();
return 'comment';
}
if ( stream.string.indexOf('#') !== -1 ) {
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();
return style;
return 'staticnet block';
}
};
});