diff --git a/package.json b/package.json index c4cdc876..706d2d36 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "@vue/devtools-api": "^6.5.0", "@vueuse/core": "^10.0.2", "body-scroll-lock": "4.0.0-beta.0", - "mark.js": "^8.11.1", + "mark.js": "8.11.1", "minisearch": "^6.0.1", "shiki": "^0.14.1", "vite": "^4.2.1", diff --git a/src/client/shim.d.ts b/src/client/shim.d.ts index 9d312125..6817bb42 100644 --- a/src/client/shim.d.ts +++ b/src/client/shim.d.ts @@ -26,3 +26,9 @@ declare module '@localSearchIndex' { const data: Record Promise<{ default: string }>> export default data } + +declare module 'mark.js/src/vanilla.js' { + import type { Mark } from 'mark.js' + const mark: Mark + export default mark +} diff --git a/src/client/theme-default/components/VPLocalSearchBox.vue b/src/client/theme-default/components/VPLocalSearchBox.vue index 29671e84..39fc1ce6 100644 --- a/src/client/theme-default/components/VPLocalSearchBox.vue +++ b/src/client/theme-default/components/VPLocalSearchBox.vue @@ -9,6 +9,7 @@ import { useScrollLock, useSessionStorage } from '@vueuse/core' +import Mark from 'mark.js/src/vanilla.js' import MiniSearch, { type SearchResult } from 'minisearch' import { useRouter } from 'vitepress' import { @@ -112,8 +113,7 @@ watch(filterText, () => { const mark = computedAsync(async () => { if (!resultsEl.value) return - const mod = await import('mark.js') - return markRaw(new (mod.default ?? mod)(resultsEl.value)) + return markRaw(new Mark(resultsEl.value)) }, null) debouncedWatch(