@shikijs/twoslash 2.4.2 → 3.0.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/dist/core.mjs +4 -1
- package/dist/index.mjs +6 -1
- package/package.json +6 -23
- package/dist/core.d.ts +0 -289
- package/dist/index.d.ts +0 -20
package/dist/core.mjs
CHANGED
|
@@ -1077,7 +1077,10 @@ function getErrorLevelClass(error) {
|
|
|
1077
1077
|
|
|
1078
1078
|
function defaultTwoslashOptions() {
|
|
1079
1079
|
return {
|
|
1080
|
-
customTags: ["annotate", "log", "warn", "error"]
|
|
1080
|
+
customTags: ["annotate", "log", "warn", "error"],
|
|
1081
|
+
compilerOptions: {
|
|
1082
|
+
moduleResolution: 100
|
|
1083
|
+
}
|
|
1081
1084
|
};
|
|
1082
1085
|
}
|
|
1083
1086
|
function createTransformerFactory(defaultTwoslasher, defaultRenderer) {
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,12 @@ import '@shikijs/core';
|
|
|
5
5
|
|
|
6
6
|
function transformerTwoslash(options = {}) {
|
|
7
7
|
return createTransformerFactory(
|
|
8
|
-
createTwoslasher({
|
|
8
|
+
createTwoslasher({
|
|
9
|
+
cache: options?.cache,
|
|
10
|
+
compilerOptions: {
|
|
11
|
+
moduleResolution: 100
|
|
12
|
+
}
|
|
13
|
+
}),
|
|
9
14
|
rendererRich(options.rendererRich)
|
|
10
15
|
)(options);
|
|
11
16
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/twoslash",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"description": "Shiki transformer for twoslash",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -18,14 +18,8 @@
|
|
|
18
18
|
],
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"exports": {
|
|
21
|
-
".":
|
|
22
|
-
|
|
23
|
-
"default": "./dist/index.mjs"
|
|
24
|
-
},
|
|
25
|
-
"./core": {
|
|
26
|
-
"types": "./dist/core.d.mts",
|
|
27
|
-
"default": "./dist/core.mjs"
|
|
28
|
-
},
|
|
21
|
+
".": "./dist/index.mjs",
|
|
22
|
+
"./core": "./dist/core.mjs",
|
|
29
23
|
"./style-rich.css": "./style-rich.css",
|
|
30
24
|
"./style-classic.css": "./style-classic.css",
|
|
31
25
|
"./*": "./dist/*"
|
|
@@ -33,32 +27,21 @@
|
|
|
33
27
|
"main": "./dist/index.mjs",
|
|
34
28
|
"module": "./dist/index.mjs",
|
|
35
29
|
"types": "./dist/index.d.mts",
|
|
36
|
-
"typesVersions": {
|
|
37
|
-
"*": {
|
|
38
|
-
"./core": [
|
|
39
|
-
"./dist/core.d.mts"
|
|
40
|
-
],
|
|
41
|
-
"*": [
|
|
42
|
-
"./dist/*",
|
|
43
|
-
"./*"
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
30
|
"files": [
|
|
48
31
|
"*.css",
|
|
49
32
|
"dist"
|
|
50
33
|
],
|
|
51
34
|
"dependencies": {
|
|
52
35
|
"twoslash": "^0.2.12",
|
|
53
|
-
"@shikijs/core": "
|
|
54
|
-
"@shikijs/types": "
|
|
36
|
+
"@shikijs/core": "3.0.0",
|
|
37
|
+
"@shikijs/types": "3.0.0"
|
|
55
38
|
},
|
|
56
39
|
"devDependencies": {
|
|
57
40
|
"@iconify-json/carbon": "^1.2.7",
|
|
58
41
|
"@iconify-json/codicon": "^1.2.10",
|
|
59
42
|
"hast-util-from-html": "^2.0.3",
|
|
60
43
|
"typescript": "^5.7.3",
|
|
61
|
-
"@shikijs/twoslash": "
|
|
44
|
+
"@shikijs/twoslash": "3.0.0"
|
|
62
45
|
},
|
|
63
46
|
"scripts": {
|
|
64
47
|
"build": "unbuild",
|
package/dist/core.d.ts
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { CodeToHastOptions, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformer } from '@shikijs/types';
|
|
2
|
-
import { TwoslashReturn, TwoslashExecuteOptions, TwoslashGenericFunction, TwoslashOptions, NodeError, NodeTag, NodeQuery, NodeCompletion, NodeHover, NodeHighlight } from 'twoslash';
|
|
3
|
-
import { ElementContent, Element, Text } from 'hast';
|
|
4
|
-
|
|
5
|
-
type TwoslashShikiReturn = Pick<TwoslashReturn, 'nodes' | 'code'> & {
|
|
6
|
-
meta?: Partial<Pick<TwoslashReturn['meta'], 'extension'>>;
|
|
7
|
-
};
|
|
8
|
-
type TwoslashShikiFunction = (code: string, lang?: string, options?: TwoslashExecuteOptions) => TwoslashShikiReturn;
|
|
9
|
-
declare module '@shikijs/core' {
|
|
10
|
-
interface ShikiTransformerContextMeta {
|
|
11
|
-
twoslash?: TwoslashShikiReturn;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
interface TransformerTwoslashOptions {
|
|
15
|
-
/**
|
|
16
|
-
* Languages to apply this transformer to
|
|
17
|
-
*/
|
|
18
|
-
langs?: string[];
|
|
19
|
-
/**
|
|
20
|
-
* Requires `twoslash` to be presented in the code block meta to apply this transformer
|
|
21
|
-
*
|
|
22
|
-
* @default false
|
|
23
|
-
*/
|
|
24
|
-
explicitTrigger?: boolean | RegExp;
|
|
25
|
-
/**
|
|
26
|
-
* Triggers that skip Twoslash transformation on the code block meta
|
|
27
|
-
*
|
|
28
|
-
* @default ['notwoslash', 'no-twoslash']
|
|
29
|
-
*/
|
|
30
|
-
disableTriggers?: (string | RegExp)[];
|
|
31
|
-
/**
|
|
32
|
-
* Mapping from language alias to language name
|
|
33
|
-
*/
|
|
34
|
-
langAlias?: Record<string, string>;
|
|
35
|
-
/**
|
|
36
|
-
* Custom filter function to apply this transformer to
|
|
37
|
-
* When specified, `langs`, `explicitTrigger`, and `disableTriggers` will be ignored
|
|
38
|
-
*/
|
|
39
|
-
filter?: (lang: string, code: string, options: CodeToHastOptions) => boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Custom instance of twoslasher function
|
|
42
|
-
*/
|
|
43
|
-
twoslasher?: TwoslashShikiFunction | TwoslashGenericFunction;
|
|
44
|
-
/**
|
|
45
|
-
* Options to pass to twoslash
|
|
46
|
-
*/
|
|
47
|
-
twoslashOptions?: TwoslashOptions;
|
|
48
|
-
/**
|
|
49
|
-
* Custom renderers to decide how each info should be rendered
|
|
50
|
-
*/
|
|
51
|
-
renderer?: TwoslashRenderer;
|
|
52
|
-
/**
|
|
53
|
-
* A map to store code for `@include` directive
|
|
54
|
-
* Provide your own instance if you want to clear the map between each transformation
|
|
55
|
-
*/
|
|
56
|
-
includesMap?: Map<string, string>;
|
|
57
|
-
/**
|
|
58
|
-
* Strictly throw when there is an error
|
|
59
|
-
* @default true
|
|
60
|
-
*/
|
|
61
|
-
throws?: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Custom error handler for twoslash errors
|
|
64
|
-
* When specified, `throws` will be ignored
|
|
65
|
-
* Optionally return a string to replace the code
|
|
66
|
-
*/
|
|
67
|
-
onTwoslashError?: (error: unknown, code: string, lang: string, options: CodeToHastOptions) => string | void;
|
|
68
|
-
/**
|
|
69
|
-
* Custom error handler for Shiki errors
|
|
70
|
-
* When specified, `throws` will be ignored
|
|
71
|
-
*/
|
|
72
|
-
onShikiError?: (error: unknown, code: string, lang: string) => void;
|
|
73
|
-
}
|
|
74
|
-
interface TwoslashRenderer {
|
|
75
|
-
lineError?: (this: ShikiTransformerContext, error: NodeError) => ElementContent[];
|
|
76
|
-
lineCustomTag?: (this: ShikiTransformerContext, tag: NodeTag) => ElementContent[];
|
|
77
|
-
lineQuery?: (this: ShikiTransformerContext, query: NodeQuery, targetNode?: Element | Text) => ElementContent[];
|
|
78
|
-
lineCompletion?: (this: ShikiTransformerContext, query: NodeCompletion) => ElementContent[];
|
|
79
|
-
nodeStaticInfo: (this: ShikiTransformerContext, info: NodeHover, node: Element | Text) => Partial<ElementContent>;
|
|
80
|
-
nodeError?: (this: ShikiTransformerContext, error: NodeError, node: Element | Text) => Partial<ElementContent>;
|
|
81
|
-
nodeQuery?: (this: ShikiTransformerContext, query: NodeQuery, node: Element | Text) => Partial<ElementContent>;
|
|
82
|
-
nodeCompletion?: (this: ShikiTransformerContext, query: NodeCompletion, node: Element | Text) => Partial<ElementContent>;
|
|
83
|
-
nodesError?: (this: ShikiTransformerContext, error: NodeError, nodes: ElementContent[]) => ElementContent[];
|
|
84
|
-
nodesHighlight?: (this: ShikiTransformerContext, highlight: NodeHighlight, nodes: ElementContent[]) => ElementContent[];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
declare class ShikiTwoslashError extends Error {
|
|
88
|
-
constructor(message: string);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
type CompletionItem = NonNullable<NodeCompletion['completions']>[number];
|
|
92
|
-
declare const defaultCompletionIcons: Record<string, Element | undefined>;
|
|
93
|
-
declare const defaultCustomTagIcons: Record<string, Element | undefined>;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The default renderer aligning with the original `@shikijs/twoslash` output.
|
|
97
|
-
*/
|
|
98
|
-
declare function rendererClassic(): TwoslashRenderer;
|
|
99
|
-
|
|
100
|
-
interface RendererRichOptions {
|
|
101
|
-
/**
|
|
102
|
-
* Render JSDoc comments in hover popup.
|
|
103
|
-
*
|
|
104
|
-
* @default true
|
|
105
|
-
*/
|
|
106
|
-
jsdoc?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Custom icons for completion items.
|
|
109
|
-
* A map from completion item kind to a HAST node.
|
|
110
|
-
*
|
|
111
|
-
* If `false`, no icons will be rendered.
|
|
112
|
-
* @default defaultCompletionIcons
|
|
113
|
-
*/
|
|
114
|
-
completionIcons?: Partial<Record<string, ElementContent>> | false;
|
|
115
|
-
/**
|
|
116
|
-
* Custom icons for custom tags lines.
|
|
117
|
-
* A map from tag name to a HAST node.
|
|
118
|
-
*
|
|
119
|
-
* If `false`, no icons will be rendered.
|
|
120
|
-
* @default defaultCustomTagIcons
|
|
121
|
-
*/
|
|
122
|
-
customTagIcons?: Partial<Record<string, ElementContent>> | false;
|
|
123
|
-
/**
|
|
124
|
-
* Custom formatter for the type info text.
|
|
125
|
-
* Note that it might not be valid TypeScript syntax.
|
|
126
|
-
*
|
|
127
|
-
* @default defaultHoverInfoProcessor
|
|
128
|
-
*/
|
|
129
|
-
processHoverInfo?: (info: string) => string;
|
|
130
|
-
/**
|
|
131
|
-
* Custom formatter for the docs text (can be markdown).
|
|
132
|
-
*
|
|
133
|
-
* @default undefined
|
|
134
|
-
*/
|
|
135
|
-
processHoverDocs?: (docs: string) => string;
|
|
136
|
-
/**
|
|
137
|
-
* The way errors should be rendered.
|
|
138
|
-
*
|
|
139
|
-
* - `'line'`: Render the error line after the line of code
|
|
140
|
-
* - `'hover'`: Render the error in the hover popup
|
|
141
|
-
*
|
|
142
|
-
* @default 'line'
|
|
143
|
-
*/
|
|
144
|
-
errorRendering?: 'line' | 'hover';
|
|
145
|
-
/**
|
|
146
|
-
* Classes added to injected elements
|
|
147
|
-
*/
|
|
148
|
-
classExtra?: string;
|
|
149
|
-
/**
|
|
150
|
-
* Language for syntax highlight.
|
|
151
|
-
* @default the language of the code block
|
|
152
|
-
*/
|
|
153
|
-
lang?: string;
|
|
154
|
-
/**
|
|
155
|
-
* Custom function to render markdown.
|
|
156
|
-
*
|
|
157
|
-
* By default it pass-through the markdown.
|
|
158
|
-
*/
|
|
159
|
-
renderMarkdown?: (this: ShikiTransformerContextCommon, markdown: string) => ElementContent[];
|
|
160
|
-
/**
|
|
161
|
-
* Custom function to render inline markdown.
|
|
162
|
-
*
|
|
163
|
-
* By default it pass-through the markdown.
|
|
164
|
-
*/
|
|
165
|
-
renderMarkdownInline?: (this: ShikiTransformerContextCommon, markdown: string, context: string) => ElementContent[];
|
|
166
|
-
/**
|
|
167
|
-
* The way query should be rendered.
|
|
168
|
-
* - `'popup'`: Render the query in the absolute popup
|
|
169
|
-
* - `'line'`: Render the query line after the line of code
|
|
170
|
-
* @default 'popup'
|
|
171
|
-
*/
|
|
172
|
-
queryRendering?: 'popup' | 'line';
|
|
173
|
-
/**
|
|
174
|
-
* Extensions for the genreated HAST tree.
|
|
175
|
-
*/
|
|
176
|
-
hast?: {
|
|
177
|
-
/**
|
|
178
|
-
* The <code> block for in the hover popup.
|
|
179
|
-
*/
|
|
180
|
-
popupTypes?: HastExtension;
|
|
181
|
-
/**
|
|
182
|
-
* The documentation block in the hover popup. Can be markdown rendered if `renderMarkdown` is provided.
|
|
183
|
-
*/
|
|
184
|
-
popupDocs?: HastExtension;
|
|
185
|
-
/**
|
|
186
|
-
* The container of jsdoc tags in the hover popup.
|
|
187
|
-
*/
|
|
188
|
-
popupDocsTags?: HastExtension;
|
|
189
|
-
/**
|
|
190
|
-
* The token for the hover informaton.
|
|
191
|
-
*/
|
|
192
|
-
hoverToken?: HastExtension;
|
|
193
|
-
/**
|
|
194
|
-
* The container of the hover popup.
|
|
195
|
-
*/
|
|
196
|
-
hoverPopup?: HastExtension;
|
|
197
|
-
/**
|
|
198
|
-
* The container of error popup.
|
|
199
|
-
*/
|
|
200
|
-
popupError?: HastExtension;
|
|
201
|
-
/**
|
|
202
|
-
* Custom function to compose the hover token.
|
|
203
|
-
*/
|
|
204
|
-
hoverCompose?: (parts: {
|
|
205
|
-
popup: Element;
|
|
206
|
-
token: Text | Element;
|
|
207
|
-
}) => ElementContent[];
|
|
208
|
-
/**
|
|
209
|
-
* The token for the query informaton.
|
|
210
|
-
*/
|
|
211
|
-
queryToken?: HastExtension;
|
|
212
|
-
/**
|
|
213
|
-
* The container of the query popup.
|
|
214
|
-
*/
|
|
215
|
-
queryPopup?: HastExtension;
|
|
216
|
-
/**
|
|
217
|
-
* Custom function to compose the hover token.
|
|
218
|
-
*/
|
|
219
|
-
queryCompose?: (parts: {
|
|
220
|
-
popup: Element;
|
|
221
|
-
token: Text | Element;
|
|
222
|
-
}) => ElementContent[];
|
|
223
|
-
/**
|
|
224
|
-
* The token for the completion informaton.
|
|
225
|
-
*/
|
|
226
|
-
completionToken?: HastExtension;
|
|
227
|
-
/**
|
|
228
|
-
* The cursor element in the completion popup.
|
|
229
|
-
*/
|
|
230
|
-
completionCursor?: HastExtension;
|
|
231
|
-
/**
|
|
232
|
-
* The container of the completion popup.
|
|
233
|
-
*/
|
|
234
|
-
completionPopup?: HastExtension;
|
|
235
|
-
/**
|
|
236
|
-
* Custom function to compose the completion token.
|
|
237
|
-
*/
|
|
238
|
-
completionCompose?: (parts: {
|
|
239
|
-
popup: Element;
|
|
240
|
-
cursor: Element;
|
|
241
|
-
}) => ElementContent[];
|
|
242
|
-
/**
|
|
243
|
-
* The token for the error informaton.
|
|
244
|
-
*/
|
|
245
|
-
errorToken?: HastExtension;
|
|
246
|
-
/**
|
|
247
|
-
* The container of the error popup.
|
|
248
|
-
* Only used when `errorRendering` is set to `'hover'`.
|
|
249
|
-
*/
|
|
250
|
-
errorPopup?: HastExtension;
|
|
251
|
-
/**
|
|
252
|
-
* Custom function to compose the error token.
|
|
253
|
-
* Only used when `errorRendering` is set to `'hover'`.
|
|
254
|
-
*/
|
|
255
|
-
errorCompose?: (parts: {
|
|
256
|
-
popup: Element;
|
|
257
|
-
token: Text | Element;
|
|
258
|
-
}) => ElementContent[];
|
|
259
|
-
/**
|
|
260
|
-
* The wrapper for the highlighted nodes.
|
|
261
|
-
*/
|
|
262
|
-
nodesHighlight?: HastExtension;
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
interface HastExtension {
|
|
266
|
-
tagName?: string;
|
|
267
|
-
properties?: Element['properties'];
|
|
268
|
-
class?: string;
|
|
269
|
-
children?: (input: ElementContent[]) => ElementContent[];
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* An alternative renderer that providers better prefixed class names,
|
|
273
|
-
* with syntax highlight for the info text.
|
|
274
|
-
*/
|
|
275
|
-
declare function rendererRich(options?: RendererRichOptions): TwoslashRenderer;
|
|
276
|
-
/**
|
|
277
|
-
* The default hover info processor, which will do some basic cleanup
|
|
278
|
-
*/
|
|
279
|
-
declare function defaultHoverInfoProcessor(type: string): string;
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* This file is the core of the @shikijs/twoslash package,
|
|
283
|
-
* Decoupled from twoslash's implementation and allowing to introduce custom implementation or cache system.
|
|
284
|
-
*/
|
|
285
|
-
|
|
286
|
-
declare function defaultTwoslashOptions(): TwoslashExecuteOptions;
|
|
287
|
-
declare function createTransformerFactory(defaultTwoslasher: TwoslashShikiFunction | TwoslashGenericFunction, defaultRenderer?: TwoslashRenderer): (options?: TransformerTwoslashOptions) => ShikiTransformer;
|
|
288
|
-
|
|
289
|
-
export { type CompletionItem, type HastExtension, type RendererRichOptions, ShikiTwoslashError, type TransformerTwoslashOptions, type TwoslashRenderer, type TwoslashShikiFunction, type TwoslashShikiReturn, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich };
|
package/dist/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ShikiTransformer } from '@shikijs/types';
|
|
2
|
-
import { CreateTwoslashOptions } from 'twoslash';
|
|
3
|
-
import { TransformerTwoslashOptions, RendererRichOptions } from './core.js';
|
|
4
|
-
export { CompletionItem, HastExtension, ShikiTwoslashError, TwoslashRenderer, TwoslashShikiFunction, TwoslashShikiReturn, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich } from './core.js';
|
|
5
|
-
import 'hast';
|
|
6
|
-
|
|
7
|
-
interface TransformerTwoslashIndexOptions extends TransformerTwoslashOptions, Pick<CreateTwoslashOptions, 'cache'> {
|
|
8
|
-
/**
|
|
9
|
-
* Options for the default rich renderer.
|
|
10
|
-
*
|
|
11
|
-
* Available when no custom renderer is provided.
|
|
12
|
-
*/
|
|
13
|
-
rendererRich?: RendererRichOptions;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Factory function to create a Shiki transformer for twoslash integrations.
|
|
17
|
-
*/
|
|
18
|
-
declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions): ShikiTransformer;
|
|
19
|
-
|
|
20
|
-
export { RendererRichOptions, type TransformerTwoslashIndexOptions, TransformerTwoslashOptions, transformerTwoslash };
|