PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.5.0
Code Block Pro – Beautiful Syntax Highlighting v1.5.0
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / build / shiki / dist / index.d.ts

index.d.ts in Code Block Pro – Beautiful Syntax Highlighting 1.5.0, at build/shiki/dist/index.d.ts

323 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { IRawThemeSetting, IRawGrammar, IRawTheme } from 'vscode-textmate';
2
3 declare type Theme = 'css-variables' | 'dark-plus' | 'dracula-soft' | 'dracula' | 'github-dark-dimmed' | 'github-dark' | 'github-light' | 'hc_light' | 'light-plus' | 'material-darker' | 'material-default' | 'material-lighter' | 'material-ocean' | 'material-palenight' | 'min-dark' | 'min-light' | 'monokai' | 'nord' | 'one-dark-pro' | 'poimandres' | 'rose-pine-dawn' | 'rose-pine-moon' | 'rose-pine' | 'slack-dark' | 'slack-ochin' | 'solarized-dark' | 'solarized-light' | 'vitesse-dark' | 'vitesse-light';
4 declare const themes: Theme[];
5
6 declare enum FontStyle {
7 NotSet = -1,
8 None = 0,
9 Italic = 1,
10 Bold = 2,
11 Underline = 4
12 }
13
14 interface IThemedTokenScopeExplanation {
15 scopeName: string;
16 themeMatches: IRawThemeSetting[];
17 }
18 interface IThemedTokenExplanation {
19 content: string;
20 scopes: IThemedTokenScopeExplanation[];
21 }
22 /**
23 * A single token with color, and optionally with explanation.
24 *
25 * For example:
26 *
27 * {
28 * "content": "shiki",
29 * "color": "#D8DEE9",
30 * "explanation": [
31 * {
32 * "content": "shiki",
33 * "scopes": [
34 * {
35 * "scopeName": "source.js",
36 * "themeMatches": []
37 * },
38 * {
39 * "scopeName": "meta.objectliteral.js",
40 * "themeMatches": []
41 * },
42 * {
43 * "scopeName": "meta.object.member.js",
44 * "themeMatches": []
45 * },
46 * {
47 * "scopeName": "meta.array.literal.js",
48 * "themeMatches": []
49 * },
50 * {
51 * "scopeName": "variable.other.object.js",
52 * "themeMatches": [
53 * {
54 * "name": "Variable",
55 * "scope": "variable.other",
56 * "settings": {
57 * "foreground": "#D8DEE9"
58 * }
59 * },
60 * {
61 * "name": "[JavaScript] Variable Other Object",
62 * "scope": "source.js variable.other.object",
63 * "settings": {
64 * "foreground": "#D8DEE9"
65 * }
66 * }
67 * ]
68 * }
69 * ]
70 * }
71 * ]
72 * }
73 *
74 */
75 interface IThemedToken {
76 /**
77 * The content of the token
78 */
79 content: string;
80 /**
81 * 6 or 8 digit hex code representation of the token's color
82 */
83 color?: string;
84 /**
85 * Font style of token. Can be None/Italic/Bold/Underline
86 */
87 fontStyle?: FontStyle;
88 /**
89 * Explanation of
90 *
91 * - token text's matching scopes
92 * - reason that token text is given a color (one matching scope matches a rule (scope -> color) in the theme)
93 */
94 explanation?: IThemedTokenExplanation[];
95 }
96
97 interface HighlighterOptions {
98 /**
99 * The theme to load upfront.
100 */
101 theme?: IThemeRegistration;
102 /**
103 * A list of themes to load upfront.
104 *
105 * Default to: `['dark-plus', 'light-plus']`
106 */
107 themes?: IThemeRegistration[];
108 /**
109 * A list of languages to load upfront.
110 *
111 * Default to all the bundled languages.
112 */
113 langs?: (Lang | ILanguageRegistration)[];
114 /**
115 * Paths for loading themes and langs. Relative to the package's root.
116 */
117 paths?: IHighlighterPaths;
118 }
119 interface Highlighter {
120 /**
121 * Convert code to HTML tokens.
122 * `lang` and `theme` must have been loaded.
123 * @deprecated Please use the `codeToHtml(code, options?)` overload instead.
124 */
125 codeToHtml(code: string, lang?: StringLiteralUnion<Lang>, theme?: StringLiteralUnion<Theme>, options?: HtmlOptions): string;
126 /**
127 * Convert code to HTML tokens.
128 * `lang` and `theme` must have been loaded.
129 */
130 codeToHtml(code: string, options?: HtmlOptions): string;
131 /**
132 * Convert code to themed tokens for custom processing.
133 * `lang` and `theme` must have been loaded.
134 * You may customize the bundled HTML / SVG renderer or write your own
135 * renderer for another render target.
136 */
137 codeToThemedTokens(code: string, lang?: StringLiteralUnion<Lang>, theme?: StringLiteralUnion<Theme>, options?: ThemedTokenizerOptions): IThemedToken[][];
138 /**
139 * Get the loaded theme
140 */
141 getTheme(theme?: IThemeRegistration): IShikiTheme;
142 /**
143 * Load a theme
144 */
145 loadTheme(theme: IThemeRegistration): Promise<void>;
146 /**
147 * Load a language
148 */
149 loadLanguage(lang: ILanguageRegistration | Lang): Promise<void>;
150 /**
151 * Get all loaded themes
152 */
153 getLoadedThemes(): Theme[];
154 /**
155 * Get all loaded languages
156 */
157 getLoadedLanguages(): Lang[];
158 /**
159 * Get the foreground color for theme. Can be used for CSS `color`.
160 */
161 getForegroundColor(theme?: StringLiteralUnion<Theme>): string;
162 /**
163 * Get the background color for theme. Can be used for CSS `background-color`.
164 */
165 getBackgroundColor(theme?: StringLiteralUnion<Theme>): string;
166 setColorReplacements(map: Record<string, string>): void;
167 }
168 interface IHighlighterPaths {
169 /**
170 * @default 'themes/'
171 */
172 themes?: string;
173 /**
174 * @default 'languages/'
175 */
176 languages?: string;
177 }
178 declare type ILanguageRegistration = {
179 id: string;
180 scopeName: string;
181 aliases?: string[];
182 samplePath?: string;
183 /**
184 * A list of languages the current language embeds.
185 * If manually specifying languages to load, make sure to load the embedded
186 * languages for each parent language.
187 */
188 embeddedLangs?: Lang[];
189 } & ({
190 path: string;
191 grammar?: IRawGrammar;
192 } | {
193 path?: string;
194 grammar: IRawGrammar;
195 });
196 declare type IThemeRegistration = IShikiTheme | StringLiteralUnion<Theme>;
197 interface IShikiTheme extends IRawTheme {
198 /**
199 * @description theme name
200 */
201 name: string;
202 /**
203 * @description light/dark theme
204 */
205 type: 'light' | 'dark' | 'css';
206 /**
207 * @description tokenColors of the theme file
208 */
209 settings: IRawThemeSetting[];
210 /**
211 * @description text default foreground color
212 */
213 fg: string;
214 /**
215 * @description text default background color
216 */
217 bg: string;
218 /**
219 * @description relative path of included theme
220 */
221 include?: string;
222 /**
223 *
224 * @description color map of the theme file
225 */
226 colors?: Record<string, string>;
227 }
228 /**
229 * type StringLiteralUnion<'foo'> = 'foo' | string
230 * This has auto completion whereas `'foo' | string` doesn't
231 * Adapted from https://github.com/microsoft/TypeScript/issues/29729
232 */
233 declare type StringLiteralUnion<T extends U, U = string> = T | (U & {});
234 interface HtmlOptions {
235 lang?: StringLiteralUnion<Lang>;
236 theme?: StringLiteralUnion<Theme>;
237 lineOptions?: LineOption[];
238 }
239 interface HtmlRendererOptions {
240 langId?: string;
241 fg?: string;
242 bg?: string;
243 lineOptions?: LineOption[];
244 elements?: ElementsOptions;
245 }
246 interface LineOption {
247 /**
248 * 1-based line number.
249 */
250 line: number;
251 classes?: string[];
252 }
253 interface ElementProps {
254 children: string;
255 [key: string]: unknown;
256 }
257 interface PreElementProps extends ElementProps {
258 className: string;
259 style: string;
260 }
261 interface CodeElementProps extends ElementProps {
262 }
263 interface LineElementProps extends ElementProps {
264 className: string;
265 lines: IThemedToken[][];
266 line: IThemedToken[];
267 index: number;
268 }
269 interface TokenElementProps extends ElementProps {
270 style: string;
271 tokens: IThemedToken[];
272 token: IThemedToken;
273 index: number;
274 }
275 interface ElementsOptions {
276 pre?: (props: PreElementProps) => string;
277 code?: (props: CodeElementProps) => string;
278 line?: (props: LineElementProps) => string;
279 token?: (props: TokenElementProps) => string;
280 }
281 interface ThemedTokenizerOptions {
282 /**
283 * Whether to include explanation of each token's matching scopes and
284 * why it's given its color. Default to false to reduce output verbosity.
285 */
286 includeExplanation?: boolean;
287 }
288
289 declare type Lang = 'abap' | 'actionscript-3' | 'ada' | 'apache' | 'apex' | 'apl' | 'applescript' | 'asm' | 'astro' | 'awk' | 'ballerina' | 'bat' | 'batch' | 'berry' | 'be' | 'bibtex' | 'bicep' | 'blade' | 'c' | 'cadence' | 'cdc' | 'clarity' | 'clojure' | 'clj' | 'cmake' | 'cobol' | 'codeql' | 'ql' | 'coffee' | 'cpp' | 'crystal' | 'csharp' | 'c#' | 'css' | 'cue' | 'd' | 'dart' | 'diff' | 'docker' | 'dream-maker' | 'elixir' | 'elm' | 'erb' | 'erlang' | 'fish' | 'fsharp' | 'f#' | 'gherkin' | 'git-commit' | 'git-rebase' | 'glsl' | 'gnuplot' | 'go' | 'graphql' | 'groovy' | 'hack' | 'haml' | 'handlebars' | 'hbs' | 'haskell' | 'hcl' | 'hlsl' | 'html' | 'ini' | 'java' | 'javascript' | 'js' | 'jinja-html' | 'json' | 'jsonc' | 'jsonnet' | 'jssm' | 'fsl' | 'jsx' | 'julia' | 'kotlin' | 'latex' | 'less' | 'liquid' | 'lisp' | 'logo' | 'lua' | 'make' | 'makefile' | 'markdown' | 'md' | 'marko' | 'matlab' | 'mdx' | 'mermaid' | 'nginx' | 'nim' | 'nix' | 'objective-c' | 'objc' | 'objective-cpp' | 'ocaml' | 'pascal' | 'perl' | 'php' | 'plsql' | 'postcss' | 'powershell' | 'ps' | 'ps1' | 'prisma' | 'prolog' | 'pug' | 'jade' | 'puppet' | 'purescript' | 'python' | 'py' | 'r' | 'raku' | 'perl6' | 'razor' | 'rel' | 'riscv' | 'rst' | 'ruby' | 'rb' | 'rust' | 'rs' | 'sas' | 'sass' | 'scala' | 'scheme' | 'scss' | 'shaderlab' | 'shader' | 'shellscript' | 'shell' | 'bash' | 'sh' | 'zsh' | 'smalltalk' | 'solidity' | 'sparql' | 'sql' | 'ssh-config' | 'stata' | 'stylus' | 'styl' | 'svelte' | 'swift' | 'system-verilog' | 'tasl' | 'tcl' | 'tex' | 'toml' | 'tsx' | 'turtle' | 'twig' | 'typescript' | 'ts' | 'vb' | 'cmd' | 'verilog' | 'vhdl' | 'viml' | 'vim' | 'vimscript' | 'vue-html' | 'vue' | 'wasm' | 'wenyan' | '文言' | 'xml' | 'xsl' | 'yaml' | 'zenscript';
290 declare const languages: ILanguageRegistration[];
291
292 declare function getHighlighter(options: HighlighterOptions): Promise<Highlighter>;
293
294 declare function renderToHtml(lines: IThemedToken[][], options?: HtmlRendererOptions): string;
295
296 /**
297 * Set the route for loading the assets
298 * URL should end with `/`
299 *
300 * For example:
301 * ```ts
302 * setCDN('https://unpkg.com/shiki/') // use unpkg
303 * setCDN('/assets/shiki/') // serve by yourself
304 * ```
305 */
306 declare function setCDN(root: string): void;
307 /**
308 * Explicitly set the source for loading the oniguruma web assembly module.
309 *
310 * Accepts Url or ArrayBuffer
311 */
312 declare function setWasm(path: string | ArrayBuffer): void;
313 /**
314 * @param themePath related path to theme.json
315 */
316 declare function fetchTheme(themePath: string): Promise<IShikiTheme>;
317 declare function toShikiTheme(rawTheme: IRawTheme): IShikiTheme;
318
319 /** @deprecated use setWasm instead, will be removed in a future version */
320 declare function setOnigasmWASM(path: string | ArrayBuffer): void;
321
322 export { languages as BUNDLED_LANGUAGES, themes as BUNDLED_THEMES, FontStyle, Highlighter, HighlighterOptions, HtmlRendererOptions, ILanguageRegistration, IShikiTheme, IThemeRegistration, IThemedToken, Lang, Theme, getHighlighter, fetchTheme as loadTheme, renderToHtml, setCDN, setOnigasmWASM, setWasm, toShikiTheme };
323