Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
codes.forEach(function (cur) {
try {
var tmp = cur.replace(/\<(\/)?(code|pre)\>/g, '').replace(/\&\;/g, '&').replace(/(^|\n)( +)?\#/g, '$1$2\/\/'); // lines starting with #
replacement = cardinal.highlight(tmp, {
linenos: true
});
} catch (e) {
replacement = require('./highlighter.js').highlight(cur.replace(/\<(\/)?(code|pre)\>/g, ''));
// not able to highlight it...ok, let's go on!
replacement = replacement.replace(/\<(\/)?(code|pre)\>/g, '');
}
finalStr = finalStr.replace(cur, CODE_START + CODE_LINE + replacement.replace(/\n/g, CODE_LINE) + CODE_END);
});
})();
function emitHighlightedCode(src, format) {
if (config.highlight) {
// force 'compact' since there is no point in sourcing entire code if we printed it highlighted already
format.compact = true;
try {
stdout.write(cardinal.highlight(src, { linenos: true }) + '\n');
} catch(e) { }
}
}
function printDetails(src, tgt, upgraded) {
console.log(
cardinal.highlight(src) + '\n' +
'==========\nexpected:\n' +
cardinal.highlight(tgt) + '\n' +
'==========\nactual:\n' +
cardinal.highlight(upgraded)
);
}
function run(t, fixture, opts) {
var file = path.join(fixtures, fixture)
, src = fs.readFileSync(file + '.js', 'utf-8')
, tgt = fs.readFileSync(file + '.upgraded.js', 'utf-8').trim('\n')
, upgraded = upgrade(src, opts || defOpts, resolvePath).trim('\n');
t.equals(cardinal.highlight(upgraded), cardinal.highlight(tgt), 'upgrades ' + fixture + '\n')
t.end()
}
let render = (lesson) => {
clear();
console.log(chalk.green(lesson.title));
for (let step of lesson.gyan) {
if (step.type === 'text') console.log(step.value);
else if (step.type === 'code') console.log(cardinal.highlight(step.value));
else if (step.type === 'break') pause();
else if (step.type === 'clear') clear();
}
};
function tryHighlight(s) {
try {
return cardinal.highlight(s, { linenos: false });
} catch (e) {
return null;
}
}
function highlightSource(s) {
try {
return cardinal.highlight(s, { lineno: true });
} catch (e) {
return s;
}
}
write(output, json = false) {
if (this.outputPath) {
fs.writeFileSync(this.outputPath, output);
} else if (isatty(process.stdout.fd) && json) {
const highlighted = highlight(output, { json: true, theme });
process.stdout.write(highlighted);
} else {
process.stdout.write(output);
}
}
}