@shikijs/transformers 2.1.0 → 2.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/dist/index.d.mts +29 -26
- package/dist/index.d.ts +29 -26
- package/dist/index.mjs +88 -88
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { ShikiTransformer } from '@shikijs/
|
|
1
|
+
import { ShikiTransformerContext, ShikiTransformer } from '@shikijs/core';
|
|
2
|
+
import { Element } from 'hast';
|
|
3
|
+
import { ShikiTransformer as ShikiTransformer$1 } from '@shikijs/types';
|
|
4
|
+
|
|
5
|
+
type MatchAlgorithm = 'v1' | 'v3';
|
|
6
|
+
interface MatchAlgorithmOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Match algorithm to use
|
|
9
|
+
*
|
|
10
|
+
* @see https://shiki.style/packages/transformers#matching-algorithm
|
|
11
|
+
* @default 'v1'
|
|
12
|
+
*/
|
|
13
|
+
matchAlgorithm?: MatchAlgorithm;
|
|
14
|
+
}
|
|
15
|
+
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;
|
|
2
16
|
|
|
3
17
|
interface TransformerCompactLineOption {
|
|
4
18
|
/**
|
|
@@ -10,7 +24,7 @@ interface TransformerCompactLineOption {
|
|
|
10
24
|
/**
|
|
11
25
|
* Transformer for `shiki`'s legacy `lineOptions`
|
|
12
26
|
*/
|
|
13
|
-
declare function transformerCompactLineOptions(lineOptions?: TransformerCompactLineOption[]): ShikiTransformer;
|
|
27
|
+
declare function transformerCompactLineOptions(lineOptions?: TransformerCompactLineOption[]): ShikiTransformer$1;
|
|
14
28
|
|
|
15
29
|
declare function parseMetaHighlightString(meta: string): number[] | null;
|
|
16
30
|
interface TransformerMetaHighlightOptions {
|
|
@@ -24,7 +38,7 @@ interface TransformerMetaHighlightOptions {
|
|
|
24
38
|
/**
|
|
25
39
|
* Allow using `{1,3-5}` in the code snippet meta to mark highlighted lines.
|
|
26
40
|
*/
|
|
27
|
-
declare function transformerMetaHighlight(options?: TransformerMetaHighlightOptions): ShikiTransformer;
|
|
41
|
+
declare function transformerMetaHighlight(options?: TransformerMetaHighlightOptions): ShikiTransformer$1;
|
|
28
42
|
|
|
29
43
|
declare function parseMetaHighlightWords(meta: string): string[];
|
|
30
44
|
interface TransformerMetaWordHighlightOptions {
|
|
@@ -38,18 +52,7 @@ interface TransformerMetaWordHighlightOptions {
|
|
|
38
52
|
/**
|
|
39
53
|
* Allow using `/word/` in the code snippet meta to mark highlighted words.
|
|
40
54
|
*/
|
|
41
|
-
declare function transformerMetaWordHighlight(options?: TransformerMetaWordHighlightOptions): ShikiTransformer;
|
|
42
|
-
|
|
43
|
-
type MatchAlgorithm = 'v1' | 'v3';
|
|
44
|
-
interface MatchAlgorithmOptions {
|
|
45
|
-
/**
|
|
46
|
-
* Match algorithm to use
|
|
47
|
-
*
|
|
48
|
-
* @see https://shiki.style/packages/transformers#matching-algorithm
|
|
49
|
-
* @default 'v1'
|
|
50
|
-
*/
|
|
51
|
-
matchAlgorithm?: MatchAlgorithm;
|
|
52
|
-
}
|
|
55
|
+
declare function transformerMetaWordHighlight(options?: TransformerMetaWordHighlightOptions): ShikiTransformer$1;
|
|
53
56
|
|
|
54
57
|
interface TransformerNotationDiffOptions extends MatchAlgorithmOptions {
|
|
55
58
|
/**
|
|
@@ -68,7 +71,7 @@ interface TransformerNotationDiffOptions extends MatchAlgorithmOptions {
|
|
|
68
71
|
/**
|
|
69
72
|
* Use `[!code ++]` and `[!code --]` to mark added and removed lines.
|
|
70
73
|
*/
|
|
71
|
-
declare function transformerNotationDiff(options?: TransformerNotationDiffOptions): ShikiTransformer;
|
|
74
|
+
declare function transformerNotationDiff(options?: TransformerNotationDiffOptions): ShikiTransformer$1;
|
|
72
75
|
|
|
73
76
|
interface TransformerNotationErrorLevelOptions extends MatchAlgorithmOptions {
|
|
74
77
|
classMap?: Record<string, string | string[]>;
|
|
@@ -80,7 +83,7 @@ interface TransformerNotationErrorLevelOptions extends MatchAlgorithmOptions {
|
|
|
80
83
|
/**
|
|
81
84
|
* Allow using `[!code error]` `[!code warning]` notation in code to mark highlighted lines.
|
|
82
85
|
*/
|
|
83
|
-
declare function transformerNotationErrorLevel(options?: TransformerNotationErrorLevelOptions): ShikiTransformer;
|
|
86
|
+
declare function transformerNotationErrorLevel(options?: TransformerNotationErrorLevelOptions): ShikiTransformer$1;
|
|
84
87
|
|
|
85
88
|
interface TransformerNotationFocusOptions extends MatchAlgorithmOptions {
|
|
86
89
|
/**
|
|
@@ -95,7 +98,7 @@ interface TransformerNotationFocusOptions extends MatchAlgorithmOptions {
|
|
|
95
98
|
/**
|
|
96
99
|
* Allow using `[!code focus]` notation in code to mark focused lines.
|
|
97
100
|
*/
|
|
98
|
-
declare function transformerNotationFocus(options?: TransformerNotationFocusOptions): ShikiTransformer;
|
|
101
|
+
declare function transformerNotationFocus(options?: TransformerNotationFocusOptions): ShikiTransformer$1;
|
|
99
102
|
|
|
100
103
|
interface TransformerNotationHighlightOptions extends MatchAlgorithmOptions {
|
|
101
104
|
/**
|
|
@@ -110,7 +113,7 @@ interface TransformerNotationHighlightOptions extends MatchAlgorithmOptions {
|
|
|
110
113
|
/**
|
|
111
114
|
* Allow using `[!code highlight]` notation in code to mark highlighted lines.
|
|
112
115
|
*/
|
|
113
|
-
declare function transformerNotationHighlight(options?: TransformerNotationHighlightOptions): ShikiTransformer;
|
|
116
|
+
declare function transformerNotationHighlight(options?: TransformerNotationHighlightOptions): ShikiTransformer$1;
|
|
114
117
|
|
|
115
118
|
interface TransformerNotationWordHighlightOptions extends MatchAlgorithmOptions {
|
|
116
119
|
/**
|
|
@@ -122,7 +125,7 @@ interface TransformerNotationWordHighlightOptions extends MatchAlgorithmOptions
|
|
|
122
125
|
*/
|
|
123
126
|
classActivePre?: string;
|
|
124
127
|
}
|
|
125
|
-
declare function transformerNotationWordHighlight(options?: TransformerNotationWordHighlightOptions): ShikiTransformer;
|
|
128
|
+
declare function transformerNotationWordHighlight(options?: TransformerNotationWordHighlightOptions): ShikiTransformer$1;
|
|
126
129
|
|
|
127
130
|
interface TransformerNotationMapOptions extends MatchAlgorithmOptions {
|
|
128
131
|
classMap?: Record<string, string | string[]>;
|
|
@@ -131,20 +134,20 @@ interface TransformerNotationMapOptions extends MatchAlgorithmOptions {
|
|
|
131
134
|
*/
|
|
132
135
|
classActivePre?: string;
|
|
133
136
|
}
|
|
134
|
-
declare function transformerNotationMap(options?: TransformerNotationMapOptions, name?: string): ShikiTransformer;
|
|
137
|
+
declare function transformerNotationMap(options?: TransformerNotationMapOptions, name?: string): ShikiTransformer$1;
|
|
135
138
|
|
|
136
139
|
/**
|
|
137
140
|
* Remove line breaks between lines.
|
|
138
141
|
* Useful when you override `display: block` to `.line` in CSS.
|
|
139
142
|
*/
|
|
140
|
-
declare function transformerRemoveLineBreak(): ShikiTransformer;
|
|
143
|
+
declare function transformerRemoveLineBreak(): ShikiTransformer$1;
|
|
141
144
|
|
|
142
145
|
/**
|
|
143
146
|
* Remove notation escapes.
|
|
144
147
|
* Useful when you want to write `// [!code` in markdown.
|
|
145
148
|
* If you process `// [\!code ...]` expression, you can get `// [!code ...]` in the output.
|
|
146
149
|
*/
|
|
147
|
-
declare function transformerRemoveNotationEscape(): ShikiTransformer;
|
|
150
|
+
declare function transformerRemoveNotationEscape(): ShikiTransformer$1;
|
|
148
151
|
|
|
149
152
|
interface TransformerRenderWhitespaceOptions {
|
|
150
153
|
/**
|
|
@@ -169,7 +172,7 @@ interface TransformerRenderWhitespaceOptions {
|
|
|
169
172
|
* Render whitespaces as separate tokens.
|
|
170
173
|
* Apply with CSS, it can be used to render tabs and spaces visually.
|
|
171
174
|
*/
|
|
172
|
-
declare function transformerRenderWhitespace(options?: TransformerRenderWhitespaceOptions): ShikiTransformer;
|
|
175
|
+
declare function transformerRenderWhitespace(options?: TransformerRenderWhitespaceOptions): ShikiTransformer$1;
|
|
173
176
|
|
|
174
177
|
interface TransformerStyleToClassOptions {
|
|
175
178
|
/**
|
|
@@ -188,7 +191,7 @@ interface TransformerStyleToClassOptions {
|
|
|
188
191
|
*/
|
|
189
192
|
classReplacer?: (className: string) => string;
|
|
190
193
|
}
|
|
191
|
-
interface ShikiTransformerStyleToClass extends ShikiTransformer {
|
|
194
|
+
interface ShikiTransformerStyleToClass extends ShikiTransformer$1 {
|
|
192
195
|
getClassRegistry: () => Map<string, Record<string, string> | string>;
|
|
193
196
|
getCSS: () => string;
|
|
194
197
|
clearRegistry: () => void;
|
|
@@ -199,4 +202,4 @@ interface ShikiTransformerStyleToClass extends ShikiTransformer {
|
|
|
199
202
|
*/
|
|
200
203
|
declare function transformerStyleToClass(options?: TransformerStyleToClassOptions): ShikiTransformerStyleToClass;
|
|
201
204
|
|
|
202
|
-
export { type ShikiTransformerStyleToClass, type TransformerCompactLineOption, type TransformerMetaHighlightOptions, type TransformerMetaWordHighlightOptions, type TransformerNotationDiffOptions, type TransformerNotationErrorLevelOptions, type TransformerNotationFocusOptions, type TransformerNotationHighlightOptions, type TransformerNotationMapOptions, type TransformerNotationWordHighlightOptions, type TransformerRenderWhitespaceOptions, type TransformerStyleToClassOptions, parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderWhitespace, transformerStyleToClass };
|
|
205
|
+
export { type ShikiTransformerStyleToClass, type TransformerCompactLineOption, type TransformerMetaHighlightOptions, type TransformerMetaWordHighlightOptions, type TransformerNotationDiffOptions, type TransformerNotationErrorLevelOptions, type TransformerNotationFocusOptions, type TransformerNotationHighlightOptions, type TransformerNotationMapOptions, type TransformerNotationWordHighlightOptions, type TransformerRenderWhitespaceOptions, type TransformerStyleToClassOptions, createCommentNotationTransformer, parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderWhitespace, transformerStyleToClass };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { ShikiTransformer } from '@shikijs/
|
|
1
|
+
import { ShikiTransformerContext, ShikiTransformer } from '@shikijs/core';
|
|
2
|
+
import { Element } from 'hast';
|
|
3
|
+
import { ShikiTransformer as ShikiTransformer$1 } from '@shikijs/types';
|
|
4
|
+
|
|
5
|
+
type MatchAlgorithm = 'v1' | 'v3';
|
|
6
|
+
interface MatchAlgorithmOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Match algorithm to use
|
|
9
|
+
*
|
|
10
|
+
* @see https://shiki.style/packages/transformers#matching-algorithm
|
|
11
|
+
* @default 'v1'
|
|
12
|
+
*/
|
|
13
|
+
matchAlgorithm?: MatchAlgorithm;
|
|
14
|
+
}
|
|
15
|
+
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;
|
|
2
16
|
|
|
3
17
|
interface TransformerCompactLineOption {
|
|
4
18
|
/**
|
|
@@ -10,7 +24,7 @@ interface TransformerCompactLineOption {
|
|
|
10
24
|
/**
|
|
11
25
|
* Transformer for `shiki`'s legacy `lineOptions`
|
|
12
26
|
*/
|
|
13
|
-
declare function transformerCompactLineOptions(lineOptions?: TransformerCompactLineOption[]): ShikiTransformer;
|
|
27
|
+
declare function transformerCompactLineOptions(lineOptions?: TransformerCompactLineOption[]): ShikiTransformer$1;
|
|
14
28
|
|
|
15
29
|
declare function parseMetaHighlightString(meta: string): number[] | null;
|
|
16
30
|
interface TransformerMetaHighlightOptions {
|
|
@@ -24,7 +38,7 @@ interface TransformerMetaHighlightOptions {
|
|
|
24
38
|
/**
|
|
25
39
|
* Allow using `{1,3-5}` in the code snippet meta to mark highlighted lines.
|
|
26
40
|
*/
|
|
27
|
-
declare function transformerMetaHighlight(options?: TransformerMetaHighlightOptions): ShikiTransformer;
|
|
41
|
+
declare function transformerMetaHighlight(options?: TransformerMetaHighlightOptions): ShikiTransformer$1;
|
|
28
42
|
|
|
29
43
|
declare function parseMetaHighlightWords(meta: string): string[];
|
|
30
44
|
interface TransformerMetaWordHighlightOptions {
|
|
@@ -38,18 +52,7 @@ interface TransformerMetaWordHighlightOptions {
|
|
|
38
52
|
/**
|
|
39
53
|
* Allow using `/word/` in the code snippet meta to mark highlighted words.
|
|
40
54
|
*/
|
|
41
|
-
declare function transformerMetaWordHighlight(options?: TransformerMetaWordHighlightOptions): ShikiTransformer;
|
|
42
|
-
|
|
43
|
-
type MatchAlgorithm = 'v1' | 'v3';
|
|
44
|
-
interface MatchAlgorithmOptions {
|
|
45
|
-
/**
|
|
46
|
-
* Match algorithm to use
|
|
47
|
-
*
|
|
48
|
-
* @see https://shiki.style/packages/transformers#matching-algorithm
|
|
49
|
-
* @default 'v1'
|
|
50
|
-
*/
|
|
51
|
-
matchAlgorithm?: MatchAlgorithm;
|
|
52
|
-
}
|
|
55
|
+
declare function transformerMetaWordHighlight(options?: TransformerMetaWordHighlightOptions): ShikiTransformer$1;
|
|
53
56
|
|
|
54
57
|
interface TransformerNotationDiffOptions extends MatchAlgorithmOptions {
|
|
55
58
|
/**
|
|
@@ -68,7 +71,7 @@ interface TransformerNotationDiffOptions extends MatchAlgorithmOptions {
|
|
|
68
71
|
/**
|
|
69
72
|
* Use `[!code ++]` and `[!code --]` to mark added and removed lines.
|
|
70
73
|
*/
|
|
71
|
-
declare function transformerNotationDiff(options?: TransformerNotationDiffOptions): ShikiTransformer;
|
|
74
|
+
declare function transformerNotationDiff(options?: TransformerNotationDiffOptions): ShikiTransformer$1;
|
|
72
75
|
|
|
73
76
|
interface TransformerNotationErrorLevelOptions extends MatchAlgorithmOptions {
|
|
74
77
|
classMap?: Record<string, string | string[]>;
|
|
@@ -80,7 +83,7 @@ interface TransformerNotationErrorLevelOptions extends MatchAlgorithmOptions {
|
|
|
80
83
|
/**
|
|
81
84
|
* Allow using `[!code error]` `[!code warning]` notation in code to mark highlighted lines.
|
|
82
85
|
*/
|
|
83
|
-
declare function transformerNotationErrorLevel(options?: TransformerNotationErrorLevelOptions): ShikiTransformer;
|
|
86
|
+
declare function transformerNotationErrorLevel(options?: TransformerNotationErrorLevelOptions): ShikiTransformer$1;
|
|
84
87
|
|
|
85
88
|
interface TransformerNotationFocusOptions extends MatchAlgorithmOptions {
|
|
86
89
|
/**
|
|
@@ -95,7 +98,7 @@ interface TransformerNotationFocusOptions extends MatchAlgorithmOptions {
|
|
|
95
98
|
/**
|
|
96
99
|
* Allow using `[!code focus]` notation in code to mark focused lines.
|
|
97
100
|
*/
|
|
98
|
-
declare function transformerNotationFocus(options?: TransformerNotationFocusOptions): ShikiTransformer;
|
|
101
|
+
declare function transformerNotationFocus(options?: TransformerNotationFocusOptions): ShikiTransformer$1;
|
|
99
102
|
|
|
100
103
|
interface TransformerNotationHighlightOptions extends MatchAlgorithmOptions {
|
|
101
104
|
/**
|
|
@@ -110,7 +113,7 @@ interface TransformerNotationHighlightOptions extends MatchAlgorithmOptions {
|
|
|
110
113
|
/**
|
|
111
114
|
* Allow using `[!code highlight]` notation in code to mark highlighted lines.
|
|
112
115
|
*/
|
|
113
|
-
declare function transformerNotationHighlight(options?: TransformerNotationHighlightOptions): ShikiTransformer;
|
|
116
|
+
declare function transformerNotationHighlight(options?: TransformerNotationHighlightOptions): ShikiTransformer$1;
|
|
114
117
|
|
|
115
118
|
interface TransformerNotationWordHighlightOptions extends MatchAlgorithmOptions {
|
|
116
119
|
/**
|
|
@@ -122,7 +125,7 @@ interface TransformerNotationWordHighlightOptions extends MatchAlgorithmOptions
|
|
|
122
125
|
*/
|
|
123
126
|
classActivePre?: string;
|
|
124
127
|
}
|
|
125
|
-
declare function transformerNotationWordHighlight(options?: TransformerNotationWordHighlightOptions): ShikiTransformer;
|
|
128
|
+
declare function transformerNotationWordHighlight(options?: TransformerNotationWordHighlightOptions): ShikiTransformer$1;
|
|
126
129
|
|
|
127
130
|
interface TransformerNotationMapOptions extends MatchAlgorithmOptions {
|
|
128
131
|
classMap?: Record<string, string | string[]>;
|
|
@@ -131,20 +134,20 @@ interface TransformerNotationMapOptions extends MatchAlgorithmOptions {
|
|
|
131
134
|
*/
|
|
132
135
|
classActivePre?: string;
|
|
133
136
|
}
|
|
134
|
-
declare function transformerNotationMap(options?: TransformerNotationMapOptions, name?: string): ShikiTransformer;
|
|
137
|
+
declare function transformerNotationMap(options?: TransformerNotationMapOptions, name?: string): ShikiTransformer$1;
|
|
135
138
|
|
|
136
139
|
/**
|
|
137
140
|
* Remove line breaks between lines.
|
|
138
141
|
* Useful when you override `display: block` to `.line` in CSS.
|
|
139
142
|
*/
|
|
140
|
-
declare function transformerRemoveLineBreak(): ShikiTransformer;
|
|
143
|
+
declare function transformerRemoveLineBreak(): ShikiTransformer$1;
|
|
141
144
|
|
|
142
145
|
/**
|
|
143
146
|
* Remove notation escapes.
|
|
144
147
|
* Useful when you want to write `// [!code` in markdown.
|
|
145
148
|
* If you process `// [\!code ...]` expression, you can get `// [!code ...]` in the output.
|
|
146
149
|
*/
|
|
147
|
-
declare function transformerRemoveNotationEscape(): ShikiTransformer;
|
|
150
|
+
declare function transformerRemoveNotationEscape(): ShikiTransformer$1;
|
|
148
151
|
|
|
149
152
|
interface TransformerRenderWhitespaceOptions {
|
|
150
153
|
/**
|
|
@@ -169,7 +172,7 @@ interface TransformerRenderWhitespaceOptions {
|
|
|
169
172
|
* Render whitespaces as separate tokens.
|
|
170
173
|
* Apply with CSS, it can be used to render tabs and spaces visually.
|
|
171
174
|
*/
|
|
172
|
-
declare function transformerRenderWhitespace(options?: TransformerRenderWhitespaceOptions): ShikiTransformer;
|
|
175
|
+
declare function transformerRenderWhitespace(options?: TransformerRenderWhitespaceOptions): ShikiTransformer$1;
|
|
173
176
|
|
|
174
177
|
interface TransformerStyleToClassOptions {
|
|
175
178
|
/**
|
|
@@ -188,7 +191,7 @@ interface TransformerStyleToClassOptions {
|
|
|
188
191
|
*/
|
|
189
192
|
classReplacer?: (className: string) => string;
|
|
190
193
|
}
|
|
191
|
-
interface ShikiTransformerStyleToClass extends ShikiTransformer {
|
|
194
|
+
interface ShikiTransformerStyleToClass extends ShikiTransformer$1 {
|
|
192
195
|
getClassRegistry: () => Map<string, Record<string, string> | string>;
|
|
193
196
|
getCSS: () => string;
|
|
194
197
|
clearRegistry: () => void;
|
|
@@ -199,4 +202,4 @@ interface ShikiTransformerStyleToClass extends ShikiTransformer {
|
|
|
199
202
|
*/
|
|
200
203
|
declare function transformerStyleToClass(options?: TransformerStyleToClassOptions): ShikiTransformerStyleToClass;
|
|
201
204
|
|
|
202
|
-
export { type ShikiTransformerStyleToClass, type TransformerCompactLineOption, type TransformerMetaHighlightOptions, type TransformerMetaWordHighlightOptions, type TransformerNotationDiffOptions, type TransformerNotationErrorLevelOptions, type TransformerNotationFocusOptions, type TransformerNotationHighlightOptions, type TransformerNotationMapOptions, type TransformerNotationWordHighlightOptions, type TransformerRenderWhitespaceOptions, type TransformerStyleToClassOptions, parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderWhitespace, transformerStyleToClass };
|
|
205
|
+
export { type ShikiTransformerStyleToClass, type TransformerCompactLineOption, type TransformerMetaHighlightOptions, type TransformerMetaWordHighlightOptions, type TransformerNotationDiffOptions, type TransformerNotationErrorLevelOptions, type TransformerNotationFocusOptions, type TransformerNotationHighlightOptions, type TransformerNotationMapOptions, type TransformerNotationWordHighlightOptions, type TransformerRenderWhitespaceOptions, type TransformerStyleToClassOptions, createCommentNotationTransformer, parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderWhitespace, transformerStyleToClass };
|
package/dist/index.mjs
CHANGED
|
@@ -1,92 +1,5 @@
|
|
|
1
1
|
import { warnDeprecated } from '@shikijs/core';
|
|
2
2
|
|
|
3
|
-
function transformerCompactLineOptions(lineOptions = []) {
|
|
4
|
-
return {
|
|
5
|
-
name: "@shikijs/transformers:compact-line-options",
|
|
6
|
-
line(node, line) {
|
|
7
|
-
const lineOption = lineOptions.find((o) => o.line === line);
|
|
8
|
-
if (lineOption?.classes)
|
|
9
|
-
this.addClassToHast(node, lineOption.classes);
|
|
10
|
-
return node;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function parseMetaHighlightString(meta) {
|
|
16
|
-
if (!meta)
|
|
17
|
-
return null;
|
|
18
|
-
const match = meta.match(/\{([\d,-]+)\}/);
|
|
19
|
-
if (!match)
|
|
20
|
-
return null;
|
|
21
|
-
const lines = match[1].split(",").flatMap((v) => {
|
|
22
|
-
const num = v.split("-").map((v2) => Number.parseInt(v2, 10));
|
|
23
|
-
if (num.length === 1)
|
|
24
|
-
return [num[0]];
|
|
25
|
-
return Array.from({ length: num[1] - num[0] + 1 }, (_, i) => i + num[0]);
|
|
26
|
-
});
|
|
27
|
-
return lines;
|
|
28
|
-
}
|
|
29
|
-
const symbol = Symbol("highlighted-lines");
|
|
30
|
-
function transformerMetaHighlight(options = {}) {
|
|
31
|
-
const {
|
|
32
|
-
className = "highlighted"
|
|
33
|
-
} = options;
|
|
34
|
-
return {
|
|
35
|
-
name: "@shikijs/transformers:meta-highlight",
|
|
36
|
-
line(node, line) {
|
|
37
|
-
if (!this.options.meta?.__raw) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const meta = this.meta;
|
|
41
|
-
meta[symbol] ??= parseMetaHighlightString(this.options.meta.__raw);
|
|
42
|
-
const lines = meta[symbol] ?? [];
|
|
43
|
-
if (lines.includes(line))
|
|
44
|
-
this.addClassToHast(node, className);
|
|
45
|
-
return node;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function parseMetaHighlightWords(meta) {
|
|
51
|
-
if (!meta)
|
|
52
|
-
return [];
|
|
53
|
-
const match = Array.from(meta.matchAll(/\/((?:\\.|[^/])+)\//g));
|
|
54
|
-
return match.map((v) => v[1].replace(/\\(.)/g, "$1"));
|
|
55
|
-
}
|
|
56
|
-
function transformerMetaWordHighlight(options = {}) {
|
|
57
|
-
const {
|
|
58
|
-
className = "highlighted-word"
|
|
59
|
-
} = options;
|
|
60
|
-
return {
|
|
61
|
-
name: "@shikijs/transformers:meta-word-highlight",
|
|
62
|
-
preprocess(code, options2) {
|
|
63
|
-
if (!this.options.meta?.__raw)
|
|
64
|
-
return;
|
|
65
|
-
const words = parseMetaHighlightWords(this.options.meta.__raw);
|
|
66
|
-
options2.decorations ||= [];
|
|
67
|
-
for (const word of words) {
|
|
68
|
-
const indexes = findAllSubstringIndexes(code, word);
|
|
69
|
-
for (const index of indexes) {
|
|
70
|
-
options2.decorations.push({
|
|
71
|
-
start: index,
|
|
72
|
-
end: index + word.length,
|
|
73
|
-
properties: {
|
|
74
|
-
class: className
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function findAllSubstringIndexes(str, substr) {
|
|
83
|
-
const indexes = [];
|
|
84
|
-
let i = -1;
|
|
85
|
-
while ((i = str.indexOf(substr, i + 1)) !== -1)
|
|
86
|
-
indexes.push(i);
|
|
87
|
-
return indexes;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
3
|
const matchers = [
|
|
91
4
|
[/^(<!--)(.+)(-->)$/, false],
|
|
92
5
|
[/^(\/\*)(.+)(\*\/)$/, false],
|
|
@@ -226,6 +139,93 @@ function createCommentNotationTransformer(name, regex, onMatch, matchAlgorithm)
|
|
|
226
139
|
};
|
|
227
140
|
}
|
|
228
141
|
|
|
142
|
+
function transformerCompactLineOptions(lineOptions = []) {
|
|
143
|
+
return {
|
|
144
|
+
name: "@shikijs/transformers:compact-line-options",
|
|
145
|
+
line(node, line) {
|
|
146
|
+
const lineOption = lineOptions.find((o) => o.line === line);
|
|
147
|
+
if (lineOption?.classes)
|
|
148
|
+
this.addClassToHast(node, lineOption.classes);
|
|
149
|
+
return node;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function parseMetaHighlightString(meta) {
|
|
155
|
+
if (!meta)
|
|
156
|
+
return null;
|
|
157
|
+
const match = meta.match(/\{([\d,-]+)\}/);
|
|
158
|
+
if (!match)
|
|
159
|
+
return null;
|
|
160
|
+
const lines = match[1].split(",").flatMap((v) => {
|
|
161
|
+
const num = v.split("-").map((v2) => Number.parseInt(v2, 10));
|
|
162
|
+
if (num.length === 1)
|
|
163
|
+
return [num[0]];
|
|
164
|
+
return Array.from({ length: num[1] - num[0] + 1 }, (_, i) => i + num[0]);
|
|
165
|
+
});
|
|
166
|
+
return lines;
|
|
167
|
+
}
|
|
168
|
+
const symbol = Symbol("highlighted-lines");
|
|
169
|
+
function transformerMetaHighlight(options = {}) {
|
|
170
|
+
const {
|
|
171
|
+
className = "highlighted"
|
|
172
|
+
} = options;
|
|
173
|
+
return {
|
|
174
|
+
name: "@shikijs/transformers:meta-highlight",
|
|
175
|
+
line(node, line) {
|
|
176
|
+
if (!this.options.meta?.__raw) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const meta = this.meta;
|
|
180
|
+
meta[symbol] ??= parseMetaHighlightString(this.options.meta.__raw);
|
|
181
|
+
const lines = meta[symbol] ?? [];
|
|
182
|
+
if (lines.includes(line))
|
|
183
|
+
this.addClassToHast(node, className);
|
|
184
|
+
return node;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function parseMetaHighlightWords(meta) {
|
|
190
|
+
if (!meta)
|
|
191
|
+
return [];
|
|
192
|
+
const match = Array.from(meta.matchAll(/\/((?:\\.|[^/])+)\//g));
|
|
193
|
+
return match.map((v) => v[1].replace(/\\(.)/g, "$1"));
|
|
194
|
+
}
|
|
195
|
+
function transformerMetaWordHighlight(options = {}) {
|
|
196
|
+
const {
|
|
197
|
+
className = "highlighted-word"
|
|
198
|
+
} = options;
|
|
199
|
+
return {
|
|
200
|
+
name: "@shikijs/transformers:meta-word-highlight",
|
|
201
|
+
preprocess(code, options2) {
|
|
202
|
+
if (!this.options.meta?.__raw)
|
|
203
|
+
return;
|
|
204
|
+
const words = parseMetaHighlightWords(this.options.meta.__raw);
|
|
205
|
+
options2.decorations ||= [];
|
|
206
|
+
for (const word of words) {
|
|
207
|
+
const indexes = findAllSubstringIndexes(code, word);
|
|
208
|
+
for (const index of indexes) {
|
|
209
|
+
options2.decorations.push({
|
|
210
|
+
start: index,
|
|
211
|
+
end: index + word.length,
|
|
212
|
+
properties: {
|
|
213
|
+
class: className
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function findAllSubstringIndexes(str, substr) {
|
|
222
|
+
const indexes = [];
|
|
223
|
+
let i = -1;
|
|
224
|
+
while ((i = str.indexOf(substr, i + 1)) !== -1)
|
|
225
|
+
indexes.push(i);
|
|
226
|
+
return indexes;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
229
|
function escapeRegExp(str) {
|
|
230
230
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
231
231
|
}
|
|
@@ -618,4 +618,4 @@ function cyrb53(str, seed = 0) {
|
|
|
618
618
|
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36).slice(0, 6);
|
|
619
619
|
}
|
|
620
620
|
|
|
621
|
-
export { parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderWhitespace, transformerStyleToClass };
|
|
621
|
+
export { createCommentNotationTransformer, parseMetaHighlightString, parseMetaHighlightWords, transformerCompactLineOptions, transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationMap, transformerNotationWordHighlight, transformerRemoveLineBreak, transformerRemoveNotationEscape, transformerRenderWhitespace, transformerStyleToClass };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/transformers",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"description": "Collective of common transformers transformers for Shiki",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@shikijs/core": "2.
|
|
34
|
-
"@shikijs/types": "2.
|
|
33
|
+
"@shikijs/core": "2.3.0",
|
|
34
|
+
"@shikijs/types": "2.3.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "unbuild",
|