diff options
| author | Marie <marie@kaifa.ch> | 2024-02-06 21:23:37 +0100 |
|---|---|---|
| committer | Marie <marie@kaifa.ch> | 2024-02-06 21:23:37 +0100 |
| commit | 6a94a52131840728219cec1a91357970837ee85f (patch) | |
| tree | d321f2eed500d1de86b587d1d19ef464912724a1 /packages/frontend/src/components/MkCode.core.vue | |
| parent | merge: fix: quote being returned as null instead of false on mastodon api (!407) (diff) | |
| download | sharkey-6a94a52131840728219cec1a91357970837ee85f.tar.gz sharkey-6a94a52131840728219cec1a91357970837ee85f.tar.bz2 sharkey-6a94a52131840728219cec1a91357970837ee85f.zip | |
merge: upstream
Diffstat (limited to 'packages/frontend/src/components/MkCode.core.vue')
| -rw-r--r-- | packages/frontend/src/components/MkCode.core.vue | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/packages/frontend/src/components/MkCode.core.vue b/packages/frontend/src/components/MkCode.core.vue index b06bb70e99..0da256866e 100644 --- a/packages/frontend/src/components/MkCode.core.vue +++ b/packages/frontend/src/components/MkCode.core.vue @@ -5,14 +5,15 @@ SPDX-License-Identifier: AGPL-3.0-only <!-- eslint-disable vue/no-v-html --> <template> -<div :class="[$style.codeBlockRoot, { [$style.codeEditor]: codeEditor }]" v-html="html"></div> +<div :class="[$style.codeBlockRoot, { [$style.codeEditor]: codeEditor }, (darkMode ? $style.dark : $style.light)]" v-html="html"></div> </template> <script lang="ts" setup> import { ref, computed, watch } from 'vue'; import { bundledLanguagesInfo } from 'shiki'; import type { BuiltinLanguage } from 'shiki'; -import { getHighlighter } from '@/scripts/code-highlighter.js'; +import { getHighlighter, getTheme } from '@/scripts/code-highlighter.js'; +import { defaultStore } from '@/store.js'; const props = defineProps<{ code: string; @@ -21,11 +22,23 @@ const props = defineProps<{ }>(); const highlighter = await getHighlighter(); - +const darkMode = defaultStore.reactiveState.darkMode; const codeLang = ref<BuiltinLanguage | 'aiscript'>('js'); + +const [lightThemeName, darkThemeName] = await Promise.all([ + getTheme('light', true), + getTheme('dark', true), +]); + const html = computed(() => highlighter.codeToHtml(props.code, { lang: codeLang.value, - theme: 'dark-plus', + themes: { + fallback: 'dark-plus', + light: lightThemeName, + dark: darkThemeName, + }, + defaultColor: false, + cssVariablePrefix: '--shiki-', })); async function fetchLanguage(to: string): Promise<void> { @@ -79,6 +92,15 @@ watch(() => props.lang, (to) => { margin: .5em 0; overflow: auto; border-radius: var(--radius-sm); + border: 1px solid var(--divider); + + color: var(--shiki-fallback); + background-color: var(--shiki-fallback-bg); + + & span { + color: var(--shiki-fallback); + background-color: var(--shiki-fallback-bg); + } & pre, & code { @@ -86,6 +108,26 @@ watch(() => props.lang, (to) => { } } +.light.codeBlockRoot :global(.shiki) { + color: var(--shiki-light); + background-color: var(--shiki-light-bg); + + & span { + color: var(--shiki-light); + background-color: var(--shiki-light-bg); + } +} + +.dark.codeBlockRoot :global(.shiki) { + color: var(--shiki-dark); + background-color: var(--shiki-dark-bg); + + & span { + color: var(--shiki-dark); + background-color: var(--shiki-dark-bg); + } +} + .codeBlockRoot.codeEditor { min-width: 100%; height: 100%; @@ -94,6 +136,7 @@ watch(() => props.lang, (to) => { padding: 12px; margin: 0; border-radius: var(--radius-sm); + border: none; min-height: 130px; pointer-events: none; min-width: calc(100% - 24px); @@ -105,6 +148,11 @@ watch(() => props.lang, (to) => { text-rendering: inherit; text-transform: inherit; white-space: pre; + + & span { + display: inline-block; + min-height: 1em; + } } } </style> |