From f76628d4ab597e69bb78fa80a489bdbe04264d65 Mon Sep 17 00:00:00 2001 From: webfansplz <308241863@qq.com> Date: Fri, 13 Jan 2023 23:08:08 +0800 Subject: [PATCH] fix: shiki fallback language (#1044) --- composables/shiki.ts | 9 +++++---- composables/tiptap/shiki.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/composables/shiki.ts b/composables/shiki.ts index 1638576c..a35e55d5 100644 --- a/composables/shiki.ts +++ b/composables/shiki.ts @@ -32,10 +32,11 @@ export function useHightlighter(lang: Lang) { .then(() => { registeredLang.value.set(lang, true) }) - .catch((e) => { - console.error(`[shiki] Failed to load language ${lang}`) - console.error(e) - registeredLang.value.set(lang, false) + .catch(() => { + const fallbackLang = 'md' + shiki.value?.loadLanguage(fallbackLang).then(() => { + registeredLang.value.set(fallbackLang, true) + }) }) return undefined } diff --git a/composables/tiptap/shiki.ts b/composables/tiptap/shiki.ts index 2e564bc4..e38124e0 100644 --- a/composables/tiptap/shiki.ts +++ b/composables/tiptap/shiki.ts @@ -43,7 +43,7 @@ function getDecorations({ findChildren(doc, node => node.type.name === name) .forEach((block) => { let from = block.pos + 1 - const language = block.node.attrs.language || 'text' + const language = block.node.attrs.language const shiki = useHightlighter(language)