MCPcopy Index your code
hub / github.com/compat-table/compat-table / dataToHtml

Function dataToHtml

build.js:421–701  ·  view source on GitHub ↗
(skeleton, rawBrowsers, tests, compiler)

Source from the content-addressed store, hash-verified

419}
420
421function dataToHtml(skeleton, rawBrowsers, tests, compiler) {
422 var $ = cheerio.load(skeleton);
423 var head = $('table thead tr:last-child');
424 var body = $('table tbody');
425 var isNonStandardTable = $('.non-standard table').length > 0;
426 var footnoteIndex = {};
427 var rowNum = 0;
428 // rawBrowsers includes very obsolete browsers which mustn't be printed, but should
429 // be used by interpolateResults(). All other uses should use this, which filters
430 // the very obsolete ones out.
431 var browsers = Object.keys(rawBrowsers).reduce(function (obj,e) {
432 var browser = rawBrowsers[e];
433 if (browser.obsolete !== "very") {
434 obj[e] = browser;
435 }
436 // Even if it's very obsolete, include its footnote if it has one
437 else if (browser.note_html && browser.note_id) {
438 footnoteIndex[browser.note_id] = browser.note_html;
439 }
440 return obj;
441 },{});
442
443 function getHtmlId(id) {
444 return 'test-' + id;
445 }
446
447 function footnoteHTML(obj) {
448 if (obj && obj.note_id) {
449 if (!footnoteIndex[obj.note_id]) {
450 if (obj.note_html) {
451 footnoteIndex[obj.note_id] = obj.note_html;
452 }
453 }
454 var num = Object.keys(footnoteIndex).indexOf(obj.note_id) + 1;
455 return '<a href="#' + obj.note_id + '-note"><sup>[' + num + ']</sup></a>';
456 }
457 return '';
458 }
459
460 function allFootnotes() {
461 var ret = $('<div>');
462 Object.keys(footnoteIndex).forEach(function (e,id) {
463 if (!(e in footnoteIndex)) {
464 console.error("There's no footnote with id '" + e + "'");
465 }
466 ret.append('<p id="' + e + '-note">' +
467 '\t<sup>[' + (id + 1) + ']</sup> ' + footnoteIndex[e] +
468 '</p>');
469 });
470 return ret;
471 }
472
473 function testValue(result) {
474 if (result && typeof result === "object" && "val" in result) {
475 return result.val;
476 }
477 return result;
478 }

Callers 1

handleFunction · 0.85

Calls 11

footnoteHTMLFunction · 0.85
escapeTestNameFunction · 0.85
generateMdnLinkFunction · 0.85
isOptionalFunction · 0.85
getHtmlIdFunction · 0.85
testScriptFunction · 0.85
capitaliseFunction · 0.85
closestStringFunction · 0.85
resultCellFunction · 0.85
testValueFunction · 0.85
allFootnotesFunction · 0.85

Tested by

no test coverage detected