|
1 | 1 | <script lang="ts" setup> |
2 | 2 | import type { RendererObject } from "marked"; |
| 3 | +import bash from "@shikijs/langs/bash"; |
| 4 | +import githubDark from "@shikijs/themes/github-dark"; |
| 5 | +import githubLight from "@shikijs/themes/github-light"; |
3 | 6 | import { marked } from "marked"; |
| 7 | +import { createHighlighterCoreSync, type HighlighterCore } from "shiki/core"; |
| 8 | +import { createJavaScriptRegexEngine } from "shiki/engine/javascript"; |
4 | 9 |
|
5 | 10 | const props = defineProps<{ |
6 | 11 | owner: string; |
@@ -42,16 +47,47 @@ const selectedCommit = shallowRef< |
42 | 47 | // Markdown |
43 | 48 |
|
44 | 49 | // Add target to links |
45 | | -const renderer: RendererObject = { |
46 | | - link(originalLink) { |
47 | | - const link = marked.Renderer.prototype.link.call(this, originalLink); |
48 | | - return link.replace("<a", "<a target='_blank' rel='noreferrer' "); |
49 | | - }, |
50 | | -}; |
51 | | -marked.use({ renderer }); |
52 | 50 |
|
53 | | -// Pagination |
| 51 | +const colorMode = useColorMode(); |
| 52 | +let shiki: HighlighterCore; |
| 53 | +
|
| 54 | +onBeforeMount(async () => { |
| 55 | + // if (typeof window === 'undefined') { |
| 56 | + // const { loadWasm } = await import('shiki') |
| 57 | + // // @ts-expect-error ignore error |
| 58 | + // await loadWasm(import(/* @vite-ignore */ 'shiki/onig.wasm')) |
| 59 | + // } |
| 60 | +
|
| 61 | + shiki = createHighlighterCoreSync({ |
| 62 | + themes: [githubDark, githubLight], |
| 63 | + langs: [bash], |
| 64 | + engine: createJavaScriptRegexEngine(), |
| 65 | + }); |
| 66 | +
|
| 67 | + const renderer: RendererObject = { |
| 68 | + link(originalLink) { |
| 69 | + const link = marked.Renderer.prototype.link.call(this, originalLink); |
| 70 | + return link.replace( |
| 71 | + "<a", |
| 72 | + "<a target='_blank' rel='noreferrer' class='text-primary underline'", |
| 73 | + ); |
| 74 | + }, |
| 75 | + code({ text }) { |
| 76 | + return `<code class="language-bash">${shiki.codeToHtml(text, { |
| 77 | + theme: colorMode.preference === "dark" ? "github-dark" : "github-light", |
| 78 | + lang: "bash", |
| 79 | + })}</code>`; |
| 80 | + }, |
| 81 | + }; |
54 | 82 |
|
| 83 | + marked.use({ renderer }); |
| 84 | +}); |
| 85 | +
|
| 86 | +onBeforeUnmount(() => { |
| 87 | + shiki?.dispose(); |
| 88 | +}); |
| 89 | +
|
| 90 | +// Pagination |
55 | 91 | const fetching = ref(false); |
56 | 92 | const fetchMoreForceDisabled = ref(!commitsWithRelease.value.length); |
57 | 93 |
|
@@ -218,7 +254,7 @@ async function fetchMore() { |
218 | 254 | </div> |
219 | 255 |
|
220 | 256 | <div |
221 | | - class="max-w-full p-4 border border-gray-100 dark:border-gray-800 rounded-lg prose dark:prose-invert" |
| 257 | + class="max-w-full p-4 overflow-x-scroll border border-gray-100 dark:border-gray-800 rounded-lg prose dark:prose-invert flex flex-col gap-2" |
222 | 258 | v-html="marked(selectedCommit.release.text)" |
223 | 259 | /> |
224 | 260 | </div> |
|
0 commit comments