@slidev/parser 0.43.8 → 0.43.10
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/package.json +2 -2
- package/dist/chunk-HBQPSWBS.js +0 -493
- package/dist/core.d.ts +0 -28
- package/dist/core.js +0 -36
- package/dist/fs.d.ts +0 -9
- package/dist/fs.js +0 -120
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slidev/parser",
|
|
3
|
-
"version": "0.43.
|
|
3
|
+
"version": "0.43.10",
|
|
4
4
|
"description": "Markdown parser for Slidev",
|
|
5
5
|
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"js-yaml": "^4.1.0",
|
|
43
|
-
"@slidev/types": "0.43.
|
|
43
|
+
"@slidev/types": "0.43.10"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "rimraf dist && tsup src/index.ts src/core.ts src/fs.ts",
|
package/dist/chunk-HBQPSWBS.js
DELETED
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core.ts
|
|
2
|
-
var _jsyaml = require('js-yaml'); var _jsyaml2 = _interopRequireDefault(_jsyaml);
|
|
3
|
-
|
|
4
|
-
// ../../node_modules/.pnpm/@antfu+utils@0.7.6/node_modules/@antfu/utils/dist/index.mjs
|
|
5
|
-
function toArray(array) {
|
|
6
|
-
array = _nullishCoalesce(array, () => ( []));
|
|
7
|
-
return Array.isArray(array) ? array : [array];
|
|
8
|
-
}
|
|
9
|
-
function uniq(array) {
|
|
10
|
-
return Array.from(new Set(array));
|
|
11
|
-
}
|
|
12
|
-
function range(...args) {
|
|
13
|
-
let start, stop, step;
|
|
14
|
-
if (args.length === 1) {
|
|
15
|
-
start = 0;
|
|
16
|
-
step = 1;
|
|
17
|
-
[stop] = args;
|
|
18
|
-
} else {
|
|
19
|
-
[start, stop, step = 1] = args;
|
|
20
|
-
}
|
|
21
|
-
const arr = [];
|
|
22
|
-
let current = start;
|
|
23
|
-
while (current < stop) {
|
|
24
|
-
arr.push(current);
|
|
25
|
-
current += step || 1;
|
|
26
|
-
}
|
|
27
|
-
return arr;
|
|
28
|
-
}
|
|
29
|
-
var toString = (v) => Object.prototype.toString.call(v);
|
|
30
|
-
function notNullish(v) {
|
|
31
|
-
return v != null;
|
|
32
|
-
}
|
|
33
|
-
function isTruthy(v) {
|
|
34
|
-
return Boolean(v);
|
|
35
|
-
}
|
|
36
|
-
var isNumber = (val) => typeof val === "number";
|
|
37
|
-
var isObject = (val) => toString(val) === "[object Object]";
|
|
38
|
-
function objectMap(obj, fn) {
|
|
39
|
-
return Object.fromEntries(
|
|
40
|
-
Object.entries(obj).map(([k, v]) => fn(k, v)).filter(notNullish)
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
var Node = class {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
constructor(value) {
|
|
47
|
-
this.value = value;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var Queue = class {
|
|
51
|
-
#head;
|
|
52
|
-
#tail;
|
|
53
|
-
#size;
|
|
54
|
-
constructor() {
|
|
55
|
-
this.clear();
|
|
56
|
-
}
|
|
57
|
-
enqueue(value) {
|
|
58
|
-
const node = new Node(value);
|
|
59
|
-
if (this.#head) {
|
|
60
|
-
this.#tail.next = node;
|
|
61
|
-
this.#tail = node;
|
|
62
|
-
} else {
|
|
63
|
-
this.#head = node;
|
|
64
|
-
this.#tail = node;
|
|
65
|
-
}
|
|
66
|
-
this.#size++;
|
|
67
|
-
}
|
|
68
|
-
dequeue() {
|
|
69
|
-
const current = this.#head;
|
|
70
|
-
if (!current) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
this.#head = this.#head.next;
|
|
74
|
-
this.#size--;
|
|
75
|
-
return current.value;
|
|
76
|
-
}
|
|
77
|
-
clear() {
|
|
78
|
-
this.#head = void 0;
|
|
79
|
-
this.#tail = void 0;
|
|
80
|
-
this.#size = 0;
|
|
81
|
-
}
|
|
82
|
-
get size() {
|
|
83
|
-
return this.#size;
|
|
84
|
-
}
|
|
85
|
-
*[Symbol.iterator]() {
|
|
86
|
-
let current = this.#head;
|
|
87
|
-
while (current) {
|
|
88
|
-
yield current.value;
|
|
89
|
-
current = current.next;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
var VOID = Symbol("p-void");
|
|
94
|
-
|
|
95
|
-
// src/utils.ts
|
|
96
|
-
function parseRangeString(total, rangeStr) {
|
|
97
|
-
if (!rangeStr || rangeStr === "all" || rangeStr === "*")
|
|
98
|
-
return range(1, total + 1);
|
|
99
|
-
const pages = [];
|
|
100
|
-
for (const part of rangeStr.split(/[,;]/g)) {
|
|
101
|
-
if (!part.includes("-")) {
|
|
102
|
-
pages.push(+part);
|
|
103
|
-
} else {
|
|
104
|
-
const [start, end] = part.split("-", 2);
|
|
105
|
-
pages.push(
|
|
106
|
-
...range(+start, !end ? total + 1 : +end + 1)
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return uniq(pages).filter((i) => i <= total).sort((a, b) => a - b);
|
|
111
|
-
}
|
|
112
|
-
function parseAspectRatio(str) {
|
|
113
|
-
if (isNumber(str))
|
|
114
|
-
return str;
|
|
115
|
-
if (!Number.isNaN(+str))
|
|
116
|
-
return +str;
|
|
117
|
-
const [wStr = "", hStr = ""] = str.split(/[:\/x\|]/);
|
|
118
|
-
const w = Number.parseFloat(wStr.trim());
|
|
119
|
-
const h = Number.parseFloat(hStr.trim());
|
|
120
|
-
if (Number.isNaN(w) || Number.isNaN(h) || h === 0)
|
|
121
|
-
throw new Error(`Invalid aspect ratio "${str}"`);
|
|
122
|
-
return w / h;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/config.ts
|
|
126
|
-
function getDefaultConfig() {
|
|
127
|
-
return {
|
|
128
|
-
theme: "default",
|
|
129
|
-
title: "Slidev",
|
|
130
|
-
titleTemplate: "%s - Slidev",
|
|
131
|
-
addons: [],
|
|
132
|
-
remoteAssets: false,
|
|
133
|
-
monaco: "dev",
|
|
134
|
-
download: false,
|
|
135
|
-
export: {},
|
|
136
|
-
info: false,
|
|
137
|
-
highlighter: "prism",
|
|
138
|
-
lineNumbers: false,
|
|
139
|
-
colorSchema: "auto",
|
|
140
|
-
routerMode: "history",
|
|
141
|
-
aspectRatio: 16 / 9,
|
|
142
|
-
canvasWidth: 980,
|
|
143
|
-
exportFilename: "",
|
|
144
|
-
selectable: false,
|
|
145
|
-
themeConfig: {},
|
|
146
|
-
fonts: {},
|
|
147
|
-
favicon: "https://cdn.jsdelivr.net/gh/slidevjs/slidev/assets/favicon.png",
|
|
148
|
-
drawings: {},
|
|
149
|
-
plantUmlServer: "https://www.plantuml.com/plantuml",
|
|
150
|
-
codeCopy: true,
|
|
151
|
-
record: "dev",
|
|
152
|
-
css: "unocss",
|
|
153
|
-
presenter: true,
|
|
154
|
-
htmlAttrs: {},
|
|
155
|
-
transition: void 0,
|
|
156
|
-
editor: true
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
|
|
160
|
-
const themeHightlighter = ["prism", "shiki"].includes(themeMeta.highlighter || "") ? themeMeta.highlighter : void 0;
|
|
161
|
-
const themeColorSchema = ["light", "dark"].includes(themeMeta.colorSchema || "") ? themeMeta.colorSchema : void 0;
|
|
162
|
-
const defaultConfig = getDefaultConfig();
|
|
163
|
-
const config = {
|
|
164
|
-
...defaultConfig,
|
|
165
|
-
highlighter: themeHightlighter || defaultConfig.highlighter,
|
|
166
|
-
colorSchema: themeColorSchema || defaultConfig.colorSchema,
|
|
167
|
-
...themeMeta.defaults,
|
|
168
|
-
...headmatter.config,
|
|
169
|
-
...headmatter,
|
|
170
|
-
fonts: resolveFonts({
|
|
171
|
-
..._optionalChain([themeMeta, 'access', _2 => _2.defaults, 'optionalAccess', _3 => _3.fonts]),
|
|
172
|
-
..._optionalChain([headmatter, 'access', _4 => _4.config, 'optionalAccess', _5 => _5.fonts]),
|
|
173
|
-
..._optionalChain([headmatter, 'optionalAccess', _6 => _6.fonts])
|
|
174
|
-
}),
|
|
175
|
-
drawings: resolveDrawings(headmatter.drawings, filepath),
|
|
176
|
-
htmlAttrs: {
|
|
177
|
-
..._optionalChain([themeMeta, 'access', _7 => _7.defaults, 'optionalAccess', _8 => _8.htmlAttrs]),
|
|
178
|
-
..._optionalChain([headmatter, 'access', _9 => _9.config, 'optionalAccess', _10 => _10.htmlAttrs]),
|
|
179
|
-
..._optionalChain([headmatter, 'optionalAccess', _11 => _11.htmlAttrs])
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
if (config.colorSchema !== "dark" && config.colorSchema !== "light")
|
|
183
|
-
config.colorSchema = "auto";
|
|
184
|
-
if (themeColorSchema && config.colorSchema === "auto")
|
|
185
|
-
config.colorSchema = themeColorSchema;
|
|
186
|
-
config.aspectRatio = parseAspectRatio(config.aspectRatio);
|
|
187
|
-
if (verify)
|
|
188
|
-
verifyConfig(config, themeMeta);
|
|
189
|
-
return config;
|
|
190
|
-
}
|
|
191
|
-
function verifyConfig(config, themeMeta = {}, warn = (v) => console.warn(`[slidev] ${v}`)) {
|
|
192
|
-
const themeHightlighter = ["prism", "shiki"].includes(themeMeta.highlighter || "") ? themeMeta.highlighter : void 0;
|
|
193
|
-
const themeColorSchema = ["light", "dark"].includes(themeMeta.colorSchema || "") ? themeMeta.colorSchema : void 0;
|
|
194
|
-
if (themeColorSchema && config.colorSchema !== themeColorSchema)
|
|
195
|
-
warn(`Color schema "${config.colorSchema}" does not supported by the theme`);
|
|
196
|
-
if (themeHightlighter && config.highlighter !== themeHightlighter)
|
|
197
|
-
warn(`Syntax highlighter "${config.highlighter}" does not supported by the theme`);
|
|
198
|
-
if (!["windicss", "unocss", void 0].includes(config.css)) {
|
|
199
|
-
warn(`Unsupported Atomic CSS engine "${config.css}", fallback to UnoCSS`);
|
|
200
|
-
config.css = "unocss";
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function resolveFonts(fonts = {}) {
|
|
204
|
-
const {
|
|
205
|
-
fallbacks = true,
|
|
206
|
-
italic = false,
|
|
207
|
-
provider = "google"
|
|
208
|
-
} = fonts;
|
|
209
|
-
let sans = toArray(fonts.sans).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
210
|
-
let serif = toArray(fonts.serif).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
211
|
-
let mono = toArray(fonts.mono).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
212
|
-
const weights = toArray(fonts.weights || "200,400,600").flatMap((i) => i.toString().split(/,\s*/g)).map((i) => i.trim());
|
|
213
|
-
const custom = toArray(fonts.custom).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
214
|
-
const local = toArray(fonts.local).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
215
|
-
const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ? uniq([...sans, ...serif, ...mono, ...custom]) : [];
|
|
216
|
-
webfonts.filter((i) => local.includes(i));
|
|
217
|
-
function toQuoted(font) {
|
|
218
|
-
if (/^(['"]).*\1$/.test(font))
|
|
219
|
-
return font;
|
|
220
|
-
return `"${font}"`;
|
|
221
|
-
}
|
|
222
|
-
if (fallbacks) {
|
|
223
|
-
sans = uniq([
|
|
224
|
-
...sans.map(toQuoted),
|
|
225
|
-
"ui-sans-serif",
|
|
226
|
-
"system-ui",
|
|
227
|
-
"-apple-system",
|
|
228
|
-
"BlinkMacSystemFont",
|
|
229
|
-
'"Segoe UI"',
|
|
230
|
-
"Roboto",
|
|
231
|
-
'"Helvetica Neue"',
|
|
232
|
-
"Arial",
|
|
233
|
-
'"Noto Sans"',
|
|
234
|
-
"sans-serif",
|
|
235
|
-
'"Apple Color Emoji"',
|
|
236
|
-
'"Segoe UI Emoji"',
|
|
237
|
-
'"Segoe UI Symbol"',
|
|
238
|
-
'"Noto Color Emoji"'
|
|
239
|
-
]);
|
|
240
|
-
serif = uniq([
|
|
241
|
-
...serif.map(toQuoted),
|
|
242
|
-
"ui-serif",
|
|
243
|
-
"Georgia",
|
|
244
|
-
"Cambria",
|
|
245
|
-
'"Times New Roman"',
|
|
246
|
-
"Times",
|
|
247
|
-
"serif"
|
|
248
|
-
]);
|
|
249
|
-
mono = uniq([
|
|
250
|
-
...mono.map(toQuoted),
|
|
251
|
-
"ui-monospace",
|
|
252
|
-
"SFMono-Regular",
|
|
253
|
-
"Menlo",
|
|
254
|
-
"Monaco",
|
|
255
|
-
"Consolas",
|
|
256
|
-
'"Liberation Mono"',
|
|
257
|
-
'"Courier New"',
|
|
258
|
-
"monospace"
|
|
259
|
-
]);
|
|
260
|
-
}
|
|
261
|
-
return {
|
|
262
|
-
sans,
|
|
263
|
-
serif,
|
|
264
|
-
mono,
|
|
265
|
-
webfonts,
|
|
266
|
-
provider,
|
|
267
|
-
local,
|
|
268
|
-
italic,
|
|
269
|
-
weights
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
function resolveDrawings(options = {}, filepath) {
|
|
273
|
-
const {
|
|
274
|
-
enabled = true,
|
|
275
|
-
persist = false,
|
|
276
|
-
presenterOnly = false,
|
|
277
|
-
syncAll = true
|
|
278
|
-
} = options;
|
|
279
|
-
const persistPath = typeof persist === "string" ? persist : persist ? `.slidev/drawings${filepath ? `/${_optionalChain([filepath, 'access', _12 => _12.match, 'call', _13 => _13(/([^\\\/]+?)(\.\w+)?$/), 'optionalAccess', _14 => _14[1]])}` : ""}` : false;
|
|
280
|
-
return {
|
|
281
|
-
enabled,
|
|
282
|
-
persist: persistPath,
|
|
283
|
-
presenterOnly,
|
|
284
|
-
syncAll
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// src/core.ts
|
|
289
|
-
function stringify(data) {
|
|
290
|
-
return `${data.slides.filter((slide) => slide.source === void 0 || slide.inline !== void 0).map((slide, idx) => stringifySlide(slide.inline || slide, idx)).join("\n").trim()}
|
|
291
|
-
`;
|
|
292
|
-
}
|
|
293
|
-
function filterDisabled(data) {
|
|
294
|
-
data.slides = data.slides.filter((i) => !_optionalChain([i, 'access', _15 => _15.frontmatter, 'optionalAccess', _16 => _16.disabled]));
|
|
295
|
-
return data;
|
|
296
|
-
}
|
|
297
|
-
function stringifySlide(data, idx = 0) {
|
|
298
|
-
if (data.raw == null)
|
|
299
|
-
prettifySlide(data);
|
|
300
|
-
return data.raw.startsWith("---") || idx === 0 ? data.raw : `---
|
|
301
|
-
${data.raw.startsWith("\n") ? data.raw : `
|
|
302
|
-
${data.raw}`}`;
|
|
303
|
-
}
|
|
304
|
-
function prettifySlide(data) {
|
|
305
|
-
data.content = `
|
|
306
|
-
${data.content.trim()}
|
|
307
|
-
`;
|
|
308
|
-
data.raw = Object.keys(data.frontmatter || {}).length ? `---
|
|
309
|
-
${_jsyaml2.default.dump(data.frontmatter).trim()}
|
|
310
|
-
---
|
|
311
|
-
${data.content}` : data.content;
|
|
312
|
-
if (data.note)
|
|
313
|
-
data.raw += `
|
|
314
|
-
<!--
|
|
315
|
-
${data.note.trim()}
|
|
316
|
-
-->
|
|
317
|
-
`;
|
|
318
|
-
else
|
|
319
|
-
data.raw += "\n";
|
|
320
|
-
return data;
|
|
321
|
-
}
|
|
322
|
-
function prettify(data) {
|
|
323
|
-
data.slides.forEach(prettifySlide);
|
|
324
|
-
return data;
|
|
325
|
-
}
|
|
326
|
-
function matter(code) {
|
|
327
|
-
let data = {};
|
|
328
|
-
const content = code.replace(
|
|
329
|
-
/^---.*\r?\n([\s\S]*?)---/,
|
|
330
|
-
(_, d) => {
|
|
331
|
-
data = _jsyaml2.default.load(d);
|
|
332
|
-
if (!isObject(data))
|
|
333
|
-
data = {};
|
|
334
|
-
return "";
|
|
335
|
-
}
|
|
336
|
-
);
|
|
337
|
-
return { data, content };
|
|
338
|
-
}
|
|
339
|
-
function detectFeatures(code) {
|
|
340
|
-
return {
|
|
341
|
-
katex: !!code.match(/\$.*?\$/) || !!code.match(/$\$\$/),
|
|
342
|
-
monaco: !!code.match(/{monaco.*}/),
|
|
343
|
-
tweet: !!code.match(/<Tweet\b/),
|
|
344
|
-
mermaid: !!code.match(/^```mermaid/m)
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
function parseSlide(raw) {
|
|
348
|
-
const result = matter(raw);
|
|
349
|
-
let note;
|
|
350
|
-
const frontmatter = result.data || {};
|
|
351
|
-
let content = result.content.trim();
|
|
352
|
-
const comments = Array.from(content.matchAll(/<!--([\s\S]*?)-->/g));
|
|
353
|
-
if (comments.length) {
|
|
354
|
-
const last = comments[comments.length - 1];
|
|
355
|
-
if (last.index !== void 0 && last.index + last[0].length >= content.length) {
|
|
356
|
-
note = last[1].trim();
|
|
357
|
-
content = content.slice(0, last.index).trim();
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
let title;
|
|
361
|
-
let level;
|
|
362
|
-
if (frontmatter.title || frontmatter.name) {
|
|
363
|
-
title = frontmatter.title || frontmatter.name;
|
|
364
|
-
} else {
|
|
365
|
-
const match = content.match(/^(#+) (.*)$/m);
|
|
366
|
-
title = _optionalChain([match, 'optionalAccess', _17 => _17[2], 'optionalAccess', _18 => _18.trim, 'call', _19 => _19()]);
|
|
367
|
-
level = _optionalChain([match, 'optionalAccess', _20 => _20[1], 'optionalAccess', _21 => _21.length]);
|
|
368
|
-
}
|
|
369
|
-
if (frontmatter.level)
|
|
370
|
-
level = frontmatter.level || 1;
|
|
371
|
-
return {
|
|
372
|
-
raw,
|
|
373
|
-
title,
|
|
374
|
-
level,
|
|
375
|
-
content,
|
|
376
|
-
frontmatter,
|
|
377
|
-
note
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
async function parse(markdown, filepath, themeMeta, extensions, onHeadmatter) {
|
|
381
|
-
const lines = markdown.split(/\r?\n/g);
|
|
382
|
-
const slides = [];
|
|
383
|
-
let start = 0;
|
|
384
|
-
async function slice(end) {
|
|
385
|
-
if (start === end)
|
|
386
|
-
return;
|
|
387
|
-
const raw = lines.slice(start, end).join("\n");
|
|
388
|
-
const slide = {
|
|
389
|
-
...parseSlide(raw),
|
|
390
|
-
index: slides.length,
|
|
391
|
-
start,
|
|
392
|
-
end
|
|
393
|
-
};
|
|
394
|
-
if (extensions) {
|
|
395
|
-
for (const e of extensions) {
|
|
396
|
-
if (e.transformSlide) {
|
|
397
|
-
const newContent = await e.transformSlide(slide.content, slide.frontmatter);
|
|
398
|
-
if (newContent !== void 0)
|
|
399
|
-
slide.content = newContent;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
slides.push(slide);
|
|
404
|
-
start = end + 1;
|
|
405
|
-
}
|
|
406
|
-
{
|
|
407
|
-
let hm = "";
|
|
408
|
-
if (lines[0].match(/^---([^-].*)?$/) && !_optionalChain([lines, 'access', _22 => _22[1], 'optionalAccess', _23 => _23.match, 'call', _24 => _24(/^\s*$/)])) {
|
|
409
|
-
let hEnd = 1;
|
|
410
|
-
while (hEnd < lines.length && !lines[hEnd].trimEnd().match(/^---$/))
|
|
411
|
-
hEnd++;
|
|
412
|
-
hm = lines.slice(1, hEnd).join("\n");
|
|
413
|
-
}
|
|
414
|
-
if (onHeadmatter) {
|
|
415
|
-
const o = _nullishCoalesce(_jsyaml2.default.load(hm), () => ( {}));
|
|
416
|
-
extensions = await onHeadmatter(o, _nullishCoalesce(extensions, () => ( [])), filepath);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
if (extensions) {
|
|
420
|
-
for (const e of extensions) {
|
|
421
|
-
if (e.transformRawLines)
|
|
422
|
-
await e.transformRawLines(lines);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
for (let i = 0; i < lines.length; i++) {
|
|
426
|
-
const line = lines[i].trimEnd();
|
|
427
|
-
if (line.match(/^---+/)) {
|
|
428
|
-
await slice(i);
|
|
429
|
-
const next = lines[i + 1];
|
|
430
|
-
if (line.match(/^---([^-].*)?$/) && !_optionalChain([next, 'optionalAccess', _25 => _25.match, 'call', _26 => _26(/^\s*$/)])) {
|
|
431
|
-
start = i;
|
|
432
|
-
for (i += 1; i < lines.length; i++) {
|
|
433
|
-
if (lines[i].trimEnd().match(/^---$/))
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
} else if (line.startsWith("```")) {
|
|
438
|
-
for (i += 1; i < lines.length; i++) {
|
|
439
|
-
if (lines[i].startsWith("```"))
|
|
440
|
-
break;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
if (start <= lines.length - 1)
|
|
445
|
-
await slice(lines.length);
|
|
446
|
-
const headmatter = _optionalChain([slides, 'access', _27 => _27[0], 'optionalAccess', _28 => _28.frontmatter]) || {};
|
|
447
|
-
headmatter.title = headmatter.title || _optionalChain([slides, 'access', _29 => _29[0], 'optionalAccess', _30 => _30.title]);
|
|
448
|
-
const config = resolveConfig(headmatter, themeMeta, filepath);
|
|
449
|
-
const features = detectFeatures(markdown);
|
|
450
|
-
return {
|
|
451
|
-
raw: markdown,
|
|
452
|
-
filepath,
|
|
453
|
-
slides,
|
|
454
|
-
config,
|
|
455
|
-
features,
|
|
456
|
-
headmatter,
|
|
457
|
-
themeMeta
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
function mergeFeatureFlags(a, b) {
|
|
461
|
-
return objectMap(a, (k, v) => [k, v || b[k]]);
|
|
462
|
-
}
|
|
463
|
-
function scanMonacoModules(md) {
|
|
464
|
-
const typeModules = /* @__PURE__ */ new Set();
|
|
465
|
-
md.replace(/^```(\w+?)\s*{monaco([\w:,-]*)}[\s\n]*([\s\S]+?)^```/mg, (full, lang = "ts", options, code) => {
|
|
466
|
-
options = options || "";
|
|
467
|
-
lang = lang.trim();
|
|
468
|
-
if (lang === "ts" || lang === "typescript") {
|
|
469
|
-
Array.from(code.matchAll(/\s+from\s+(["'])([\/\w@-]+)\1/g)).map((i) => i[2]).filter(isTruthy).map((i) => typeModules.add(i));
|
|
470
|
-
}
|
|
471
|
-
return "";
|
|
472
|
-
});
|
|
473
|
-
return Array.from(typeModules);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
exports.parseRangeString = parseRangeString; exports.parseAspectRatio = parseAspectRatio; exports.getDefaultConfig = getDefaultConfig; exports.resolveConfig = resolveConfig; exports.verifyConfig = verifyConfig; exports.resolveFonts = resolveFonts; exports.stringify = stringify; exports.filterDisabled = filterDisabled; exports.stringifySlide = stringifySlide; exports.prettifySlide = prettifySlide; exports.prettify = prettify; exports.detectFeatures = detectFeatures; exports.parseSlide = parseSlide; exports.parse = parse; exports.mergeFeatureFlags = mergeFeatureFlags; exports.scanMonacoModules = scanMonacoModules;
|
package/dist/core.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { SlidevConfig, SlidevThemeMeta, FontOptions, ResolvedFontOptions, SlidevMarkdown, SlideInfoBase, SlidevFeatureFlags, SlidevPreparserExtension, PreparserExtensionFromHeadmatter } from '@slidev/types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 1,3-5,8 => [1, 3, 4, 5, 8]
|
|
5
|
-
*/
|
|
6
|
-
declare function parseRangeString(total: number, rangeStr?: string): number[];
|
|
7
|
-
/**
|
|
8
|
-
* Accepts `16/9` `1:1` `3x4`
|
|
9
|
-
*/
|
|
10
|
-
declare function parseAspectRatio(str: string | number): number;
|
|
11
|
-
|
|
12
|
-
declare function getDefaultConfig(): SlidevConfig;
|
|
13
|
-
declare function resolveConfig(headmatter: any, themeMeta?: SlidevThemeMeta, filepath?: string, verify?: boolean): SlidevConfig;
|
|
14
|
-
declare function verifyConfig(config: SlidevConfig, themeMeta?: SlidevThemeMeta, warn?: (v: string) => void): void;
|
|
15
|
-
declare function resolveFonts(fonts?: FontOptions): ResolvedFontOptions;
|
|
16
|
-
|
|
17
|
-
declare function stringify(data: SlidevMarkdown): string;
|
|
18
|
-
declare function filterDisabled(data: SlidevMarkdown): SlidevMarkdown;
|
|
19
|
-
declare function stringifySlide(data: SlideInfoBase, idx?: number): string;
|
|
20
|
-
declare function prettifySlide(data: SlideInfoBase): SlideInfoBase;
|
|
21
|
-
declare function prettify(data: SlidevMarkdown): SlidevMarkdown;
|
|
22
|
-
declare function detectFeatures(code: string): SlidevFeatureFlags;
|
|
23
|
-
declare function parseSlide(raw: string): SlideInfoBase;
|
|
24
|
-
declare function parse(markdown: string, filepath?: string, themeMeta?: SlidevThemeMeta, extensions?: SlidevPreparserExtension[], onHeadmatter?: PreparserExtensionFromHeadmatter): Promise<SlidevMarkdown>;
|
|
25
|
-
declare function mergeFeatureFlags(a: SlidevFeatureFlags, b: SlidevFeatureFlags): SlidevFeatureFlags;
|
|
26
|
-
declare function scanMonacoModules(md: string): string[];
|
|
27
|
-
|
|
28
|
-
export { detectFeatures, filterDisabled, getDefaultConfig, mergeFeatureFlags, parse, parseAspectRatio, parseRangeString, parseSlide, prettify, prettifySlide, resolveConfig, resolveFonts, scanMonacoModules, stringify, stringifySlide, verifyConfig };
|
package/dist/core.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _chunkHBQPSWBSjs = require('./chunk-HBQPSWBS.js');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
exports.detectFeatures = _chunkHBQPSWBSjs.detectFeatures; exports.filterDisabled = _chunkHBQPSWBSjs.filterDisabled; exports.getDefaultConfig = _chunkHBQPSWBSjs.getDefaultConfig; exports.mergeFeatureFlags = _chunkHBQPSWBSjs.mergeFeatureFlags; exports.parse = _chunkHBQPSWBSjs.parse; exports.parseAspectRatio = _chunkHBQPSWBSjs.parseAspectRatio; exports.parseRangeString = _chunkHBQPSWBSjs.parseRangeString; exports.parseSlide = _chunkHBQPSWBSjs.parseSlide; exports.prettify = _chunkHBQPSWBSjs.prettify; exports.prettifySlide = _chunkHBQPSWBSjs.prettifySlide; exports.resolveConfig = _chunkHBQPSWBSjs.resolveConfig; exports.resolveFonts = _chunkHBQPSWBSjs.resolveFonts; exports.scanMonacoModules = _chunkHBQPSWBSjs.scanMonacoModules; exports.stringify = _chunkHBQPSWBSjs.stringify; exports.stringifySlide = _chunkHBQPSWBSjs.stringifySlide; exports.verifyConfig = _chunkHBQPSWBSjs.verifyConfig;
|
package/dist/fs.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PreparserExtensionLoader, SlidevThemeMeta, SlidevMarkdown, SlideInfoWithPath } from '@slidev/types';
|
|
2
|
-
export { detectFeatures, filterDisabled, getDefaultConfig, mergeFeatureFlags, parse, parseAspectRatio, parseRangeString, parseSlide, prettify, prettifySlide, resolveConfig, resolveFonts, scanMonacoModules, stringify, stringifySlide, verifyConfig } from './core.js';
|
|
3
|
-
|
|
4
|
-
declare function injectPreparserExtensionLoader(fn: PreparserExtensionLoader): void;
|
|
5
|
-
declare function load(filepath: string, themeMeta?: SlidevThemeMeta, content?: string): Promise<SlidevMarkdown>;
|
|
6
|
-
declare function save(data: SlidevMarkdown, filepath?: string): Promise<void>;
|
|
7
|
-
declare function saveExternalSlide(slide: SlideInfoWithPath): Promise<void>;
|
|
8
|
-
|
|
9
|
-
export { injectPreparserExtensionLoader, load, save, saveExternalSlide };
|
package/dist/fs.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _chunkHBQPSWBSjs = require('./chunk-HBQPSWBS.js');
|
|
19
|
-
|
|
20
|
-
// src/fs.ts
|
|
21
|
-
var _fs = require('fs');
|
|
22
|
-
var _path = require('path');
|
|
23
|
-
var preparserExtensionLoader = null;
|
|
24
|
-
function injectPreparserExtensionLoader(fn) {
|
|
25
|
-
preparserExtensionLoader = fn;
|
|
26
|
-
}
|
|
27
|
-
async function load(filepath, themeMeta, content) {
|
|
28
|
-
const dir = _path.dirname.call(void 0, filepath);
|
|
29
|
-
const markdown = await _asyncNullishCoalesce(content, async () => ( await _fs.promises.readFile(filepath, "utf-8")));
|
|
30
|
-
const preparserExtensions = [];
|
|
31
|
-
const data = await _chunkHBQPSWBSjs.parse.call(void 0, markdown, filepath, themeMeta, [], async (headmatter, exts, filepath2) => {
|
|
32
|
-
preparserExtensions.splice(
|
|
33
|
-
0,
|
|
34
|
-
preparserExtensions.length,
|
|
35
|
-
...exts,
|
|
36
|
-
...preparserExtensionLoader ? await preparserExtensionLoader(headmatter, filepath2) : []
|
|
37
|
-
);
|
|
38
|
-
return preparserExtensions;
|
|
39
|
-
});
|
|
40
|
-
const entries = /* @__PURE__ */ new Set([
|
|
41
|
-
filepath
|
|
42
|
-
]);
|
|
43
|
-
for (let iSlide = 0; iSlide < data.slides.length; ) {
|
|
44
|
-
const baseSlide = data.slides[iSlide];
|
|
45
|
-
if (!baseSlide.frontmatter.src) {
|
|
46
|
-
iSlide++;
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
data.slides.splice(iSlide, 1);
|
|
50
|
-
if (baseSlide.frontmatter.hide)
|
|
51
|
-
continue;
|
|
52
|
-
const srcExpression = baseSlide.frontmatter.src;
|
|
53
|
-
let path;
|
|
54
|
-
if (srcExpression.startsWith("/"))
|
|
55
|
-
path = _path.resolve.call(void 0, dir, srcExpression.substring(1));
|
|
56
|
-
else if (_optionalChain([baseSlide, 'access', _ => _.source, 'optionalAccess', _2 => _2.filepath]))
|
|
57
|
-
path = _path.resolve.call(void 0, _path.dirname.call(void 0, baseSlide.source.filepath), srcExpression);
|
|
58
|
-
else
|
|
59
|
-
path = _path.resolve.call(void 0, dir, srcExpression);
|
|
60
|
-
const raw = await _fs.promises.readFile(path, "utf-8");
|
|
61
|
-
const subSlides = await _chunkHBQPSWBSjs.parse.call(void 0, raw, path, themeMeta, preparserExtensions);
|
|
62
|
-
for (const [offset, subSlide] of subSlides.slides.entries()) {
|
|
63
|
-
const slide = { ...baseSlide };
|
|
64
|
-
slide.source = {
|
|
65
|
-
filepath: path,
|
|
66
|
-
...subSlide
|
|
67
|
-
};
|
|
68
|
-
if (offset === 0 && !baseSlide.frontmatter.srcSequence) {
|
|
69
|
-
slide.inline = { ...baseSlide };
|
|
70
|
-
delete slide.inline.frontmatter.src;
|
|
71
|
-
Object.assign(slide, slide.source, { raw: null });
|
|
72
|
-
} else {
|
|
73
|
-
Object.assign(slide, slide.source);
|
|
74
|
-
}
|
|
75
|
-
const baseSlideFrontMatterWithoutSrc = { ...baseSlide.frontmatter };
|
|
76
|
-
delete baseSlideFrontMatterWithoutSrc.src;
|
|
77
|
-
slide.frontmatter = {
|
|
78
|
-
...subSlide.frontmatter,
|
|
79
|
-
...baseSlideFrontMatterWithoutSrc,
|
|
80
|
-
srcSequence: `${baseSlide.frontmatter.srcSequence ? `${baseSlide.frontmatter.srcSequence},` : ""}${srcExpression}`
|
|
81
|
-
};
|
|
82
|
-
data.features = _chunkHBQPSWBSjs.mergeFeatureFlags.call(void 0, data.features, _chunkHBQPSWBSjs.detectFeatures.call(void 0, raw));
|
|
83
|
-
entries.add(path);
|
|
84
|
-
data.slides.splice(iSlide + offset, 0, slide);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
for (let iSlide = 0; iSlide < data.slides.length; iSlide++)
|
|
88
|
-
data.slides[iSlide].index = iSlide === 0 ? 0 : 1 + data.slides[iSlide - 1].index;
|
|
89
|
-
data.entries = Array.from(entries);
|
|
90
|
-
return data;
|
|
91
|
-
}
|
|
92
|
-
async function save(data, filepath) {
|
|
93
|
-
filepath = filepath || data.filepath;
|
|
94
|
-
await _fs.promises.writeFile(filepath, _chunkHBQPSWBSjs.stringify.call(void 0, data), "utf-8");
|
|
95
|
-
}
|
|
96
|
-
async function saveExternalSlide(slide) {
|
|
97
|
-
await _fs.promises.writeFile(slide.filepath, _chunkHBQPSWBSjs.stringifySlide.call(void 0, slide), "utf-8");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
exports.detectFeatures = _chunkHBQPSWBSjs.detectFeatures; exports.filterDisabled = _chunkHBQPSWBSjs.filterDisabled; exports.getDefaultConfig = _chunkHBQPSWBSjs.getDefaultConfig; exports.injectPreparserExtensionLoader = injectPreparserExtensionLoader; exports.load = load; exports.mergeFeatureFlags = _chunkHBQPSWBSjs.mergeFeatureFlags; exports.parse = _chunkHBQPSWBSjs.parse; exports.parseAspectRatio = _chunkHBQPSWBSjs.parseAspectRatio; exports.parseRangeString = _chunkHBQPSWBSjs.parseRangeString; exports.parseSlide = _chunkHBQPSWBSjs.parseSlide; exports.prettify = _chunkHBQPSWBSjs.prettify; exports.prettifySlide = _chunkHBQPSWBSjs.prettifySlide; exports.resolveConfig = _chunkHBQPSWBSjs.resolveConfig; exports.resolveFonts = _chunkHBQPSWBSjs.resolveFonts; exports.save = save; exports.saveExternalSlide = saveExternalSlide; exports.scanMonacoModules = _chunkHBQPSWBSjs.scanMonacoModules; exports.stringify = _chunkHBQPSWBSjs.stringify; exports.stringifySlide = _chunkHBQPSWBSjs.stringifySlide; exports.verifyConfig = _chunkHBQPSWBSjs.verifyConfig;
|
package/dist/index.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { detectFeatures, filterDisabled, getDefaultConfig, mergeFeatureFlags, parse, parseAspectRatio, parseRangeString, parseSlide, prettify, prettifySlide, resolveConfig, resolveFonts, scanMonacoModules, stringify, stringifySlide, verifyConfig } from './core.js';
|
|
2
|
-
import '@slidev/types';
|
package/dist/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _chunkHBQPSWBSjs = require('./chunk-HBQPSWBS.js');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
exports.detectFeatures = _chunkHBQPSWBSjs.detectFeatures; exports.filterDisabled = _chunkHBQPSWBSjs.filterDisabled; exports.getDefaultConfig = _chunkHBQPSWBSjs.getDefaultConfig; exports.mergeFeatureFlags = _chunkHBQPSWBSjs.mergeFeatureFlags; exports.parse = _chunkHBQPSWBSjs.parse; exports.parseAspectRatio = _chunkHBQPSWBSjs.parseAspectRatio; exports.parseRangeString = _chunkHBQPSWBSjs.parseRangeString; exports.parseSlide = _chunkHBQPSWBSjs.parseSlide; exports.prettify = _chunkHBQPSWBSjs.prettify; exports.prettifySlide = _chunkHBQPSWBSjs.prettifySlide; exports.resolveConfig = _chunkHBQPSWBSjs.resolveConfig; exports.resolveFonts = _chunkHBQPSWBSjs.resolveFonts; exports.scanMonacoModules = _chunkHBQPSWBSjs.scanMonacoModules; exports.stringify = _chunkHBQPSWBSjs.stringify; exports.stringifySlide = _chunkHBQPSWBSjs.stringifySlide; exports.verifyConfig = _chunkHBQPSWBSjs.verifyConfig;
|