MCPcopy
hub / github.com/codeaashu/claude-code / ansiToHtml

Function ansiToHtml

web/lib/ansi-to-html.ts:144–166  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

142 * Suitable for dangerouslySetInnerHTML when the source is trusted server output.
143 */
144export function ansiToHtml(text: string): string {
145 const segments = parseAnsiSegments(text);
146 return segments
147 .map(({ text: t, style }) => {
148 const parts: string[] = [];
149 if (style.color) parts.push(`color:${style.color}`);
150 if (style.background) parts.push(`background:${style.background}`);
151 if (style.bold) parts.push("font-weight:bold");
152 if (style.dim) parts.push("opacity:0.7");
153 if (style.italic) parts.push("font-style:italic");
154 const deco = [style.underline && "underline", style.strikethrough && "line-through"]
155 .filter(Boolean).join(" ");
156 if (deco) parts.push(`text-decoration:${deco}`);
157
158 const escaped = t
159 .replace(/&/g, "&")
160 .replace(/</g, "&lt;")
161 .replace(/>/g, "&gt;");
162
163 return parts.length ? `<span style="${parts.join(";")}">${escaped}</span>` : escaped;
164 })
165 .join("");
166}

Callers

nothing calls this directly

Calls 2

parseAnsiSegmentsFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected