MCPcopy Index your code
hub / github.com/banga/git-split-diffs / highlightSyntaxInLine

Function highlightSyntaxInLine

src/highlightSyntaxInLine.ts:33–59  ·  view source on GitHub ↗
(
    line: FormattedString,
    fileName: string,
    highlighter: shiki.Highlighter,
    theme: shiki.BundledTheme
)

Source from the content-addressed store, hash-verified

31}
32
33export async function highlightSyntaxInLine(
34 line: FormattedString,
35 fileName: string,
36 highlighter: shiki.Highlighter,
37 theme: shiki.BundledTheme
38): Promise<void> {
39 const language = path.extname(fileName).slice(1) as shiki.BundledLanguage;
40 if (!shiki.bundledLanguages[language]) {
41 return;
42 }
43
44 await highlighter.loadLanguage(language);
45
46 const { tokens } = highlighter.codeToTokens(line.getString(), {
47 includeExplanation: false,
48 lang: language,
49 theme,
50 });
51
52 for (const token of tokens.flat()) {
53 line.addSpan(
54 token.offset,
55 token.offset + token.content.length,
56 parseShikiColor(token)
57 );
58 }
59}

Callers 3

benchmark.tsFile · 0.90
formatAndFitHunkLineFunction · 0.90

Calls 4

parseShikiColorFunction · 0.85
sliceMethod · 0.80
getStringMethod · 0.80
addSpanMethod · 0.80

Tested by

no test coverage detected