javascript - Get value between matching tags? (CodeMirror) -
i'm using codemirror 5.3.
i'm tag matching html in mixed-mode document highlight start , end tags - works well. (https://codemirror.net/demo/matchtags.html)
i'm trying capture content between markers (in case using context-menu action right-click on tags), can send off external process.
i use var tm = doc.getallmarks(); , because i'm tag matching , not bookmarking, pretty know there's going 2 items in array. however, textmarker array returns doesn't (as far can tell) contain {line, ch} cursors marks.
is there proper way starting , ending positions of marks - either directly or lines , character positions? best can think of iterating each:
[].lines[0].parent.lines   and looking see if each instance of codemirror.line has markedspans object, give me line index, , use [].lines[0].markedspans[0].from , [].lines[0].markedspans[0].to find positions of characters in mark. , use doc.getrange grab content , shuffle off processing... this:
var tm = doc.getallmarks(),     lines = tm[0].lines[0].parent.lines,     range = {         from: { line: 0, ch: 0},         to: { line: 0, ch: 0 }     },     hack = 0,     textcontent = ""; (var i=0,j=lines.length;i<j;i++) {     if (lines[i].hasownproperty("markedspans")) {         if (hack==0) { // sorry, i'm in hurry             range.from.line = i;             range.from.ch = lines[i].markedspans.from;             hack=1;         } else {             range.to.line = i;             range.to.ch = lines[i].markedspans.to;         }     } } textcontent = doc.getrange(range.from,range.to);   all sounds pretty glitchy, , i'm looking better way.
you can call .find() on object returned marktext, return {from, to} position of marker (or null if marker cleared).
Comments
Post a Comment