vscode-shiki-bridge 0.0.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -5
- package/dist/index.cjs +736 -158
- package/dist/index.d.ts +78 -22
- package/dist/index.js +735 -158
- package/dist/internals.d.ts +156 -0
- package/dist/internals.js +682 -0
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# vscode-shiki-bridge
|
|
1
|
+
# `vscode-shiki-bridge`
|
|
2
2
|
|
|
3
3
|
🌉 Extracts the user's VS Code theme and language grammars for Shiki
|
|
4
4
|
|
|
@@ -40,13 +40,124 @@ const html = highlighter.codeToHtml(
|
|
|
40
40
|
|
|
41
41
|

|
|
42
42
|
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
### Themes
|
|
46
|
+
|
|
47
|
+
#### `UserThemeResult`
|
|
48
|
+
|
|
49
|
+
A tuple containing a theme id, and an array containing the `ThemeRegistration`.
|
|
50
|
+
|
|
51
|
+
If the theme cannot be found, [the special `"none"` theme](https://shiki.style/themes#special-themes) is returned.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
export type UserThemeResult = [id: string, themes: [ThemeRegistration]];
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### `getUserTheme`
|
|
58
|
+
|
|
59
|
+
Get a `UserThemeResult` for the currently active theme.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
async function getUserTheme(): Promise<UserThemeResult>;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### `getTheme`
|
|
66
|
+
|
|
67
|
+
Get a `UserThemeResult` for the given `themeName`. The `themeName` can be its `label` or `id`. VS Code themes will define at least on of these (usually the `label`), `vscode-shiki-bridge` will resolve it to the correct theme.
|
|
68
|
+
|
|
69
|
+
If the theme cannot be found, [the special `"none"` theme](https://shiki.style/themes#special-themes) is returned.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
async function getTheme(themeName: string): Promise<UserThemeResult>;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Languages
|
|
76
|
+
|
|
77
|
+
#### `LanguageRegistrationExtended`
|
|
78
|
+
|
|
79
|
+
The `LanguageRegistration` interface from `shiki` with the following VS Code specific properties preserved:
|
|
80
|
+
|
|
81
|
+
- `filenames`
|
|
82
|
+
- [`filenamePatterns`](https://code.visualstudio.com/docs/editor/glob-patterns)
|
|
83
|
+
- [`extensions`](https://code.visualstudio.com/docs/languages/overview#_add-a-file-extension-to-a-language)
|
|
84
|
+
- `mimetypes`
|
|
85
|
+
|
|
86
|
+
#### `getUserLangs`
|
|
87
|
+
|
|
88
|
+
Collect the `LanguageRegistrationExtended` objects for the languages supported by VS Code extensions. If `languageIds` is provided only those language ids will be collected.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
async function getUserLangs(languageIds?: string[]): Promise<LanguageRegistrationExtended[]>;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### `LanguagesResult`
|
|
95
|
+
|
|
96
|
+
The same result from `getUserLangs` but with some utility methods to resolve aliases and file extensions.
|
|
97
|
+
|
|
98
|
+
Also check the [`languages` namespace of the `vscode` api](https://code.visualstudio.com/api/references/vscode-api#languages) for how documents are resolved to its programming language.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
interface LanguagesResult {
|
|
102
|
+
langs: LanguageRegistrationExtended[];
|
|
103
|
+
/**
|
|
104
|
+
* Get the language registration for the given language id.
|
|
105
|
+
* Will resolve language id if it is an alias.
|
|
106
|
+
*
|
|
107
|
+
* Returns `undefined` if there is no language registration for the given language id.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const result = getUserLangs(['tsx']);
|
|
112
|
+
*
|
|
113
|
+
* const resolvedLanguageId = result.get('tsx');
|
|
114
|
+
* // ^? LanguageRegistration { name: 'typescriptreact', ... }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
get(languageId: string): LanguageRegistrationExtended | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* A helper function to resolve a possible alias to its language id.
|
|
120
|
+
* The language registrations always use the resolved alias as its `name` property.
|
|
121
|
+
* All its aliases can be found under the `aliases` property.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* const result = getUserLangs(['tsx']);
|
|
126
|
+
*
|
|
127
|
+
* const resolvedLanguageId = result.resolveAlias('tsx');
|
|
128
|
+
* // ^? 'typescriptreact'
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
resolveAlias(languageId: string): string;
|
|
132
|
+
/**
|
|
133
|
+
* A helper function to resolve an `.ext` extension to its language id.
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const result = getUserLangs(['handlebars']);
|
|
137
|
+
*
|
|
138
|
+
* const resolvedLanguageId = result.resolveExtension('.hbs');
|
|
139
|
+
* // ^? 'handlebars'
|
|
140
|
+
*/
|
|
141
|
+
resolveExtension(extension: string): string;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
### Examples
|
|
147
|
+
Check the [`example/`](./example/) directory for complete examples on how to use `vscode-shiki-bridge`.
|
|
148
|
+
To test the library, check out the repository and follow the instructions below
|
|
149
|
+
|
|
43
150
|
## Development and Debug
|
|
44
151
|
|
|
45
152
|
1. Open the project in VS Code / Cursor
|
|
46
|
-
2.
|
|
47
|
-
3.
|
|
48
|
-
4.
|
|
153
|
+
2. install dependencies with `npm i`
|
|
154
|
+
3. Press `F5` to start debugging (opens a new VS Code window with the example extension)
|
|
155
|
+
4. Run the "Shiki Preview" command from the Command Palette to see your highlighted code blocks
|
|
156
|
+
5. Make changes and reload the window to test
|
|
157
|
+
|
|
158
|
+
## Documentation
|
|
159
|
+
See the [`docs/`](./docs/) directory for documentation on how this library bridges the gap from [VS Code Highlighting](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide) to Shikis [Custom Themes](https://shiki.style/guide/load-theme) and [Custom Languages](https://shiki.style/guide/load-lang).
|
|
49
160
|
|
|
50
161
|
## License
|
|
51
162
|
|
|
52
|
-
MIT
|
|
163
|
+
[MIT](./LICENSE)
|