|
1 | 1 | import { customAlphabet } from 'nanoid'
|
2 | 2 | import c from 'picocolors'
|
3 |
| -import type { LanguageInput, ShikijiTransformer } from 'shikiji' |
| 3 | +import type { ShikijiTransformer } from 'shikiji' |
4 | 4 | import {
|
5 | 5 | bundledLanguages,
|
6 | 6 | getHighlighter,
|
|
9 | 9 | isSpecialLang
|
10 | 10 | } from 'shikiji'
|
11 | 11 | import type { Logger } from 'vite'
|
12 |
| -import type { ThemeOptions } from '../markdown' |
| 12 | +import type { MarkdownOptions, ThemeOptions } from '../markdown' |
13 | 13 | import {
|
14 | 14 | transformerCompactLineOptions,
|
15 | 15 | transformerNotationDiff,
|
@@ -55,21 +55,25 @@ const attrsToLines = (attrs: string): TransformerCompactLineOption[] => {
|
55 | 55 |
|
56 | 56 | export async function highlight(
|
57 | 57 | theme: ThemeOptions,
|
58 |
| - languages: LanguageInput[] = [], |
59 |
| - defaultLang: string = '', |
60 |
| - logger: Pick<Logger, 'warn'> = console, |
61 |
| - userTransformers: ShikijiTransformer[] = [], |
62 |
| - languageAlias: Record<string, string> = {} |
| 58 | + options: MarkdownOptions, |
| 59 | + logger: Pick<Logger, 'warn'> = console |
63 | 60 | ): Promise<(str: string, lang: string, attrs: string) => string> {
|
| 61 | + const { |
| 62 | + defaultHighlightLang: defaultLang = '', |
| 63 | + codeTransformers: userTransformers = [] |
| 64 | + } = options |
| 65 | + |
64 | 66 | const highlighter = await getHighlighter({
|
65 | 67 | themes:
|
66 | 68 | typeof theme === 'string' || 'name' in theme
|
67 | 69 | ? [theme]
|
68 | 70 | : [theme.light, theme.dark],
|
69 |
| - langs: [...Object.keys(bundledLanguages), ...languages], |
70 |
| - langAlias: languageAlias |
| 71 | + langs: [...Object.keys(bundledLanguages), ...(options.languages || [])], |
| 72 | + langAlias: options.languageAlias |
71 | 73 | })
|
72 | 74 |
|
| 75 | + await options?.shikijiSetup?.(highlighter) |
| 76 | + |
73 | 77 | const transformers: ShikijiTransformer[] = [
|
74 | 78 | transformerNotationDiff(),
|
75 | 79 | transformerNotationFocus({
|
|
0 commit comments