import React from "react"; import { CODE_GUTTER_COLOR } from "../theme.ts"; import { countLines, numWidth, fileExtLanguage, extractTrim } from "../str.ts"; import { HighlightedCode } from "../markdown/highlight-code.tsx"; import { Span } from "paintcannon-react"; import { TerminalFlex } from "./terminal-flex.tsx"; export function FileRenderer({ contents, filePath, startLineNr, }: { contents: string; filePath: string; startLineNr?: number; }) { let start = startLineNr || 1; const lines = countLines(contents) + start; const maxWidth = numWidth(lines); const gutterWidth = maxWidth + 1; const language = fileExtLanguage(filePath); let currentLine = start; return ( {contents.split("\n").map((line, index) => { const lineNumber = currentLine++; const matchedLine = extractTrim(line); return ( {lineNumber} {matchedLine[0]} {matchedLine[2]} ); })} ); }