| 1 | import { createSingletonPromise } from '@antfu/utils' |
| 2 | import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript' |
| 3 | import { createBundledHighlighter, createSingletonShorthands } from 'shiki/core' |
| 4 | import setups from '#slidev/setups/shiki' |
| 5 | import { resolveShikiOptions, shikiContext } from './shiki-options' |
| 6 | |
| 7 | export default createSingletonPromise(async () => { |
| 8 | const { options, languageNames, languageInput, themeOption, themeNames, themeInput } = resolveShikiOptions(await Promise.all(setups.map(setup => setup(shikiContext)))) |
| 9 | |
| 10 | const createHighlighter = createBundledHighlighter<string, string>({ |
| 11 | engine: createJavaScriptRegexEngine, |
| 12 | langs: languageInput, |
| 13 | themes: themeInput, |
| 14 | }) |
| 15 | const shorthands = createSingletonShorthands(createHighlighter) |
| 16 | const getEagerHighlighter = createSingletonPromise(() => shorthands.getSingletonHighlighter({ |
| 17 | ...options, |
| 18 | langs: [...languageNames], |
| 19 | themes: themeNames, |
| 20 | })) |
| 21 | |
| 22 | return { |
| 23 | defaultHighlightOptions: options, |
| 24 | getEagerHighlighter, |
| 25 | shorthands, |
| 26 | languageNames, |
| 27 | themeNames, |
| 28 | themeOption, |
| 29 | } |
| 30 | }) |
| 31 |