How to use the emphasize.highlight 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 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 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
				) {
github binary-com / binary-static / scripts / extract_js_texts.js View on Github external
            .map((line, idx) => `${padding}${getLineNumber(code_start_line, code_gutter_len, idx)}${emphasize.highlight('js', line).value}`)
            .join('\n')
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