MCPcopy Index your code
hub / github.com/REditorSupport/vscode-R / parseIndexFile

Function parseIndexFile

src/helpViewer/packages.ts:375–412  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

373
374
375function parseIndexFile(html: string): IndexEntry[] {
376
377 const $ = cheerio.load(html);
378
379 const tables = $('table');
380
381 const ret: IndexEntry[] = [];
382
383 // loop over all tables on document and each row as one index entry
384 // assumes that the provided html is from a valid index file
385 tables.each((tableIndex, table) => {
386 const rows = $('tr', table);
387 rows.each((rowIndex, row) => {
388 const elements = $('td', row);
389 if(elements.length === 2){
390 const e0 = elements[0];
391 const e1 = elements[1];
392 if(
393 e0.type === 'tag' && e1.type === 'tag' &&
394 e0.firstChild?.type === 'tag'
395 ){
396 const href = e0.firstChild.attribs['href'];
397 const name = e0.firstChild?.firstChild?.data || '';
398 const description = e1.firstChild?.data || '';
399 ret.push({
400 name: name,
401 description: description,
402 href: href,
403 });
404 }
405 }
406 });
407 });
408
409 const retSorted = ret.sort((a, b) => a.name.localeCompare(b.name));
410
411 return retSorted;
412}
413
414
415// Used to let the user confirm their choice when installing/removing packages

Callers 1

getParsedIndexFileMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected