How to use emphasize - 10 common examples

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
printData(response) {
    if (! response.data) {
      return print(chalk.gray(''));
    }

    // 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 nikersify / jay / source / plugin / highlight.ts View on Github external
const highlightSheet: Sheet = {
			keyword: c.magenta,
			built_in: c.cyan.italic,
			literal: c.cyan,
			number: c.yellow,
			regexp: c.red,
			string: c.green,
			symbol: c.cyan,
			class: c.yellow.italic,
			attr: c.cyan,
			comment: c.gray
		}
		/* eslint-enable @typescript-eslint/camelcase */

		return [
			emphasize.highlight(
				'js',
				output,
				highlightSheet
			).value,
			cursor
		]
	})
}
github thatisuday / catage / lib / functions.js View on Github external
const stringToAnsi = exports.stringToAnsi = ( str, language ) => {
    
    // accept case-insensitive language
    language = _.isEmpty( language ) ? null : language.toLowerCase();

    // if `language` is not supported, return `str` back without syntax highlighting
    if( ! _.includes( _.values( LANGUAGES ), language ) ) {
        return str;
    }

    // highlight `str` using `emphasize` package in ANSI color format
    const { value } = emphasize.highlight( language, str );

    // return ANSI formatted string
    return value;
};
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 forthright / vile / lib / cli / analyze / log_helper.js View on Github external
var log_snippet = function (lines, code, filepath, file_ext, nocolors) {
    if (nocolors) {
        console.log(_.zip(lines, code.split("\n"))
            .map(function (s) { return s.join(" "); }).join("\n"));
    }
    else {
        var colored = void 0;
        try {
            colored = _.get(emphasize
                .highlight(file_ext, code), "value", "");
        }
        catch (e) {
            log.warn("highlighting failed for " + filepath + ":");
            colored = code;
        }
        var colored_lines = lines.map(function (l) { return chalk.gray(l); });
        console.log(_.zip(colored_lines, colored.split("\n"))
            .map(function (s) { return s.join(""); }).join("\n"));
    }
};
var to_console_snippet = function (issue, nocolors) {
github forthright / vile / src / cli / analyze / log_helper.ts View on Github external
const log_snippet = (
  lines : any[],
  code : string,
  filepath : string,
  file_ext : string,
  nocolors : boolean
) : void => {
  if (nocolors) {
    console.log(_.zip(lines, code.split("\n"))
      .map((s : any[]) => s.join(" ")).join("\n"))
  } else {
    let colored : string

    try {
      colored = _.get(emphasize
        .highlight(file_ext, code), "value", "")
    } catch (e) {
      log.warn(`highlighting failed for ${filepath}:`)
      colored = code
    }

    const colored_lines = lines.map((l) => chalk.gray(l))
    console.log(_.zip(colored_lines, colored.split("\n"))
      .map((s : any[]) => s.join("")).join("\n"))
  }
}
github Siteimprove / alfa / packages / alfa-highlight / src / highlight.ts View on Github external
export function highlight(language: string, value: string): string {
  return mark.reset(emphasize.highlight(language, value, sheet).value);
}
github nikersify / jay / source / prompt.ts View on Github external
function renderPrompt(): void {
			const cols = stdout.columns || Infinity
			const completion = scroller && menuItems.length > 0 ?
				menuItems[scroller.selected === -1 ? 0 : scroller.selected][0] :
				''

			const lineHighlightTime = time('lineHighlight')
			const highlightedLine =
				emphasize.highlight('js', rl.line, highlightSheet).value
			debug(lineHighlightTime())

			const slice = (start: number, end?: number) =>
				sliceAnsi(highlightedLine, start, end)

			const beforeCursor = (() => {
				const sliced = slice(0, rl.cursor)

				if (menuItems.length === 0) {
					return sliced
				}

				if (
					((scroller && scroller.selected === -1) || !scroller) &&
					!stopping
				) {

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