Skip to content

Commit

Permalink
fix(search): fix highlighting in detailed view
Browse files Browse the repository at this point in the history
mark.js ships dist as IIFE which causes lot of issues, but is also has its source available in the package which is _almost_ ESM, so directly using it and locking the version to avoid any issues due to internal changes
  • Loading branch information
brc-dd committed Apr 20, 2023
1 parent 1f5798e commit 1f4920c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/client/shim.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ declare module '@localSearchIndex' {
const data: Record<string, () => 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
}
4 changes: 2 additions & 2 deletions src/client/theme-default/components/VPLocalSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1f4920c

Please sign in to comment.