flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/web/app/lib/highlight.server.ts

31 lines1,018 bytesCodeBlame

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 shell1import { THEME, getHighlighter, languageOf, linesToHtml } from "./shiki";
API and MCP server, Rust identity service, registration, site redesign2
3const 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 shell9export 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 */
23export async function highlightLines(path: string, text: string): Promise<string[] | null> {
24 const lang = languageOf(path);
API and MCP server, Rust identity service, registration, site redesign25 if (!lang || text.length > MAX_HIGHLIGHT_CHARS) return null;
26 try {
Agents as a team: lifecycle, merge queue, billing and a new shell27 return linesToHtml(await getHighlighter(), text.replace(/\n$/, ""), lang);
API and MCP server, Rust identity service, registration, site redesign28 } catch {
29 return null;
30 }
31}