From 2d08dd8a9c289bcdb6395e8bdf28b6b729946ab1 Mon Sep 17 00:00:00 2001 From: Justice Almanzar Date: Wed, 7 Dec 2022 09:33:40 -0500 Subject: Shiki settings preview (#297) --- src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts') diff --git a/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts b/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts index 416f8e9..0d92f80 100644 --- a/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts +++ b/src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts @@ -18,8 +18,19 @@ import { useSettings } from "@api/settings"; +import { shiki } from "../api/shiki"; import { ShikiSettings } from "../types"; -export function useShikiSettings(settings: (keyof ShikiSettings)[]) { - return useSettings(settings.map(setting => `plugins.ShikiCodeblocks.${setting}`)).plugins.ShikiCodeblocks as ShikiSettings; +export function useShikiSettings(settingKeys: (keyof ShikiSettings)[], overrides?: Record) { + const settings = useSettings(settingKeys.map(key => `plugins.ShikiCodeblocks.${key}`)).plugins.ShikiCodeblocks as ShikiSettings; + + const withOverrides = { ...settings, ...overrides }; + + const themeUrl = withOverrides.customTheme || withOverrides.theme; + if (themeUrl !== shiki.currentThemeUrl) shiki.setTheme(themeUrl); + + return { + ...withOverrides, + isThemeLoading: themeUrl !== shiki.currentThemeUrl, + }; } -- cgit