1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-02 00:59:38 +02: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-directive { color: #333; font-weight: bold; }
.cm-staticext { color: #008; }
.cm-staticnetBlock { color: #800; }
.cm-staticnetAllow { color: #004f00; }

View File

@ -24,28 +24,29 @@
'use strict';
CodeMirror.defineMode("ubo-static-filtering", function() {
var reComment1 = /^\s*!/;
var reComment2 = /^\s*#/;
var reExt = /^(\s*[^#]*)(#@?(?:\$\??|\?)?#)(.+)$/;
var reNet = /^(.*?)(?:(\$)([^$]+)?)?$/;
var reNetAllow = /^\s*@@/;
var lineStyle = null;
var lineMatches = null;
const reDirective = /^\s*!#(?:if|endif)\b/;
const reComment1 = /^\s*!/;
const reComment2 = /^\s*#/;
const reExt = /^(\s*[^#]*)(#@?(?:\$\??|\?)?#)(.+)$/;
const reNet = /^(.*?)(?:(\$)([^$]+)?)?$/;
const reNetAllow = /^\s*@@/;
let lineStyle = null;
let lineMatches = null;
var lineStyles = new Map([
const lineStyles = new Map([
[ 'staticext', [ '', 'staticOpt', '' ] ],
[ 'staticnetAllow', [ '', 'staticOpt', '' ] ],
[ 'staticnetBlock', [ '', 'staticOpt', '' ] ],
]);
var styleFromStream = function(stream) {
for ( var i = 1, l = 0; i < lineMatches.length; i++ ) {
const styleFromStream = function(stream) {
for ( let i = 1, l = 0; i < lineMatches.length; i++ ) {
if ( typeof lineMatches[i] !== 'string' ) { continue; }
l += lineMatches[i].length;
if ( stream.pos < l ) {
stream.pos = l;
var style = lineStyle;
var xstyle = lineStyles.get(style)[i-1];
let style = lineStyle;
const xstyle = lineStyles.get(style)[i-1];
if ( xstyle !== '' ) { style += ' ' + xstyle; }
return style;
}
@ -62,6 +63,10 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
} else if ( lineStyle !== null ) {
return styleFromStream(stream);
}
if ( reDirective.test(stream.string) ) {
stream.skipToEnd();
return 'directive';
}
if ( reComment1.test(stream.string) ) {
stream.skipToEnd();
return 'comment';