fine tuning syntax highlighter

This commit is contained in:
Raymond Hill 2018-03-05 13:05:26 -05:00
parent ed8c9ac04e
commit 7a90a69347
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 19 additions and 11 deletions

View file

@ -20,9 +20,10 @@
.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-staticextAnchor { font-weight: bold; }
.cm-staticnetBlock { color: #800; }
.cm-staticnetAllow { color: #004f00; }
.cm-staticnetOpt { font-weight: bold; }
.cm-search-widget {
align-items: center;

View file

@ -27,21 +27,25 @@ 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;
var lineStyles = {
staticext: [ '', 'staticextA', '' ]
};
var lineStyles = new Map([
[ 'staticext', [ '', 'staticextAnchor', '' ] ],
[ 'staticnetAllow', [ '', 'staticnetOpt', '' ] ],
[ 'staticnetBlock', [ '', 'staticnetOpt', '' ] ],
]);
var styleFromStream = function(stream) {
for ( var 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[style][i-1];
var xstyle = lineStyles.get(style)[i-1];
if ( xstyle !== '' ) { style += ' ' + xstyle; }
return style;
}
@ -76,12 +80,15 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
return 'comment';
}
}
if ( reNetAllow.test(stream.string) ) {
stream.skipToEnd();
return 'staticnet allow';
lineMatches = reNet.exec(stream.string);
if ( lineMatches !== null ) {
lineStyle = reNetAllow.test(stream.string) ?
'staticnetAllow' :
'staticnetBlock';
return styleFromStream(stream);
}
stream.skipToEnd();
return 'staticnet block';
return null;
}
};
});