(text: string)
| 142 | * Suitable for dangerouslySetInnerHTML when the source is trusted server output. |
| 143 | */ |
| 144 | export 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, "<") |
| 161 | .replace(/>/g, ">"); |
| 162 | |
| 163 | return parts.length ? `<span style="${parts.join(";")}">${escaped}</span>` : escaped; |
| 164 | }) |
| 165 | .join(""); |
| 166 | } |
nothing calls this directly
no test coverage detected