highlightedLines
uses tcmts.cli.pages.highlight, which uses tcmts.cli.pages.jsxPieces, which uses tcmts.core.ts.parse, which uses tcmts.core.ts.compiler, which uses process
A definition's lines (#tturprzk) as highlighted HTML, one for each: code coloured as its page colours
it; a file by its format (TypeScript, JavaScript and JSON coloured, other text as it is). Not exact, JSX is read by
the scanner alone, which is quick (text between tags may be coloured as code).
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { formatOf, isBytes } from "#codebase/tcmts/cli/files"; import { esc, highlight } from "#codebase/tcmts/cli/pages"; import { highlightedTexts, htmlLines } from "#codebase/tcmts/share"; export function highlightedLines( cb: Codebase, hash: string, lines: string[], exact = true, ): string[] { const rec = cb.store.getDef(hash); const text = lines.join("\n"); const format = !rec ? "" : rec.kind === "file" ? isBytes(rec) ? "" : formatOf(rec) : rec.jsx ? "tsx" : "ts"; // (JSX read from its syntax tree, which takes the compiler a while, or by the scanner alone) const as = format === "tsx" && !exact ? "ts" : format; const key = `${as}\n${text}`; const kept = highlightedTexts.get(key); if (kept) return kept; const html = ["ts", "tsx", "js", "json"].includes(as) ? highlight(text, [], new Set(), as === "tsx") : esc(text); const out = htmlLines(html); // (if the highlighter's lines aren't the lines, each line on its own, as it is) const result = out.length === lines.length ? out : lines.map(esc); highlightedTexts.set(key, result); if (highlightedTexts.size > 4000) highlightedTexts.delete(highlightedTexts.keys().next().value!); return result; }
uses
- tcmts.cli.codebase.Codebase
- tcmts.cli.files.formatOf
- tcmts.cli.files.isBytes
- tcmts.cli.pages.esc
- tcmts.cli.pages.highlight
- tcmts.share.highlightedTexts
- tcmts.share.htmlLines