summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkCode.core.vue
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-02-02 15:05:18 +0900
committerGitHub <noreply@github.com>2024-02-02 15:05:18 +0900
commit9e1145df813a49bcf603f5e1830018eac8c4864d (patch)
tree21c23057a038ce5601bc53fb18c3da724bfb44fd /packages/frontend/src/components/MkCode.core.vue
parentrefactor(frontend): `os.popup()`の`props`の型チェックを有効化 (#13... (diff)
downloadsharkey-9e1145df813a49bcf603f5e1830018eac8c4864d.tar.gz
sharkey-9e1145df813a49bcf603f5e1830018eac8c4864d.tar.bz2
sharkey-9e1145df813a49bcf603f5e1830018eac8c4864d.zip
enhance(frontend): shiki v1に移行 (#13138)
* enhance(frontend): shiki v1に移行 * optimize chunks, エラーを握りつぶす * wasmを分離 * バンドルサイズの警告の最小値を650kBに引き上げ * optimize
Diffstat (limited to 'packages/frontend/src/components/MkCode.core.vue')
-rw-r--r--packages/frontend/src/components/MkCode.core.vue21
1 files changed, 11 insertions, 10 deletions
diff --git a/packages/frontend/src/components/MkCode.core.vue b/packages/frontend/src/components/MkCode.core.vue
index 8fca3bb15f..c655ff416e 100644
--- a/packages/frontend/src/components/MkCode.core.vue
+++ b/packages/frontend/src/components/MkCode.core.vue
@@ -5,13 +5,13 @@ SPDX-License-Identifier: AGPL-3.0-only
<!-- eslint-disable vue/no-v-html -->
<template>
-<div :class="['codeBlockRoot', { 'codeEditor': codeEditor }]" v-html="html"></div>
+<div :class="[$style.codeBlockRoot, { [$style.codeEditor]: codeEditor }]" v-html="html"></div>
</template>
<script lang="ts" setup>
import { ref, computed, watch } from 'vue';
-import { BUNDLED_LANGUAGES } from 'shiki';
-import type { Lang as ShikiLang } from 'shiki';
+import { bundledLanguagesInfo } from 'shiki';
+import type { BuiltinLanguage } from 'shiki';
import { getHighlighter } from '@/scripts/code-highlighter.js';
const props = defineProps<{
@@ -22,24 +22,25 @@ const props = defineProps<{
const highlighter = await getHighlighter();
-const codeLang = ref<ShikiLang | 'aiscript'>('js');
+const codeLang = ref<BuiltinLanguage | 'aiscript'>('js');
const html = computed(() => highlighter.codeToHtml(props.code, {
lang: codeLang.value,
theme: 'dark-plus',
}));
async function fetchLanguage(to: string): Promise<void> {
- const language = to as ShikiLang;
+ const language = to as BuiltinLanguage;
// Check for the loaded languages, and load the language if it's not loaded yet.
if (!highlighter.getLoadedLanguages().includes(language)) {
// Check if the language is supported by Shiki
- const bundles = BUNDLED_LANGUAGES.filter((bundle) => {
+ const bundles = bundledLanguagesInfo.filter((bundle) => {
// Languages are specified by their id, they can also have aliases (i. e. "js" and "javascript")
return bundle.id === language || bundle.aliases?.includes(language);
});
if (bundles.length > 0) {
- await highlighter.loadLanguage(language);
+ console.log(`Loading language: ${language}`);
+ await highlighter.loadLanguage(bundles[0].import);
codeLang.value = language;
} else {
codeLang.value = 'js';
@@ -57,8 +58,8 @@ watch(() => props.lang, (to) => {
}, { immediate: true });
</script>
-<style scoped lang="scss">
-.codeBlockRoot :deep(.shiki) {
+<style module lang="scss">
+.codeBlockRoot :global(.shiki) {
padding: 1em;
margin: .5em 0;
overflow: auto;
@@ -74,7 +75,7 @@ watch(() => props.lang, (to) => {
min-width: 100%;
height: 100%;
- & :deep(.shiki) {
+ & :global(.shiki) {
padding: 12px;
margin: 0;
border-radius: 6px;