-
-
Notifications
You must be signed in to change notification settings - Fork 320
/
options.ts
171 lines (156 loc) · 5.14 KB
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import type { LoadWasmOptions } from '../oniguruma'
import type { StringLiteralUnion } from './utils'
import type { LanguageInput, SpecialLanguage } from './langs'
import type { ThemeInput, ThemeRegistrationAny } from './themes'
import type { TransformerOptions } from './transformers'
import type { TokenizeWithThemeOptions, TokensResult } from './tokens'
import type { DecorationOptions } from './decorations'
export interface HighlighterCoreOptions {
/**
* Theme names, or theme registration objects to be loaded upfront.
*/
themes?: ThemeInput[]
/**
* Language names, or language registration objects to be loaded upfront.
*/
langs?: LanguageInput[]
/**
* Alias of languages
* @example { 'my-lang': 'javascript' }
*/
langAlias?: Record<string, string>
/**
* Load wasm file from a custom path or using a custom function.
*/
loadWasm?: LoadWasmOptions
}
export interface BundledHighlighterOptions<L extends string, T extends string> {
/**
* Theme registation
*
* @default []
*/
themes: (ThemeInput | StringLiteralUnion<T>)[]
/**
* Language registation
*
* @default []
*/
langs: (LanguageInput | StringLiteralUnion<L> | SpecialLanguage)[]
/**
* Alias of languages
* @example { 'my-lang': 'javascript' }
*/
langAlias?: Record<string, StringLiteralUnion<L>>
}
export interface CodeOptionsSingleTheme<Themes extends string = string> {
theme: ThemeRegistrationAny | StringLiteralUnion<Themes>
}
export interface CodeOptionsMultipleThemes<Themes extends string = string> {
/**
* A map of color names to themes.
* This allows you to specify multiple themes for the generated code.
*
* ```ts
* highlighter.codeToHtml(code, {
* lang: 'js',
* themes: {
* light: 'vitesse-light',
* dark: 'vitesse-dark',
* }
* })
* ```
*
* Will generate:
*
* ```html
* <span style="color:#111;--shiki-dark:#fff;">code</span>
* ```
*
* @see https://github.com/shikijs/shiki#lightdark-dual-themes
*/
themes: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<Themes>>>
/**
* The default theme applied to the code (via inline `color` style).
* The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
*
* For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
* and the `dark` theme and other custom themes are applied via CSS variables:
*
* ```html
* <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
* ```
*
* When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
*
* ```html
* <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
* ```
*
*
* @default 'light'
*/
defaultColor?: StringLiteralUnion<'light' | 'dark'> | false
/**
* Prefix of CSS variables used to store the color of the other theme.
*
* @default '--shiki-'
*/
cssVariablePrefix?: string
}
export type CodeOptionsThemes<Themes extends string = string> =
| CodeOptionsSingleTheme<Themes>
| CodeOptionsMultipleThemes<Themes>
export type CodeToHastOptions<Languages extends string = string, Themes extends string = string> =
& CodeToHastOptionsCommon<Languages>
& CodeOptionsThemes<Themes>
& CodeOptionsMeta
export interface CodeToHastOptionsCommon<Languages extends string = string>
extends
TransformerOptions,
DecorationOptions,
Pick<TokenizeWithThemeOptions, 'colorReplacements' | 'tokenizeMaxLineLength' | 'tokenizeTimeLimit'> {
lang: StringLiteralUnion<Languages | SpecialLanguage>
/**
* Merge whitespace tokens to saving extra `<span>`.
*
* When set to true, it will merge whitespace tokens with the next token.
* When set to false, it keep the output as-is.
* When set to `never`, it will force to separate leading and trailing spaces from tokens.
*
* @default true
*/
mergeWhitespaces?: boolean | 'never'
/**
* The structure of the generated HAST and HTML.
*
* - `classic`: The classic structure with `<pre>` and `<code>` elements, each line wrapped with a `<span class="line">` element.
* - `inline`: All tokens are rendered as `<span>`, line breaks are rendered as `<br>`. No `<pre>` or `<code>` elements. Default forground and background colors are not applied.
*
* @default 'classic'
*/
structure?: 'classic' | 'inline'
}
export interface CodeOptionsMeta {
/**
* Meta data passed to Shiki, usually used by plugin integrations to pass the code block header.
*
* Key values in meta will be serialized to the attributes of the root `<pre>` element.
*
* Keys starting with `_` will be ignored.
*
* A special key `__raw` key will be used to pass the raw code block header (if the integration supports it).
*/
meta?: {
/**
* Raw string of the code block header.
*/
__raw?: string
[key: string]: any
}
}
export interface CodeToHastRenderOptionsCommon extends TransformerOptions, Omit<TokensResult, 'tokens'> {
lang?: string
langId?: string
}
export type CodeToHastRenderOptions = CodeToHastRenderOptionsCommon & CodeToHastOptions