How to use cardinal - 10 common examples

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 sidorares / crconsole / index.js View on Github external
self.client.Debugger.getScriptSource({ scriptId: frame.location.scriptId }, function(err, resp) {
          self.writeLn('break in ' + [lineNumber, columnNumber].join(':'))
          var startLine = lineNumber - NUM_LINES;
          var lastLine  = lineNumber + NUM_LINES;
          var out = [];
          var src = cardinal.highlight(resp.scriptSource, {
            theme: resolveCardinalTheme()
          }).split('\n');
          for (var i=startLine; i < lastLine; ++i) {
            var prefix = pad(lastLine, lineNumber, i);
            var bpsForLine = self.breakpointsForLocation({
              scriptId: frame.location.scriptId,
              lineNumber: i
            });
            if (bpsForLine) {
              prefix = prefix.red;
            }

            if (src[i])
              out.push(prefix + src[i]);
          }
          self.writeLn(out.join('\n'));
          // TODO mark current column with underline?
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 tapjs / node-tap / lib / reporter / pretty-source.js View on Github external
module.exports = (diag) => {
  if (!diag || typeof diag.source !== 'string')
    return null

  if (!diag.source || !diag.at || !diag.at.line || !diag.at.file)
    return diag.source

  const source = diag.source

  const at = diag.at
  try {
    const lines = highlightFileSync(at.file, {
      jsx: true,
      theme,
    }).split('\n')

    const ctx = 3
    const startLine = Math.max(at.line - ctx, 0)
    const endLine = Math.min(at.line + ctx, lines.length)
    const numLen = endLine.toString().length + 1

    const caret = at.column
      ? [
        `  ${new Array(numLen).join(' ')
          } ` + hex('#777')('| ') +
          red(`${new Array(at.column).join('-')}${bold('^')}`)
      ] : []
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;
  }
}

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