@rspress/core 2.0.0-beta.3 → 2.0.0-beta.30

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.
@@ -0,0 +1,77 @@
1
+ /*! For license information please see shiki-transformers.js.LICENSE.txt */
2
+ const SHIKI_TRANSFORMER_ADD_TITLE = 'shiki-transformer:add-title';
3
+ function parseTitleFromMeta(meta) {
4
+ if (!meta) return '';
5
+ const kvList = meta.split(' ').filter(Boolean);
6
+ for (const item of kvList){
7
+ const [k, v = ''] = item.split('=').filter(Boolean);
8
+ if ('title' === k && v.length > 0) return v.replace(/["'`]/g, '');
9
+ }
10
+ return '';
11
+ }
12
+ function transformerAddTitle() {
13
+ return {
14
+ name: SHIKI_TRANSFORMER_ADD_TITLE,
15
+ pre (pre) {
16
+ const title = parseTitleFromMeta(this.options.meta?.__raw);
17
+ if (title.length > 0) pre.properties = {
18
+ ...pre.properties,
19
+ title
20
+ };
21
+ return pre;
22
+ }
23
+ };
24
+ }
25
+ const SHIKI_TRANSFORMER_LINE_NUMBER = 'shiki-transformer:line-number';
26
+ function transformerLineNumber(options = {}) {
27
+ const { classActiveLine = 'line-number', classActivePre = 'has-line-number' } = options;
28
+ return {
29
+ name: SHIKI_TRANSFORMER_LINE_NUMBER,
30
+ pre (pre) {
31
+ return this.addClassToHast(pre, classActivePre);
32
+ },
33
+ line (node) {
34
+ this.addClassToHast(node, classActiveLine);
35
+ }
36
+ };
37
+ }
38
+ /**
39
+ * these codes are copied from @shiki/transformers, transformerMetaHighlight
40
+ * @source https://github.com/shikijs/shiki/blob/f5cf06f55a0b4643d7b02f15ee2c5033be6f1245/packages/transformers/src/transformers/meta-highlight.ts#L56
41
+ * @license MIT
42
+ */ function parseMetaHighlightString(meta) {
43
+ if (!meta) return null;
44
+ const match = meta.match(/\{([\d,-]+)\}/);
45
+ if (!match) return null;
46
+ const lines = match[1].split(',').flatMap((v)=>{
47
+ const num = v.split('-').map((v)=>Number.parseInt(v, 10));
48
+ if (1 === num.length) return [
49
+ num[0]
50
+ ];
51
+ return Array.from({
52
+ length: num[1] - num[0] + 1
53
+ }, (_, i)=>i + num[0]);
54
+ });
55
+ return lines;
56
+ }
57
+ const symbol = Symbol('highlighted-lines');
58
+ const SHIKI_TRANSFORMER_META_HIGHLIGHT = 'shiki-transformer:compatible-meta-highlight';
59
+ function transformerCompatibleMetaHighlight(options = {}) {
60
+ const { classActiveLine = 'highlighted', classActivePre = 'has-highlighted' } = options;
61
+ return {
62
+ name: '@shikijs/transformers:meta-highlight',
63
+ line (node, line) {
64
+ if (!this.options.meta?.__raw) return;
65
+ const meta = this.meta;
66
+ meta[symbol] ??= parseMetaHighlightString(this.options.meta.__raw);
67
+ const lines = meta[symbol] ?? [];
68
+ if (lines.includes(line)) this.addClassToHast(node, classActiveLine);
69
+ return node;
70
+ },
71
+ pre (hast) {
72
+ this.addClassToHast(hast, classActivePre);
73
+ return hast;
74
+ }
75
+ };
76
+ }
77
+ export { SHIKI_TRANSFORMER_ADD_TITLE, SHIKI_TRANSFORMER_LINE_NUMBER, SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerAddTitle, transformerCompatibleMetaHighlight, transformerLineNumber };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * these codes are copied from @shiki/transformers, transformerMetaHighlight
3
+ * @source https://github.com/shikijs/shiki/blob/f5cf06f55a0b4643d7b02f15ee2c5033be6f1245/packages/transformers/src/transformers/meta-highlight.ts#L56
4
+ * @license MIT
5
+ */
@@ -0,0 +1,4 @@
1
+
2
+ export * from "@rspress/theme-default";
3
+
4
+ export { }
package/dist/theme.js ADDED
@@ -0,0 +1 @@
1
+ export * from "@rspress/theme-default";
@@ -0,0 +1,382 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$ref": "#/definitions/MetaJson",
4
+ "definitions": {
5
+ "MetaJson": {
6
+ "$ref": "#/definitions/SideMeta"
7
+ },
8
+ "SideMeta": {
9
+ "type": "array",
10
+ "items": {
11
+ "$ref": "#/definitions/SideMetaItem"
12
+ }
13
+ },
14
+ "SideMetaItem": {
15
+ "anyOf": [
16
+ {
17
+ "$ref": "#/definitions/FileSideMeta"
18
+ },
19
+ {
20
+ "$ref": "#/definitions/DirSideMeta"
21
+ },
22
+ {
23
+ "$ref": "#/definitions/DividerSideMeta"
24
+ },
25
+ {
26
+ "$ref": "#/definitions/SectionHeaderMeta"
27
+ },
28
+ {
29
+ "$ref": "#/definitions/CustomLinkMeta"
30
+ },
31
+ {
32
+ "type": "string"
33
+ }
34
+ ]
35
+ },
36
+ "FileSideMeta": {
37
+ "type": "object",
38
+ "properties": {
39
+ "type": {
40
+ "type": "string",
41
+ "const": "file"
42
+ },
43
+ "name": {
44
+ "type": "string"
45
+ },
46
+ "label": {
47
+ "type": "string"
48
+ },
49
+ "tag": {
50
+ "type": "string"
51
+ },
52
+ "overviewHeaders": {
53
+ "type": "array",
54
+ "items": {
55
+ "type": "number"
56
+ }
57
+ },
58
+ "context": {
59
+ "type": "string"
60
+ }
61
+ },
62
+ "required": [
63
+ "type",
64
+ "name"
65
+ ],
66
+ "additionalProperties": false
67
+ },
68
+ "DirSideMeta": {
69
+ "type": "object",
70
+ "properties": {
71
+ "type": {
72
+ "type": "string",
73
+ "const": "dir"
74
+ },
75
+ "name": {
76
+ "type": "string"
77
+ },
78
+ "label": {
79
+ "type": "string"
80
+ },
81
+ "tag": {
82
+ "type": "string"
83
+ },
84
+ "overviewHeaders": {
85
+ "type": "array",
86
+ "items": {
87
+ "type": "number"
88
+ }
89
+ },
90
+ "context": {
91
+ "type": "string"
92
+ },
93
+ "collapsible": {
94
+ "type": "boolean"
95
+ },
96
+ "collapsed": {
97
+ "type": "boolean"
98
+ }
99
+ },
100
+ "required": [
101
+ "type",
102
+ "name"
103
+ ],
104
+ "additionalProperties": false
105
+ },
106
+ "DividerSideMeta": {
107
+ "type": "object",
108
+ "properties": {
109
+ "type": {
110
+ "type": "string",
111
+ "const": "divider"
112
+ },
113
+ "dashed": {
114
+ "type": "boolean"
115
+ }
116
+ },
117
+ "required": [
118
+ "type"
119
+ ],
120
+ "additionalProperties": false
121
+ },
122
+ "SectionHeaderMeta": {
123
+ "type": "object",
124
+ "properties": {
125
+ "type": {
126
+ "type": "string",
127
+ "const": "section-header"
128
+ },
129
+ "label": {
130
+ "type": "string"
131
+ },
132
+ "tag": {
133
+ "type": "string"
134
+ }
135
+ },
136
+ "required": [
137
+ "type",
138
+ "label"
139
+ ],
140
+ "additionalProperties": false
141
+ },
142
+ "CustomLinkMeta": {
143
+ "anyOf": [
144
+ {
145
+ "type": "object",
146
+ "properties": {
147
+ "type": {
148
+ "type": "string",
149
+ "const": "custom-link"
150
+ },
151
+ "label": {
152
+ "type": "string"
153
+ },
154
+ "tag": {
155
+ "type": "string"
156
+ },
157
+ "overviewHeaders": {
158
+ "type": "array",
159
+ "items": {
160
+ "type": "number"
161
+ }
162
+ },
163
+ "context": {
164
+ "type": "string"
165
+ },
166
+ "link": {
167
+ "type": "string"
168
+ }
169
+ },
170
+ "required": [
171
+ "type",
172
+ "label",
173
+ "link"
174
+ ],
175
+ "additionalProperties": false
176
+ },
177
+ {
178
+ "type": "object",
179
+ "properties": {
180
+ "type": {
181
+ "type": "string",
182
+ "const": "custom-link"
183
+ },
184
+ "label": {
185
+ "type": "string"
186
+ },
187
+ "tag": {
188
+ "type": "string"
189
+ },
190
+ "overviewHeaders": {
191
+ "type": "array",
192
+ "items": {
193
+ "type": "number"
194
+ }
195
+ },
196
+ "context": {
197
+ "type": "string"
198
+ },
199
+ "link": {
200
+ "type": "string"
201
+ },
202
+ "collapsible": {
203
+ "type": "boolean"
204
+ },
205
+ "collapsed": {
206
+ "type": "boolean"
207
+ },
208
+ "items": {
209
+ "type": "array",
210
+ "items": {
211
+ "anyOf": [
212
+ {
213
+ "type": "object",
214
+ "properties": {
215
+ "type": {
216
+ "type": "string",
217
+ "const": "custom-link"
218
+ },
219
+ "label": {
220
+ "type": "string"
221
+ },
222
+ "tag": {
223
+ "type": "string"
224
+ },
225
+ "overviewHeaders": {
226
+ "type": "array",
227
+ "items": {
228
+ "type": "number"
229
+ }
230
+ },
231
+ "context": {
232
+ "type": "string"
233
+ },
234
+ "link": {
235
+ "type": "string"
236
+ }
237
+ },
238
+ "required": [
239
+ "label",
240
+ "link"
241
+ ],
242
+ "additionalProperties": false
243
+ },
244
+ {
245
+ "type": "object",
246
+ "properties": {
247
+ "type": {
248
+ "type": "string",
249
+ "const": "custom-link"
250
+ },
251
+ "label": {
252
+ "type": "string"
253
+ },
254
+ "tag": {
255
+ "type": "string"
256
+ },
257
+ "overviewHeaders": {
258
+ "type": "array",
259
+ "items": {
260
+ "type": "number"
261
+ }
262
+ },
263
+ "context": {
264
+ "type": "string"
265
+ },
266
+ "link": {
267
+ "type": "string"
268
+ },
269
+ "collapsible": {
270
+ "type": "boolean"
271
+ },
272
+ "collapsed": {
273
+ "type": "boolean"
274
+ },
275
+ "items": {
276
+ "type": "array",
277
+ "items": {
278
+ "$ref": "#/definitions/alias-926151818-564-1152-926151818-0-1986"
279
+ }
280
+ }
281
+ },
282
+ "required": [
283
+ "label",
284
+ "items"
285
+ ],
286
+ "additionalProperties": false
287
+ }
288
+ ]
289
+ }
290
+ }
291
+ },
292
+ "required": [
293
+ "type",
294
+ "label",
295
+ "items"
296
+ ],
297
+ "additionalProperties": false
298
+ }
299
+ ]
300
+ },
301
+ "alias-926151818-564-1152-926151818-0-1986": {
302
+ "anyOf": [
303
+ {
304
+ "type": "object",
305
+ "properties": {
306
+ "type": {
307
+ "type": "string",
308
+ "const": "custom-link"
309
+ },
310
+ "label": {
311
+ "type": "string"
312
+ },
313
+ "tag": {
314
+ "type": "string"
315
+ },
316
+ "overviewHeaders": {
317
+ "type": "array",
318
+ "items": {
319
+ "type": "number"
320
+ }
321
+ },
322
+ "context": {
323
+ "type": "string"
324
+ },
325
+ "link": {
326
+ "type": "string"
327
+ }
328
+ },
329
+ "required": [
330
+ "label",
331
+ "link"
332
+ ],
333
+ "additionalProperties": false
334
+ },
335
+ {
336
+ "type": "object",
337
+ "properties": {
338
+ "type": {
339
+ "type": "string",
340
+ "const": "custom-link"
341
+ },
342
+ "label": {
343
+ "type": "string"
344
+ },
345
+ "tag": {
346
+ "type": "string"
347
+ },
348
+ "overviewHeaders": {
349
+ "type": "array",
350
+ "items": {
351
+ "type": "number"
352
+ }
353
+ },
354
+ "context": {
355
+ "type": "string"
356
+ },
357
+ "link": {
358
+ "type": "string"
359
+ },
360
+ "collapsible": {
361
+ "type": "boolean"
362
+ },
363
+ "collapsed": {
364
+ "type": "boolean"
365
+ },
366
+ "items": {
367
+ "type": "array",
368
+ "items": {
369
+ "$ref": "#/definitions/alias-926151818-564-1152-926151818-0-1986"
370
+ }
371
+ }
372
+ },
373
+ "required": [
374
+ "label",
375
+ "items"
376
+ ],
377
+ "additionalProperties": false
378
+ }
379
+ ]
380
+ }
381
+ }
382
+ }
@@ -0,0 +1,118 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$ref": "#/definitions/NavJson",
4
+ "definitions": {
5
+ "NavJson": {
6
+ "type": "array",
7
+ "items": {
8
+ "$ref": "#/definitions/NavItem"
9
+ }
10
+ },
11
+ "NavItem": {
12
+ "anyOf": [
13
+ {
14
+ "$ref": "#/definitions/NavItemWithLink"
15
+ },
16
+ {
17
+ "$ref": "#/definitions/NavItemWithChildren"
18
+ },
19
+ {
20
+ "$ref": "#/definitions/NavItemWithLinkAndChildren"
21
+ }
22
+ ]
23
+ },
24
+ "NavItemWithLink": {
25
+ "type": "object",
26
+ "properties": {
27
+ "text": {
28
+ "type": "string"
29
+ },
30
+ "link": {
31
+ "type": "string"
32
+ },
33
+ "tag": {
34
+ "type": "string"
35
+ },
36
+ "activeMatch": {
37
+ "type": "string"
38
+ },
39
+ "position": {
40
+ "type": "string",
41
+ "enum": [
42
+ "left",
43
+ "right"
44
+ ]
45
+ }
46
+ },
47
+ "required": [
48
+ "text",
49
+ "link"
50
+ ],
51
+ "additionalProperties": false
52
+ },
53
+ "NavItemWithChildren": {
54
+ "type": "object",
55
+ "properties": {
56
+ "text": {
57
+ "type": "string"
58
+ },
59
+ "tag": {
60
+ "type": "string"
61
+ },
62
+ "items": {
63
+ "type": "array",
64
+ "items": {
65
+ "$ref": "#/definitions/NavItemWithLink"
66
+ }
67
+ },
68
+ "position": {
69
+ "type": "string",
70
+ "enum": [
71
+ "left",
72
+ "right"
73
+ ]
74
+ }
75
+ },
76
+ "required": [
77
+ "items"
78
+ ],
79
+ "additionalProperties": false
80
+ },
81
+ "NavItemWithLinkAndChildren": {
82
+ "type": "object",
83
+ "properties": {
84
+ "text": {
85
+ "type": "string"
86
+ },
87
+ "link": {
88
+ "type": "string"
89
+ },
90
+ "items": {
91
+ "type": "array",
92
+ "items": {
93
+ "$ref": "#/definitions/NavItemWithLink"
94
+ }
95
+ },
96
+ "tag": {
97
+ "type": "string"
98
+ },
99
+ "activeMatch": {
100
+ "type": "string"
101
+ },
102
+ "position": {
103
+ "type": "string",
104
+ "enum": [
105
+ "left",
106
+ "right"
107
+ ]
108
+ }
109
+ },
110
+ "required": [
111
+ "text",
112
+ "link",
113
+ "items"
114
+ ],
115
+ "additionalProperties": false
116
+ }
117
+ }
118
+ }