Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import { highlight as baseHighlight, type TokenColors } from 'tinyhighlight'import c, { type Colors } from 'tinyrainbow'
function getDefs(c: Colors): TokenColors { const Invalid = (text: string) => c.white(c.bgRed(c.bold(text))) return { Keyword: c.magenta, IdentifierCapitalized: c.yellow, Punctuator: c.yellow, StringLiteral: c.green, NoSubstitutionTemplate: c.green, MultiLineComment: c.gray, SingleLineComment: c.gray, RegularExpressionLiteral: c.cyan, NumericLiteral: c.blue, TemplateHead: text => c.green(text.slice(0, text.length - 2)) + c.cyan(text.slice(-2)), TemplateTail: text => c.cyan(text.slice(0, 1)) + c.green(text.slice(1)), TemplateMiddle: text => c.cyan(text.slice(0, 1)) + c.green(text.slice(1, text.length - 2)) + c.cyan(text.slice(-2)), IdentifierCallable: c.blue, PrivateIdentifierCallable: text => `#${c.blue(text.slice(1))}`, Invalid,
JSXString: c.green, JSXIdentifier: c.yellow, JSXInvalid: Invalid, JSXPunctuator: c.yellow, }}
interface HighlightOptions { jsx?: boolean colors?: Colors}
export function highlight( code: string, options: HighlightOptions = { jsx: false },): string { return baseHighlight(code, { jsx: options.jsx, colors: getDefs(options.colors || c), })}