-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add syntax highlighting support for more languages
- Loading branch information
Showing
10 changed files
with
103 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
Binary file added
BIN
+10.4 KB
...oedits/renderer/image-gen/__image_snapshots__/unhighlighted-suggestion-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.62 KB
...edits/renderer/image-gen/__image_snapshots__/unhighlighted-suggestion-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
import type { BundledLanguage } from 'shiki/langs' | ||
import type { MultiLineSupportedLanguage } from '../../../completions/detect-multiline' | ||
import type { AddedLinesDecorationInfo } from '../decorators/default-decorator' | ||
import { drawTokensToCanvas, initCanvas } from './canvas' | ||
import { highlightDecorations, initHighlighter } from './highlight' | ||
import { SYNTAX_HIGHLIGHT_MAPPING, highlightDecorations, initHighlighter } from './highlight' | ||
|
||
export async function initImageSuggestionService() { | ||
return Promise.all([initHighlighter(), initCanvas()]) | ||
} | ||
|
||
interface SuggestionOptions { | ||
decorations: AddedLinesDecorationInfo[] | ||
lang: BundledLanguage | ||
lang: string | ||
} | ||
|
||
export function generateSuggestionAsImage(options: SuggestionOptions): { light: string; dark: string } { | ||
const { decorations, lang } = options | ||
const highlightingLang = SYNTAX_HIGHLIGHT_MAPPING[lang as MultiLineSupportedLanguage] | ||
|
||
const highlightedLightDecorations = highlightDecorations(decorations, lang, 'light') | ||
const highlightedDarkDecorations = highlightDecorations(decorations, lang, 'dark') | ||
const darkDecorations = highlightingLang | ||
? highlightDecorations(decorations, highlightingLang, 'dark') | ||
: decorations | ||
const lightDecorations = highlightingLang | ||
? highlightDecorations(decorations, highlightingLang, 'light') | ||
: decorations | ||
|
||
return { | ||
dark: drawTokensToCanvas(highlightedDarkDecorations).toDataURL('image/png'), | ||
light: drawTokensToCanvas(highlightedLightDecorations).toDataURL('image/png'), | ||
dark: drawTokensToCanvas(darkDecorations, 'dark').toDataURL('image/png'), | ||
light: drawTokensToCanvas(lightDecorations, 'light').toDataURL('image/png'), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters