tinyhighlight
Version:
A tiny syntax highlighter.
40 lines (38 loc) • 1.21 kB
JavaScript
import {
highlight
} from "./chunk-LUUY6BET.js";
// src/picocolors.ts
import c from "picocolors";
function getDefs(c2) {
let Invalid = (text) => c2.white(c2.bgRed(c2.bold(text)));
return {
Keyword: c2.magenta,
IdentifierCapitalized: c2.yellow,
Punctuator: c2.yellow,
StringLiteral: c2.green,
NoSubstitutionTemplate: c2.green,
MultiLineComment: c2.gray,
SingleLineComment: c2.gray,
RegularExpressionLiteral: c2.cyan,
NumericLiteral: c2.blue,
TemplateHead: (text) => c2.green(text.slice(0, text.length - 2)) + c2.cyan(text.slice(-2)),
TemplateTail: (text) => c2.cyan(text.slice(0, 1)) + c2.green(text.slice(1)),
TemplateMiddle: (text) => c2.cyan(text.slice(0, 1)) + c2.green(text.slice(1, text.length - 2)) + c2.cyan(text.slice(-2)),
IdentifierCallable: c2.blue,
PrivateIdentifierCallable: (text) => `#${c2.blue(`${text}`.slice(1))}`,
Invalid,
JSXString: c2.green,
JSXIdentifier: c2.yellow,
JSXInvalid: Invalid,
JSXPunctuator: c2.yellow
};
}
function highlight2(code, options = { jsx: !1 }) {
return code ? highlight(code, {
jsx: options.jsx,
colors: getDefs(c)
}) : "";
}
export {
highlight2 as highlight
};