MCPcopy Create free account
hub / github.com/cosscom/coss / highlightCode

Function highlightCode

packages/ui/src/lib/highlight-code.ts:55–88  ·  view source on GitHub ↗
(
	code: string,
	language = "tsx",
	options?: { showLineNumbers?: boolean },
)

Source from the content-addressed store, hash-verified

53] as ShikiTransformer[];
54
55export async function highlightCode(
56 code: string,
57 language = "tsx",
58 options?: { showLineNumbers?: boolean },
59) {
60 const { showLineNumbers = true } = options ?? {};
61
62 const html = await codeToHtml(code, {
63 lang: language,
64 themes: {
65 dark: "github-dark",
66 light: "github-light",
67 },
68 transformers: [
69 {
70 code(node) {
71 if (showLineNumbers) {
72 node.properties["data-line-numbers"] = "";
73 }
74 },
75 line(node) {
76 node.properties["data-line"] = "";
77 },
78 pre(node) {
79 node.properties.class =
80 "text-[.8125rem] min-w-0 w-max px-4 py-3.5 outline-none has-data-[highlighted-line]:px-0 has-data-[line-numbers]:ps-0 has-data-[slot=tabs]:p-0 !bg-transparent";
81 },
82 },
83 transformerNotationWordHighlight(),
84 ],
85 });
86
87 return html;
88}

Callers 1

CodeBlockFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected