/** * Syntax highlighting as structured spans, for the terminal's diff panel. * * `highlight.ts` returns lines with ANSI codes already embedded, built by running one regex * replacement after another over the same string. That is fine for printing a line and wrong here, * for two reasons. The colours it inserts become text the later regexes then match against — the * number rule sees the `32` inside the green it just wrote — so the chain is correct only in the * order it happens to run in, and a rule added later can quietly corrupt the ones before it. And * embedded ANSI cannot be combined with a background: the diff panel tints added lines green, and a * pre-coloured string carries its own resets that fight the tint. * * So this walks each line once, character by character, and returns typed spans. Nothing is * re-scanned, so nothing can be corrupted; whitespace is preserved exactly, which the regex chain * did not manage either; and the caller decides what colour a kind is and what sits behind it. * * Line-at-a-time deliberately. A diff shows fragments — hunks with gaps between them — so there is * no whole file to parse and a block comment's opening may never be in view. Each line is judged on * what it contains, which is what a diff reader is looking at anyway. */ export type SpanKind = 'plain' | 'keyword' | 'string' | 'comment' | 'number' | 'fn' | 'type' | 'punct'; export interface Span { text: string; kind: SpanKind; } export type SpanLang = 'js' | 'py' | 'sh' | 'css' | 'json' | 'md' | 'generic'; /** The language to tokenise as, from a file name. */ export declare function spanLangFor(filename: string): SpanLang; export declare function tokenizeLine(line: string, lang?: SpanLang): Span[]; //# sourceMappingURL=highlight-spans.d.ts.map