diff --git a/src/css/codemirror.css b/src/css/codemirror.css index 9f929738d..c02839677 100644 --- a/src/css/codemirror.css +++ b/src/css/codemirror.css @@ -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; diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index 24a871400..28e8d6b5b 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -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; } }; });