@slidev/parser 0.43.15 → 0.45.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/{chunk-7UHTFYFF.mjs → chunk-U4NHYXZX.mjs} +30 -14
- package/dist/core.mjs +1 -1
- package/dist/fs.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -305,7 +305,10 @@ function prettifySlide(data) {
|
|
|
305
305
|
data.content = `
|
|
306
306
|
${data.content.trim()}
|
|
307
307
|
`;
|
|
308
|
-
data.raw = Object.keys(data.frontmatter || {}).length ?
|
|
308
|
+
data.raw = Object.keys(data.frontmatter || {}).length ? data.frontmatterStyle === "yaml" ? `\`\`\`yaml
|
|
309
|
+
${YAML.dump(data.frontmatter).trim()}
|
|
310
|
+
\`\`\`
|
|
311
|
+
${data.content}` : `---
|
|
309
312
|
${YAML.dump(data.frontmatter).trim()}
|
|
310
313
|
---
|
|
311
314
|
${data.content}` : data.content;
|
|
@@ -323,18 +326,30 @@ function prettify(data) {
|
|
|
323
326
|
data.slides.forEach(prettifySlide);
|
|
324
327
|
return data;
|
|
325
328
|
}
|
|
329
|
+
function safeParseYAML(str) {
|
|
330
|
+
const res = YAML.load(str);
|
|
331
|
+
return isObject(res) ? res : {};
|
|
332
|
+
}
|
|
326
333
|
function matter(code) {
|
|
327
|
-
let
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
+
let type;
|
|
335
|
+
const data = {};
|
|
336
|
+
let content = code.replace(/^---.*\r?\n([\s\S]*?)---/, (_, f) => {
|
|
337
|
+
type = "frontmatter";
|
|
338
|
+
Object.assign(data, safeParseYAML(f));
|
|
339
|
+
return "";
|
|
340
|
+
});
|
|
341
|
+
if (type !== "frontmatter") {
|
|
342
|
+
content = content.replace(/^\s*```ya?ml([\s\S]*?)```/, (_, d) => {
|
|
343
|
+
type = "yaml";
|
|
344
|
+
Object.assign(data, safeParseYAML(d));
|
|
334
345
|
return "";
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return {
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
type,
|
|
350
|
+
data,
|
|
351
|
+
content
|
|
352
|
+
};
|
|
338
353
|
}
|
|
339
354
|
function detectFeatures(code) {
|
|
340
355
|
return {
|
|
@@ -345,10 +360,10 @@ function detectFeatures(code) {
|
|
|
345
360
|
};
|
|
346
361
|
}
|
|
347
362
|
function parseSlide(raw) {
|
|
348
|
-
const
|
|
363
|
+
const matterResult = matter(raw);
|
|
349
364
|
let note;
|
|
350
|
-
const frontmatter =
|
|
351
|
-
let content =
|
|
365
|
+
const frontmatter = matterResult.data || {};
|
|
366
|
+
let content = matterResult.content.trim();
|
|
352
367
|
const comments = Array.from(content.matchAll(/<!--([\s\S]*?)-->/g));
|
|
353
368
|
if (comments.length) {
|
|
354
369
|
const last = comments[comments.length - 1];
|
|
@@ -374,6 +389,7 @@ function parseSlide(raw) {
|
|
|
374
389
|
level,
|
|
375
390
|
content,
|
|
376
391
|
frontmatter,
|
|
392
|
+
frontmatterStyle: matterResult.type,
|
|
377
393
|
note
|
|
378
394
|
};
|
|
379
395
|
}
|
package/dist/core.mjs
CHANGED
package/dist/fs.mjs
CHANGED
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slidev/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
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
|
+
"@slidev/types": "0.45.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "rimraf dist && tsup src/index.ts src/core.ts src/fs.ts",
|