javascript - CodeMirror - Using RegEx with overlay -


i can't seem find example of using regex matches create overlay in codemirror. moustaches example matching 1 thing @ time seems simple enough, in api, says regex match returns array of matches , can't figure out in context of structure in moustaches example.

i have regular expression finds elements need highlight: i've tested , works.

should loading array outside of token function , matching each one? or there way work array?

the other issue want apply different styling depending on (biz|cms) option in regex - 1 'biz' , 'cms'. there others i'm trying keep simple.

this far have got. comments show confusion.

codemirror.definemode("tbs", function(config, parserconfig) {     var tbsoverlay = {         token: function(stream, state) {             tbsarray = match("^<(biz|cms).([a-za-z0-9.]*)(\s)?(\/)?>");              if (tbsarray != null) {                 (i = 0; < tbsarray.length; i++) {                      var result = tbsarray[i];                     //do need stream.match each element hold of each bit of text?                     //or there way identify , tag matches?                  }             }              //obviously bit won't work either - regex             while (stream.next() != null && !stream.match("<biz.", false)) {}              return null;         }     };      return codemirror.overlaymode(codemirror.getmode(config, parserconfig.backdrop || "text/html"), tbsoverlay); }); 

it returns array produced regexp.exec or string.prototype.match (see example https://developer.mozilla.org/en-us/docs/javascript/reference/global_objects/string/match), don't want iterate through it, rather pick out specific elements correspond groups in regexp (if (result[1] == "biz") ...)


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -