1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

Visually emphasize directive syntax (!#if/!#endif) in list viewer/editor

This commit is contained in:
Raymond Hill 2019-03-21 19:53:04 -03:00
parent c56fee9448
commit ac71d6577a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 18 additions and 12 deletions

View File

@ -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; }

View File

@ -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';