|
1 | 1 | <script lang="ts"> |
2 | 2 | import type { ResultFile } from "$lib/server/search-api"; |
3 | 3 | import { onMount } from "svelte"; |
| 4 | + import type { ThemedToken, BundledLanguage } from "shikiji"; |
| 5 | + import { browserTheme, type BrowserTheme } from "$lib/theme"; |
4 | 6 | import type { LineGroup } from "./chunk-renderer"; |
5 | 7 | import RenderedContent from "./rendered-content.svelte"; |
6 | | - import type { ThemedToken, BundledLanguage } from "shikiji"; |
7 | 8 |
|
8 | 9 | export let lines: LineGroup; |
9 | 10 | export let file: ResultFile; |
|
26 | 27 | let visible = false; |
27 | 28 | let highlights: undefined | ReadonlyArray<ReadonlyArray<ThemedToken>>; |
28 | 29 |
|
29 | | - const highlight = async (code: string) => { |
| 30 | + const highlight = async (code: string, theme: BrowserTheme) => { |
30 | 31 | // We dynamically import shiki itself because it's huge and won't be |
31 | 32 | // needed by those landing on the home page with no search query, or |
32 | 33 | // on the server at all. |
|
50 | 51 | // It's worth checking again, as downloading that chunk can take a |
51 | 52 | // while, and highlighting can occupy meaningful CPU time. |
52 | 53 | highlights = await codeToThemedTokens(code, { |
53 | | - theme: "github-light", |
| 54 | + theme: `github-${theme}`, |
54 | 55 | lang, |
55 | 56 | }); |
56 | 57 | } else if (language !== "text") { |
|
72 | 73 | if (!lines.some(({ line }) => line.text.length >= 1000)) { |
73 | 74 | // Shikiji only accepts a single string even though it goes |
74 | 75 | // right ahead and splits it :(. |
75 | | - highlight(lines.map(({ line: { text } }) => text).join("\n")); |
| 76 | + highlight( |
| 77 | + lines.map(({ line: { text } }) => text).join("\n"), |
| 78 | + $browserTheme, |
| 79 | + ); |
76 | 80 | } else { |
77 | 81 | // We can have defined `highlights` here if our LineGroup was cut in two |
78 | 82 | // by a now-removed "hidden" threshold. Having highlights for part of |
|
108 | 112 | class="py-1 grid grid-cols-[minmax(2rem,_min-content)_1fr] gap-x-2 whitespace-pre overflow-x-auto" |
109 | 113 | > |
110 | 114 | {#each lines as { lineNumber, line }, i} |
111 | | - <span class="select-none text-gray-600 text-right pr-1"> |
| 115 | + <span class="select-none text-gray-600 dark:text-gray-500 text-right pr-1"> |
112 | 116 | {#if file.fileUrl && file.lineNumberTemplate} |
113 | 117 | <a |
114 | 118 | class="hover:underline decoration-1" |
|
0 commit comments