How to use the emphasize.highlightAuto function in emphasize

To help you get started, we’ve selected a few emphasize 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 paulirish / c-cli / cli.js View on Github external
//     sudo easy_install -U Pygments
//     alias c='pygmentize -O style=monokai -f console256 -g'
// Performance-wise they appear to be pretty much the same.

const fs = require('fs');

const emphasize = require('emphasize');

const filePath = process.argv[2];
if (!filePath) {
    console.error('USAGE: c filename.ext');
    process.exit(1);
}

const doc = fs.readFileSync(filePath, 'utf8');
const output = emphasize.highlightAuto(doc).value;

process.stdout.write(output);
github DFurnes / hey / src / DefaultFormatter.js View on Github external
// Handle pretty-printing common types of content (by header).
    if (response.headers && response.headers['content-type']) {
      let type = response.headers['content-type'];

      if (type.includes('application/json')) {
        return printJson(response.data);
      } else if (type.includes('text/html') || type.includes('application/xml')) {
        return print(emphasize.highlight('xml', response.data).value);
      } else if (type.includes('text/plain')) {
        return print(response.data);
      }
    }

    // ...or try to guess!
    return print(emphasize.highlightAuto(response.data).value);
  }
}
github parcel-bundler / parcel / packages / core / codeframe / src / codeframe.js View on Github external
const highlightSyntax = (txt: string, lang?: string): string => {
  if (lang) {
    try {
      return emphasize.highlight(lang, txt).value;
    } catch (e) {
      // fallback for unknown languages...
    }
  }

  return emphasize.highlightAuto(txt).value;
};
github gucong3000 / gulp-reporter / lib / formatter.js View on Github external
function highlight (error) {
	let source = error.source.replace(/\t/g, '    ');
	if (chalk.enabled) {
		const extname = path.extname(error.fileName).slice(1);
		if (extname) {
			try {
				return emphasize.highlight(extname.slice(1), source).value;
			} catch (ex) {
				//
			}
		}
		source = emphasize.highlightAuto(source).value;
	}
	return source;
}

emphasize

ANSI syntax highlighting for the terminal

MIT
Latest version published 1 year ago

Package Health Score

54 / 100
Full package analysis

Popular emphasize functions