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.
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 1 | // Shiki and its grammars load on the first file highlighted, not when the |
| 2 | // Worker starts: most requests highlight nothing. | |
| 3 | const shiki = () => import("./shiki"); | |
| API and MCP server, Rust identity service, registration, site redesign | 4 | |
| 5 | const MAX_HIGHLIGHT_CHARS = 200_000; | |
| 6 | ||
| 7 | /** | |
| 8 | * Highlighted HTML for a file, or null when its language is unknown or it | |
| 9 | * is too large, in which case the caller shows plain text. | |
| 10 | */ | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 11 | export async function highlight(path: string, text: string): Promise<string | null> { |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 12 | const { THEME, getHighlighter, languageOf } = await shiki(); |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 13 | const lang = languageOf(path); |
| 14 | if (!lang || text.length > MAX_HIGHLIGHT_CHARS) return null; | |
| 15 | try { | |
| 16 | return (await getHighlighter()).codeToHtml(text.replace(/\n$/, ""), { lang, theme: THEME }); | |
| 17 | } catch { | |
| 18 | return null; | |
| 19 | } | |
| 20 | } | |
| 21 | ||
| 22 | /** | |
| 23 | * A file's lines as highlighted HTML, one string per line, or null when its | |
| 24 | * language is unknown or it is too large. | |
| 25 | */ | |
| 26 | export async function highlightLines(path: string, text: string): Promise<string[] | null> { | |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 27 | const { getHighlighter, languageOf, linesToHtml } = await shiki(); |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 28 | const lang = languageOf(path); |
| API and MCP server, Rust identity service, registration, site redesign | 29 | if (!lang || text.length > MAX_HIGHLIGHT_CHARS) return null; |
| 30 | try { | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 31 | return linesToHtml(await getHighlighter(), text.replace(/\n$/, ""), lang); |
| API and MCP server, Rust identity service, registration, site redesign | 32 | } catch { |
| 33 | return null; | |
| 34 | } | |
| 35 | } |