g1t/apps/web/app/lib/highlight.server.ts
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Agents as a team: lifecycle, merge queue, billing and a new shell | 1 | import { THEME, getHighlighter, languageOf, linesToHtml } from "./shiki"; |
| API and MCP server, Rust identity service, registration, site redesign | 2 | |
| 3 | const MAX_HIGHLIGHT_CHARS = 200_000; | |
| 4 | ||
| 5 | /** | |
| 6 | * Highlighted HTML for a file, or null when its language is unknown or it | |
| 7 | * is too large, in which case the caller shows plain text. | |
| 8 | */ | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 9 | export async function highlight(path: string, text: string): Promise<string | null> { |
| 10 | const lang = languageOf(path); | |
| 11 | if (!lang || text.length > MAX_HIGHLIGHT_CHARS) return null; | |
| 12 | try { | |
| 13 | return (await getHighlighter()).codeToHtml(text.replace(/\n$/, ""), { lang, theme: THEME }); | |
| 14 | } catch { | |
| 15 | return null; | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | /** | |
| 20 | * A file's lines as highlighted HTML, one string per line, or null when its | |
| 21 | * language is unknown or it is too large. | |
| 22 | */ | |
| 23 | export async function highlightLines(path: string, text: string): Promise<string[] | null> { | |
| 24 | const lang = languageOf(path); | |
| API and MCP server, Rust identity service, registration, site redesign | 25 | if (!lang || text.length > MAX_HIGHLIGHT_CHARS) return null; |
| 26 | try { | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 27 | return linesToHtml(await getHighlighter(), text.replace(/\n$/, ""), lang); |
| API and MCP server, Rust identity service, registration, site redesign | 28 | } catch { |
| 29 | return null; | |
| 30 | } | |
| 31 | } |