MCPcopy Index your code
hub / github.com/bigskysoftware/_hyperscript / renderCode

Function renderCode

debug-plugin/content-script.js:197–235  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

195 };
196
197 const renderCode = function () {
198 if (!cmd || !cmd.programSource) {
199 return "";
200 }
201 cmdMap = [];
202 const src = cmd.programSource;
203
204 // Find feature
205 let feat = cmd;
206 while (feat.parent && !feat.isFeature) feat = feat.parent;
207
208 // Traverse, finding starts
209 const all = traverse(feat);
210 for (let j = 0; j < all.length; j++) {
211 const c = all[j];
212 if (!c.startToken) continue;
213 cmdMap.push({
214 index: c.startToken.start,
215 widget: makeCommandWidget(cmdMap.length),
216 cmd: c,
217 });
218 }
219
220 let rv = src.slice(0, cmdMap[0].index);
221 for (let i = 0; i < cmdMap.length; i++) {
222 const obj = cmdMap[i];
223 const end = cmdMap[i + 1] ? cmdMap[i + 1].index : undefined;
224 if (obj.cmd === cmd) {
225 rv +=
226 obj.widget +
227 '<u class="current">' +
228 escapeHTML(src.slice(obj.index, end)) +
229 "</u>";
230 } else {
231 rv += obj.widget + escapeHTML(src.slice(obj.index, end));
232 }
233 }
234 return rv;
235 };
236
237 const traverse = function (ge) {
238 const rv = [];

Callers 1

uiFunction · 0.85

Calls 3

traverseFunction · 0.85
makeCommandWidgetFunction · 0.85
escapeHTMLFunction · 0.70

Tested by

no test coverage detected