How to use the cardinal.highlight function in cardinal

To help you get started, we’ve selected a few cardinal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github felipenmoura / sos-stackoverflow-search / dist / stringUtils.js View on Github external
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);
                });
            })();
github thlorenz / replpad / lib / feedEdits.js View on Github external
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) { }
      }
    }
github thlorenz / browserify-ftw / test / upgrade.js View on Github external
function printDetails(src, tgt, upgraded) {
  console.log(
    cardinal.highlight(src) + '\n' +
    '==========\nexpected:\n' +
    cardinal.highlight(tgt) + '\n' +
    '==========\nactual:\n' +
    cardinal.highlight(upgraded)
  );
}
github thlorenz / browserify-ftw / test / upgrade.js View on Github external
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()
}
github siddharthkp / learn-es6 / helpers / render.js View on Github external
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();
    }
};
github thlorenz / hermit / lib / style.js View on Github external
function tryHighlight(s) {
    try {
      return cardinal.highlight(s, { linenos: false });
    } catch (e) {
      return null;
    }
  }
github thlorenz / active-handles / index.js View on Github external
function highlightSource(s) {
  try {
    return cardinal.highlight(s, { lineno: true });
  } catch (e)  {
    return s;
  }
}
github apiaryio / api-elements.js / packages / fury-cli / lib / fury.js View on Github external
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);
    }
  }
}

cardinal

Syntax highlights JavaScript code with ANSI colors to be printed to the terminal.

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis