MCPcopy Create free account
hub / github.com/TruthHun/BookStack / takeToken

Function takeToken

static/mergely/lib/codemirror.js:6771–6790  ·  view source on GitHub ↗
(cm, pos, precise, asArray)

Source from the content-addressed store, hash-verified

6769
6770 // Utility for getTokenAt and getLineTokens
6771 function takeToken(cm, pos, precise, asArray) {
6772 function getObj(copy) {
6773 return {start: stream.start, end: stream.pos,
6774 string: stream.current(),
6775 type: style || null,
6776 state: copy ? copyState(doc.mode, state) : state};
6777 }
6778
6779 var doc = cm.doc, mode = doc.mode, style;
6780 pos = clipPos(doc, pos);
6781 var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise);
6782 var stream = new StringStream(line.text, cm.options.tabSize), tokens;
6783 if (asArray) tokens = [];
6784 while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
6785 stream.start = stream.pos;
6786 style = readToken(mode, stream, state);
6787 if (asArray) tokens.push(getObj(true));
6788 }
6789 return asArray ? tokens : getObj();
6790 }
6791
6792 // Run the given mode's parser over a line, calling f for each token.
6793 function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {

Callers 1

codemirror.jsFile · 0.70

Calls 5

clipPosFunction · 0.70
getLineFunction · 0.70
getStateBeforeFunction · 0.70
readTokenFunction · 0.70
getObjFunction · 0.70

Tested by

no test coverage detected