| 1 |
import { IGrammar, IRawTheme } from 'vscode-textmate'; |
| 2 |
|
| 3 |
type Theme = 'css-variables' | 'dark-plus' | 'dracula-soft' | 'dracula' | 'github-dark-dimmed' | 'github-dark' | 'github-light' | 'light-plus' | 'material-theme-darker' | 'material-theme-lighter' | 'material-theme-ocean' | 'material-theme-palenight' | 'material-theme' | '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-black' | '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: any[]; |
| 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 |
* Default to: 'nord' |
| 102 |
*/ |
| 103 |
theme?: IThemeRegistration; |
| 104 |
/** |
| 105 |
* A list of themes to load upfront. |
| 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?: CodeToHtmlOptions): string; |
| 126 |
/** |
| 127 |
* Convert code to HTML tokens. |
| 128 |
* `lang` and `theme` must have been loaded. |
| 129 |
*/ |
| 130 |
codeToHtml(code: string, options?: CodeToHtmlOptions): 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 |
* Convert ansi-escaped text to HTML tokens. |
| 140 |
* `theme` must have been loaded. |
| 141 |
*/ |
| 142 |
ansiToHtml(ansi: string, options?: AnsiToHtmlOptions): string; |
| 143 |
/** |
| 144 |
* Convert ansi-escaped text to themed tokens for custom processing. |
| 145 |
* `theme` must have been loaded. |
| 146 |
* You may customize the bundled HTML / SVG renderer or write your own |
| 147 |
* renderer for another render target. |
| 148 |
*/ |
| 149 |
ansiToThemedTokens(ansi: string, theme?: StringLiteralUnion<Theme>): IThemedToken[][]; |
| 150 |
/** |
| 151 |
* Get the loaded theme |
| 152 |
*/ |
| 153 |
getTheme(theme?: IThemeRegistration): IShikiTheme; |
| 154 |
/** |
| 155 |
* Load a theme |
| 156 |
*/ |
| 157 |
loadTheme(theme: IThemeRegistration): Promise<void>; |
| 158 |
/** |
| 159 |
* Load a language |
| 160 |
*/ |
| 161 |
loadLanguage(lang: ILanguageRegistration | Lang): Promise<void>; |
| 162 |
/** |
| 163 |
* Get all loaded themes |
| 164 |
*/ |
| 165 |
getLoadedThemes(): Theme[]; |
| 166 |
/** |
| 167 |
* Get all loaded languages |
| 168 |
*/ |
| 169 |
getLoadedLanguages(): Lang[]; |
| 170 |
/** |
| 171 |
* Get the foreground color for theme. Can be used for CSS `color`. |
| 172 |
*/ |
| 173 |
getForegroundColor(theme?: StringLiteralUnion<Theme>): string; |
| 174 |
/** |
| 175 |
* Get the background color for theme. Can be used for CSS `background-color`. |
| 176 |
*/ |
| 177 |
getBackgroundColor(theme?: StringLiteralUnion<Theme>): string; |
| 178 |
setColorReplacements(map: Record<string, string>): void; |
| 179 |
} |
| 180 |
interface IHighlighterPaths { |
| 181 |
/** |
| 182 |
* @default 'themes/' |
| 183 |
*/ |
| 184 |
themes?: string; |
| 185 |
/** |
| 186 |
* @default 'languages/' |
| 187 |
*/ |
| 188 |
languages?: string; |
| 189 |
/** |
| 190 |
* @default 'dist/' |
| 191 |
*/ |
| 192 |
wasm?: string; |
| 193 |
} |
| 194 |
type ILanguageRegistration = { |
| 195 |
id: string; |
| 196 |
scopeName: string; |
| 197 |
displayName?: string; |
| 198 |
aliases?: string[]; |
| 199 |
samplePath?: string; |
| 200 |
/** |
| 201 |
* A list of languages the current language embeds. |
| 202 |
* If manually specifying languages to load, make sure to load the embedded |
| 203 |
* languages for each parent language. |
| 204 |
*/ |
| 205 |
embeddedLangs?: Lang[]; |
| 206 |
balancedBracketSelectors?: string[]; |
| 207 |
unbalancedBracketSelectors?: string[]; |
| 208 |
} & { |
| 209 |
path: string; |
| 210 |
grammar?: IGrammar; |
| 211 |
}; |
| 212 |
type IThemeRegistration = IShikiTheme | StringLiteralUnion<Theme>; |
| 213 |
interface IShikiTheme extends IRawTheme { |
| 214 |
/** |
| 215 |
* @description theme name |
| 216 |
*/ |
| 217 |
name: string; |
| 218 |
/** |
| 219 |
* @description light/dark theme |
| 220 |
*/ |
| 221 |
type: 'light' | 'dark' | 'css'; |
| 222 |
/** |
| 223 |
* @description tokenColors of the theme file |
| 224 |
*/ |
| 225 |
settings: any[]; |
| 226 |
/** |
| 227 |
* @description text default foreground color |
| 228 |
*/ |
| 229 |
fg: string; |
| 230 |
/** |
| 231 |
* @description text default background color |
| 232 |
*/ |
| 233 |
bg: string; |
| 234 |
/** |
| 235 |
* @description relative path of included theme |
| 236 |
*/ |
| 237 |
include?: string; |
| 238 |
/** |
| 239 |
* |
| 240 |
* @description color map of the theme file |
| 241 |
*/ |
| 242 |
colors?: Record<string, string>; |
| 243 |
} |
| 244 |
interface Nothing { |
| 245 |
} |
| 246 |
/** |
| 247 |
* type StringLiteralUnion<'foo'> = 'foo' | string |
| 248 |
* This has auto completion whereas `'foo' | string` doesn't |
| 249 |
* Adapted from https://github.com/microsoft/TypeScript/issues/29729 |
| 250 |
*/ |
| 251 |
type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing); |
| 252 |
interface CodeToHtmlOptions { |
| 253 |
lang?: StringLiteralUnion<Lang>; |
| 254 |
theme?: StringLiteralUnion<Theme>; |
| 255 |
lineOptions?: LineOption[]; |
| 256 |
} |
| 257 |
interface AnsiToHtmlOptions { |
| 258 |
theme?: StringLiteralUnion<Theme>; |
| 259 |
lineOptions?: LineOption[]; |
| 260 |
} |
| 261 |
interface HtmlRendererOptions { |
| 262 |
langId?: string; |
| 263 |
fg?: string; |
| 264 |
bg?: string; |
| 265 |
lineOptions?: LineOption[]; |
| 266 |
elements?: ElementsOptions; |
| 267 |
themeName?: string; |
| 268 |
} |
| 269 |
interface LineOption { |
| 270 |
/** |
| 271 |
* 1-based line number. |
| 272 |
*/ |
| 273 |
line: number; |
| 274 |
classes?: string[]; |
| 275 |
} |
| 276 |
interface ElementProps { |
| 277 |
children: string; |
| 278 |
[key: string]: unknown; |
| 279 |
} |
| 280 |
interface PreElementProps extends ElementProps { |
| 281 |
className: string; |
| 282 |
style: string; |
| 283 |
} |
| 284 |
interface CodeElementProps extends ElementProps { |
| 285 |
} |
| 286 |
interface LineElementProps extends ElementProps { |
| 287 |
className: string; |
| 288 |
lines: IThemedToken[][]; |
| 289 |
line: IThemedToken[]; |
| 290 |
index: number; |
| 291 |
} |
| 292 |
interface TokenElementProps extends ElementProps { |
| 293 |
style: string; |
| 294 |
tokens: IThemedToken[]; |
| 295 |
token: IThemedToken; |
| 296 |
index: number; |
| 297 |
} |
| 298 |
interface ElementsOptions { |
| 299 |
pre?: (props: PreElementProps) => string; |
| 300 |
code?: (props: CodeElementProps) => string; |
| 301 |
line?: (props: LineElementProps) => string; |
| 302 |
token?: (props: TokenElementProps) => string; |
| 303 |
} |
| 304 |
interface ThemedTokenizerOptions { |
| 305 |
/** |
| 306 |
* Whether to include explanation of each token's matching scopes and |
| 307 |
* why it's given its color. Default to false to reduce output verbosity. |
| 308 |
*/ |
| 309 |
includeExplanation?: boolean; |
| 310 |
} |
| 311 |
|
| 312 |
type Lang = 'abap' | 'actionscript-3' | 'ada' | 'apache' | 'apex' | 'apl' | 'applescript' | 'ara' | 'asm' | 'astro' | 'awk' | 'ballerina' | 'bat' | 'batch' | 'beancount' | 'berry' | 'be' | 'bibtex' | 'bicep' | 'blade' | 'c' | 'cadence' | 'cdc' | 'clarity' | 'clojure' | 'clj' | 'cmake' | 'cobol' | 'codeql' | 'ql' | 'coffee' | 'cpp' | 'c++' | 'crystal' | 'csharp' | 'c#' | 'cs' | 'css' | 'csv' | 'cue' | 'cypher' | 'cql' | 'd' | 'dart' | 'dax' | 'diff' | 'docker' | 'dockerfile' | 'dream-maker' | 'elixir' | 'elm' | 'erb' | 'erlang' | 'erl' | 'fish' | 'fsharp' | 'f#' | 'fs' | 'gdresource' | 'gdscript' | 'gdshader' | 'gherkin' | 'git-commit' | 'git-rebase' | 'glimmer-js' | 'gjs' | 'glimmer-ts' | 'gts' | 'glsl' | 'gnuplot' | 'go' | 'graphql' | 'gql' | 'groovy' | 'hack' | 'haml' | 'handlebars' | 'hbs' | 'haskell' | 'hs' | 'hcl' | 'hjson' | 'hlsl' | 'html' | 'http' | 'imba' | 'ini' | 'properties' | 'java' | 'javascript' | 'js' | 'jinja-html' | 'jison' | 'json' | 'json5' | 'jsonc' | 'jsonl' | 'jsonnet' | 'jssm' | 'fsl' | 'jsx' | 'julia' | 'kotlin' | 'kt' | 'kts' | 'kusto' | 'kql' | 'latex' | 'less' | 'liquid' | 'lisp' | 'logo' | 'lua' | 'make' | 'makefile' | 'markdown' | 'md' | 'marko' | 'matlab' | 'mdc' | 'mdx' | 'mermaid' | 'mojo' | 'narrat' | 'nar' | 'nextflow' | 'nf' | 'nginx' | 'nim' | 'nix' | 'nushell' | 'nu' | 'objective-c' | 'objc' | 'objective-cpp' | 'ocaml' | 'pascal' | 'perl' | 'php' | 'plsql' | 'postcss' | 'powerquery' | 'powershell' | 'ps' | 'ps1' | 'prisma' | 'prolog' | 'proto' | 'pug' | 'jade' | 'puppet' | 'purescript' | 'python' | 'py' | 'r' | 'raku' | 'perl6' | 'razor' | 'reg' | 'rel' | 'riscv' | 'rst' | 'ruby' | 'rb' | 'rust' | 'rs' | 'sas' | 'sass' | 'scala' | 'scheme' | 'scss' | 'shaderlab' | 'shader' | 'shellscript' | 'bash' | 'sh' | 'shell' | 'zsh' | 'shellsession' | 'console' | 'smalltalk' | 'solidity' | 'sparql' | 'splunk' | 'spl' | 'sql' | 'ssh-config' | 'stata' | 'stylus' | 'styl' | 'svelte' | 'swift' | 'system-verilog' | 'tasl' | 'tcl' | 'tex' | 'toml' | 'tsx' | 'turtle' | 'twig' | 'typescript' | 'ts' | 'v' | 'vb' | 'cmd' | 'verilog' | 'vhdl' | 'viml' | 'vim' | 'vimscript' | 'vue-html' | 'vue' | 'vyper' | 'vy' | 'wasm' | 'wenyan' | '文言' | 'wgsl' | 'wolfram' | 'wl' | 'xml' | 'xsl' | 'yaml' | 'yml' | 'zenscript' | 'zig'; |
| 313 |
declare const languages: ILanguageRegistration[]; |
| 314 |
|
| 315 |
declare function getHighlighter(options: HighlighterOptions): Promise<Highlighter>; |
| 316 |
|
| 317 |
declare function renderToHtml(lines: IThemedToken[][], options?: HtmlRendererOptions): string; |
| 318 |
|
| 319 |
declare global { |
| 320 |
interface Response { |
| 321 |
json(): Promise<any>; |
| 322 |
text(): Promise<any>; |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
/** |
| 327 |
* Set the route for loading the assets |
| 328 |
* URL should end with `/` |
| 329 |
* |
| 330 |
* For example: |
| 331 |
* ```ts |
| 332 |
* setCDN('https://unpkg.com/shiki/') // use unpkg |
| 333 |
* setCDN('/assets/shiki/') // serve by yourself |
| 334 |
* ``` |
| 335 |
*/ |
| 336 |
declare function setCDN(root: string): void; |
| 337 |
/** |
| 338 |
* Explicitly set the source for loading the oniguruma web assembly module. |
| 339 |
* * |
| 340 |
* Accepts ArrayBuffer or Response (usage of string is deprecated) |
| 341 |
*/ |
| 342 |
declare function setWasm(data: string | ArrayBuffer | Response): void; |
| 343 |
/** |
| 344 |
* @param themePath related path to theme.json |
| 345 |
*/ |
| 346 |
declare function fetchTheme(themePath: string): Promise<IShikiTheme>; |
| 347 |
declare function toShikiTheme(rawTheme: IRawTheme): IShikiTheme; |
| 348 |
|
| 349 |
/** @deprecated use setWasm instead, will be removed in a future version */ |
| 350 |
declare function setOnigasmWASM(path: string | ArrayBuffer): void; |
| 351 |
|
| 352 |
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 }; |
| 353 |
|