Created
June 27, 2012 11:23
-
-
Save mikesimons/3003458 to your computer and use it in GitHub Desktop.
Primer for CodeMirror mode abuse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var code = "function func_name() { var something = 'abc'; return 1; }"; | |
var js_mode = CodeMirror.modes["javascript"]({}, {}); | |
var state = js_mode.startState(); | |
var stream = new CodeMirror.StringStream(code); | |
var style = null; | |
while(!stream.eol()) { | |
style = js_mode.token(stream, state); | |
console.log(style + ": " + code.slice(stream.start, stream.pos)); | |
stream.start = stream.pos; | |
} | |
// See https://github.com/marijnh/CodeMirror2/blob/master/lib/codemirror.js#L2524 | |
// Note this is one line only | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment