mirror of https://github.com/gorhill/uBlock.git
Visually emphasize directive syntax (`!#if`/`!#endif`) in list viewer/editor
This commit is contained in:
parent
c56fee9448
commit
ac71d6577a
|
@ -18,6 +18,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.cm-s-default .cm-comment { color: #777; }
|
.cm-s-default .cm-comment { color: #777; }
|
||||||
|
.cm-directive { color: #333; font-weight: bold; }
|
||||||
.cm-staticext { color: #008; }
|
.cm-staticext { color: #008; }
|
||||||
.cm-staticnetBlock { color: #800; }
|
.cm-staticnetBlock { color: #800; }
|
||||||
.cm-staticnetAllow { color: #004f00; }
|
.cm-staticnetAllow { color: #004f00; }
|
||||||
|
|
|
@ -24,28 +24,29 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
CodeMirror.defineMode("ubo-static-filtering", function() {
|
CodeMirror.defineMode("ubo-static-filtering", function() {
|
||||||
var reComment1 = /^\s*!/;
|
const reDirective = /^\s*!#(?:if|endif)\b/;
|
||||||
var reComment2 = /^\s*#/;
|
const reComment1 = /^\s*!/;
|
||||||
var reExt = /^(\s*[^#]*)(#@?(?:\$\??|\?)?#)(.+)$/;
|
const reComment2 = /^\s*#/;
|
||||||
var reNet = /^(.*?)(?:(\$)([^$]+)?)?$/;
|
const reExt = /^(\s*[^#]*)(#@?(?:\$\??|\?)?#)(.+)$/;
|
||||||
var reNetAllow = /^\s*@@/;
|
const reNet = /^(.*?)(?:(\$)([^$]+)?)?$/;
|
||||||
var lineStyle = null;
|
const reNetAllow = /^\s*@@/;
|
||||||
var lineMatches = null;
|
let lineStyle = null;
|
||||||
|
let lineMatches = null;
|
||||||
|
|
||||||
var lineStyles = new Map([
|
const lineStyles = new Map([
|
||||||
[ 'staticext', [ '', 'staticOpt', '' ] ],
|
[ 'staticext', [ '', 'staticOpt', '' ] ],
|
||||||
[ 'staticnetAllow', [ '', 'staticOpt', '' ] ],
|
[ 'staticnetAllow', [ '', 'staticOpt', '' ] ],
|
||||||
[ 'staticnetBlock', [ '', 'staticOpt', '' ] ],
|
[ 'staticnetBlock', [ '', 'staticOpt', '' ] ],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var styleFromStream = function(stream) {
|
const styleFromStream = function(stream) {
|
||||||
for ( var i = 1, l = 0; i < lineMatches.length; i++ ) {
|
for ( let i = 1, l = 0; i < lineMatches.length; i++ ) {
|
||||||
if ( typeof lineMatches[i] !== 'string' ) { continue; }
|
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;
|
let style = lineStyle;
|
||||||
var xstyle = lineStyles.get(style)[i-1];
|
const xstyle = lineStyles.get(style)[i-1];
|
||||||
if ( xstyle !== '' ) { style += ' ' + xstyle; }
|
if ( xstyle !== '' ) { style += ' ' + xstyle; }
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +63,10 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
|
||||||
} else if ( lineStyle !== null ) {
|
} else if ( lineStyle !== null ) {
|
||||||
return styleFromStream(stream);
|
return styleFromStream(stream);
|
||||||
}
|
}
|
||||||
|
if ( reDirective.test(stream.string) ) {
|
||||||
|
stream.skipToEnd();
|
||||||
|
return 'directive';
|
||||||
|
}
|
||||||
if ( reComment1.test(stream.string) ) {
|
if ( reComment1.test(stream.string) ) {
|
||||||
stream.skipToEnd();
|
stream.skipToEnd();
|
||||||
return 'comment';
|
return 'comment';
|
||||||
|
|
Loading…
Reference in New Issue