@shikijs/transformers 3.23.0 → 4.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/index.d.mts +173 -158
- package/dist/index.mjs +653 -745
- package/package.json +8 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,254 +1,269 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Element } from
|
|
3
|
-
import { ShikiTransformer as ShikiTransformer$1 } from
|
|
1
|
+
import { ShikiTransformer, ShikiTransformerContext } from "@shikijs/core";
|
|
2
|
+
import { Element } from "hast";
|
|
3
|
+
import { ShikiTransformer as ShikiTransformer$1 } from "@shikijs/types";
|
|
4
4
|
|
|
5
|
+
//#region src/shared/notation-transformer.d.ts
|
|
5
6
|
type MatchAlgorithm = 'v1' | 'v3';
|
|
6
7
|
interface MatchAlgorithmOptions {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Match algorithm to use
|
|
10
|
+
*
|
|
11
|
+
* @see https://shiki.style/packages/transformers#matching-algorithm
|
|
12
|
+
* @default 'v3'
|
|
13
|
+
*/
|
|
14
|
+
matchAlgorithm?: MatchAlgorithm;
|
|
14
15
|
}
|
|
15
16
|
declare function createCommentNotationTransformer(name: string, regex: RegExp, onMatch: (this: ShikiTransformerContext, match: string[], line: Element, commentNode: Element, lines: Element[], index: number) => boolean, matchAlgorithm: MatchAlgorithm | undefined): ShikiTransformer;
|
|
16
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/transformers/compact-line-options.d.ts
|
|
17
19
|
interface TransformerCompactLineOption {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/**
|
|
21
|
+
* 1-based line number.
|
|
22
|
+
*/
|
|
23
|
+
line: number;
|
|
24
|
+
classes?: string[];
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Transformer for `shiki`'s legacy `lineOptions`
|
|
26
28
|
*/
|
|
27
29
|
declare function transformerCompactLineOptions(lineOptions?: TransformerCompactLineOption[]): ShikiTransformer$1;
|
|
28
|
-
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/transformers/meta-highlight.d.ts
|
|
29
32
|
declare function parseMetaHighlightString(meta: string): number[] | null;
|
|
30
33
|
interface TransformerMetaHighlightOptions {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Class for highlighted lines
|
|
36
|
+
*
|
|
37
|
+
* @default 'highlighted'
|
|
38
|
+
*/
|
|
39
|
+
className?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Interpret line numbers as 0-indexed
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
zeroIndexed?: boolean;
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
48
|
* Allow using `{1,3-5}` in the code snippet meta to mark highlighted lines.
|
|
46
49
|
*/
|
|
47
50
|
declare function transformerMetaHighlight(options?: TransformerMetaHighlightOptions): ShikiTransformer$1;
|
|
48
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/transformers/meta-highlight-word.d.ts
|
|
49
53
|
declare function parseMetaHighlightWords(meta: string): string[];
|
|
50
54
|
interface TransformerMetaWordHighlightOptions {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Class for highlighted words
|
|
57
|
+
*
|
|
58
|
+
* @default 'highlighted-word'
|
|
59
|
+
*/
|
|
60
|
+
className?: string;
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
59
63
|
* Allow using `/word/` in the code snippet meta to mark highlighted words.
|
|
60
64
|
*/
|
|
61
65
|
declare function transformerMetaWordHighlight(options?: TransformerMetaWordHighlightOptions): ShikiTransformer$1;
|
|
62
66
|
declare function findAllSubstringIndexes(str: string, substr: string): number[];
|
|
63
|
-
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/transformers/notation-diff.d.ts
|
|
64
69
|
interface TransformerNotationDiffOptions extends MatchAlgorithmOptions {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Class for added lines
|
|
72
|
+
*/
|
|
73
|
+
classLineAdd?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Class for removed lines
|
|
76
|
+
*/
|
|
77
|
+
classLineRemove?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Class added to the <pre> element when the current code has diff
|
|
80
|
+
*/
|
|
81
|
+
classActivePre?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Class added to the <code> element when the current code has diff
|
|
84
|
+
*/
|
|
85
|
+
classActiveCode?: string;
|
|
81
86
|
}
|
|
82
87
|
/**
|
|
83
88
|
* Use `[!code ++]` and `[!code --]` to mark added and removed lines.
|
|
84
89
|
*/
|
|
85
90
|
declare function transformerNotationDiff(options?: TransformerNotationDiffOptions): ShikiTransformer$1;
|
|
86
|
-
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/transformers/notation-error-level.d.ts
|
|
87
93
|
interface TransformerNotationErrorLevelOptions extends MatchAlgorithmOptions {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
classMap?: Record<string, string | string[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Class added to the <pre> element when the current code has diff
|
|
97
|
+
*/
|
|
98
|
+
classActivePre?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Class added to the <code> element when the current code has diff
|
|
101
|
+
*/
|
|
102
|
+
classActiveCode?: string;
|
|
97
103
|
}
|
|
98
104
|
/**
|
|
99
105
|
* Allow using `[!code error]` `[!code warning]` notation in code to mark highlighted lines.
|
|
100
106
|
*/
|
|
101
107
|
declare function transformerNotationErrorLevel(options?: TransformerNotationErrorLevelOptions): ShikiTransformer$1;
|
|
102
|
-
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/transformers/notation-focus.d.ts
|
|
103
110
|
interface TransformerNotationFocusOptions extends MatchAlgorithmOptions {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Class for focused lines
|
|
113
|
+
*/
|
|
114
|
+
classActiveLine?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Class added to the root element when the code has focused lines
|
|
117
|
+
*/
|
|
118
|
+
classActivePre?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Class added to the <code> element when the code has focused lines
|
|
121
|
+
*/
|
|
122
|
+
classActiveCode?: string;
|
|
116
123
|
}
|
|
117
124
|
/**
|
|
118
125
|
* Allow using `[!code focus]` notation in code to mark focused lines.
|
|
119
126
|
*/
|
|
120
127
|
declare function transformerNotationFocus(options?: TransformerNotationFocusOptions): ShikiTransformer$1;
|
|
121
|
-
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/transformers/notation-highlight.d.ts
|
|
122
130
|
interface TransformerNotationHighlightOptions extends MatchAlgorithmOptions {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Class for highlighted lines
|
|
133
|
+
*/
|
|
134
|
+
classActiveLine?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Class added to the root element when the code has highlighted lines
|
|
137
|
+
*/
|
|
138
|
+
classActivePre?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Class added to the <code> element when the code has highlighted lines
|
|
141
|
+
*/
|
|
142
|
+
classActiveCode?: string;
|
|
135
143
|
}
|
|
136
144
|
/**
|
|
137
145
|
* Allow using `[!code highlight]` notation in code to mark highlighted lines.
|
|
138
146
|
*/
|
|
139
147
|
declare function transformerNotationHighlight(options?: TransformerNotationHighlightOptions): ShikiTransformer$1;
|
|
140
|
-
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/transformers/notation-highlight-word.d.ts
|
|
141
150
|
interface TransformerNotationWordHighlightOptions extends MatchAlgorithmOptions {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Class for highlighted words
|
|
153
|
+
*/
|
|
154
|
+
classActiveWord?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Class added to the root element when the code has highlighted words
|
|
157
|
+
*/
|
|
158
|
+
classActivePre?: string;
|
|
150
159
|
}
|
|
151
160
|
declare function transformerNotationWordHighlight(options?: TransformerNotationWordHighlightOptions): ShikiTransformer$1;
|
|
152
|
-
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/transformers/notation-map.d.ts
|
|
153
163
|
interface TransformerNotationMapOptions extends MatchAlgorithmOptions {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
classMap?: Record<string, string | string[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Class added to the <pre> element when the current code has diff
|
|
167
|
+
*/
|
|
168
|
+
classActivePre?: string;
|
|
169
|
+
/**
|
|
170
|
+
* Class added to the <code> element when the current code has diff
|
|
171
|
+
*/
|
|
172
|
+
classActiveCode?: string;
|
|
163
173
|
}
|
|
164
174
|
declare function transformerNotationMap(options?: TransformerNotationMapOptions, name?: string): ShikiTransformer$1;
|
|
165
|
-
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/transformers/remove-comments.d.ts
|
|
166
177
|
interface TransformerRemoveCommentsOptions {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Remove lines that become empty after removing comments.
|
|
180
|
+
* @default true
|
|
181
|
+
*/
|
|
182
|
+
removeEmptyLines?: boolean;
|
|
172
183
|
}
|
|
173
184
|
/**
|
|
174
185
|
* Remove comments from the code.
|
|
175
186
|
*/
|
|
176
187
|
declare function transformerRemoveComments(options?: TransformerRemoveCommentsOptions): ShikiTransformer$1;
|
|
177
|
-
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/transformers/remove-line-breaks.d.ts
|
|
178
190
|
/**
|
|
179
191
|
* Remove line breaks between lines.
|
|
180
192
|
* Useful when you override `display: block` to `.line` in CSS.
|
|
181
193
|
*/
|
|
182
194
|
declare function transformerRemoveLineBreak(): ShikiTransformer$1;
|
|
183
|
-
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/transformers/remove-notation-escape.d.ts
|
|
184
197
|
/**
|
|
185
198
|
* Remove notation escapes.
|
|
186
199
|
* Useful when you want to write `// [!code` in markdown.
|
|
187
200
|
* If you process `// [\!code ...]` expression, you can get `// [!code ...]` in the output.
|
|
188
201
|
*/
|
|
189
202
|
declare function transformerRemoveNotationEscape(): ShikiTransformer$1;
|
|
190
|
-
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/transformers/render-indent-guides.d.ts
|
|
191
205
|
interface TransformerRenderIndentGuidesOptions {
|
|
192
|
-
|
|
206
|
+
indent?: number | false;
|
|
193
207
|
}
|
|
194
208
|
/**
|
|
195
209
|
* Render indentations as separate tokens.
|
|
196
210
|
* Apply with CSS, it can be used to render indent guides visually.
|
|
197
211
|
*/
|
|
198
212
|
declare function transformerRenderIndentGuides(options?: TransformerRenderIndentGuidesOptions): ShikiTransformer$1;
|
|
199
|
-
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/transformers/render-whitespace.d.ts
|
|
200
215
|
interface TransformerRenderWhitespaceOptions {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Class for tab
|
|
218
|
+
*
|
|
219
|
+
* @default 'tab'
|
|
220
|
+
*/
|
|
221
|
+
classTab?: string;
|
|
222
|
+
/**
|
|
223
|
+
* Class for space
|
|
224
|
+
*
|
|
225
|
+
* @default 'space'
|
|
226
|
+
*/
|
|
227
|
+
classSpace?: string;
|
|
228
|
+
/**
|
|
229
|
+
* Position of rendered whitespace
|
|
230
|
+
* @default all position
|
|
231
|
+
*/
|
|
232
|
+
position?: 'all' | 'boundary' | 'trailing' | 'leading';
|
|
218
233
|
}
|
|
219
234
|
/**
|
|
220
235
|
* Render whitespaces as separate tokens.
|
|
221
236
|
* Apply with CSS, it can be used to render tabs and spaces visually.
|
|
222
237
|
*/
|
|
223
238
|
declare function transformerRenderWhitespace(options?: TransformerRenderWhitespaceOptions): ShikiTransformer$1;
|
|
224
|
-
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/transformers/style-to-class.d.ts
|
|
225
241
|
interface TransformerStyleToClassOptions {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Prefix for class names.
|
|
244
|
+
* @default '__shiki_'
|
|
245
|
+
*/
|
|
246
|
+
classPrefix?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Suffix for class names.
|
|
249
|
+
* @default ''
|
|
250
|
+
*/
|
|
251
|
+
classSuffix?: string;
|
|
252
|
+
/**
|
|
253
|
+
* Callback to replace class names.
|
|
254
|
+
* @default (className) => className
|
|
255
|
+
*/
|
|
256
|
+
classReplacer?: (className: string) => string;
|
|
241
257
|
}
|
|
242
258
|
interface ShikiTransformerStyleToClass extends ShikiTransformer$1 {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
259
|
+
getClassRegistry: () => Map<string, Record<string, string> | string>;
|
|
260
|
+
getCSS: () => string;
|
|
261
|
+
clearRegistry: () => void;
|
|
246
262
|
}
|
|
247
263
|
/**
|
|
248
264
|
* Remove line breaks between lines.
|
|
249
265
|
* Useful when you override `display: block` to `.line` in CSS.
|
|
250
266
|
*/
|
|
251
267
|
declare function transformerStyleToClass(options?: TransformerStyleToClassOptions): ShikiTransformerStyleToClass;
|
|
252
|
-
|
|
253
|
-
export { createCommentNotationTransformer, findAllSubstringIndexes, parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveComments, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderIndentGuides, transformerRenderWhitespace, transformerStyleToClass };
|
|
254
|
-
export type { ShikiTransformerStyleToClass, TransformerCompactLineOption, TransformerMetaHighlightOptions, TransformerMetaWordHighlightOptions, TransformerNotationDiffOptions, TransformerNotationErrorLevelOptions, TransformerNotationFocusOptions, TransformerNotationHighlightOptions, TransformerNotationMapOptions, TransformerNotationWordHighlightOptions, TransformerRemoveCommentsOptions, TransformerRenderIndentGuidesOptions, TransformerRenderWhitespaceOptions, TransformerStyleToClassOptions };
|
|
268
|
+
//#endregion
|
|
269
|
+
export { ShikiTransformerStyleToClass, TransformerCompactLineOption, TransformerMetaHighlightOptions, TransformerMetaWordHighlightOptions, TransformerNotationDiffOptions, TransformerNotationErrorLevelOptions, TransformerNotationFocusOptions, TransformerNotationHighlightOptions, TransformerNotationMapOptions, TransformerNotationWordHighlightOptions, TransformerRemoveCommentsOptions, TransformerRenderIndentGuidesOptions, TransformerRenderWhitespaceOptions, TransformerStyleToClassOptions, createCommentNotationTransformer, findAllSubstringIndexes, parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveComments, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderIndentGuides, transformerRenderWhitespace, transformerStyleToClass };
|