From 7a90a693471d6c1f84673ebbce50a876dd3625aa Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 5 Mar 2018 13:05:26 -0500 Subject: [PATCH] fine tuning syntax highlighter --- src/css/codemirror.css | 7 ++++--- src/js/codemirror/ubo-static-filtering.js | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) 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; } }; });