mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-29 13:49:41 +07:00
* Remove docs folder. This was a redirect from a GitHub pages site that does not appear to be in use. * Rename api folder to api-samples. * Move examples to functional-samples folder. * Move cookbook sample to functional-samples. * Move tutorials to functional-samples folder. * Move mv2 and apps folders to _archive. * Rename tools folder to .repo. * Move reference folder to functional-samples. * Update README. Update README with new relative links for reorg. * Update README.md Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> --------- Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
CodeMirror.runMode = function(string, modespec, callback, options) {
|
|
var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
|
|
var isNode = callback.nodeType == 1;
|
|
var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
|
|
if (isNode) {
|
|
var node = callback, accum = [], col = 0;
|
|
callback = function(text, style) {
|
|
if (text == "\n") {
|
|
accum.push("<br>");
|
|
col = 0;
|
|
return;
|
|
}
|
|
var escaped = "";
|
|
// HTML-escape and replace tabs
|
|
for (var pos = 0;;) {
|
|
var idx = text.indexOf("\t", pos);
|
|
if (idx == -1) {
|
|
escaped += CodeMirror.htmlEscape(text.slice(pos));
|
|
col += text.length - pos;
|
|
break;
|
|
} else {
|
|
col += idx - pos;
|
|
escaped += CodeMirror.htmlEscape(text.slice(pos, idx));
|
|
var size = tabSize - col % tabSize;
|
|
col += size;
|
|
for (var i = 0; i < size; ++i) escaped += " ";
|
|
pos = idx + 1;
|
|
}
|
|
}
|
|
|
|
if (style)
|
|
accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + escaped + "</span>");
|
|
else
|
|
accum.push(escaped);
|
|
}
|
|
}
|
|
var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
|
|
for (var i = 0, e = lines.length; i < e; ++i) {
|
|
if (i) callback("\n");
|
|
var stream = new CodeMirror.StringStream(lines[i]);
|
|
while (!stream.eol()) {
|
|
var style = mode.token(stream, state);
|
|
callback(stream.current(), style, i, stream.start);
|
|
stream.start = stream.pos;
|
|
}
|
|
}
|
|
if (isNode)
|
|
node.innerHTML = accum.join("");
|
|
};
|