@slidev/parser 0.43.14 → 0.44.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.
@@ -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 data = {};
328
- const content = code.replace(
329
- /^---.*\r?\n([\s\S]*?)---/,
330
- (_, d) => {
331
- data = YAML.load(d);
332
- if (!isObject(data))
333
- data = {};
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 { data, content };
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 result = matter(raw);
363
+ const matterResult = matter(raw);
349
364
  let note;
350
- const frontmatter = result.data || {};
351
- let content = result.content.trim();
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
@@ -15,7 +15,7 @@ import {
15
15
  stringify,
16
16
  stringifySlide,
17
17
  verifyConfig
18
- } from "./chunk-7UHTFYFF.mjs";
18
+ } from "./chunk-U4NHYXZX.mjs";
19
19
  export {
20
20
  detectFeatures,
21
21
  filterDisabled,
package/dist/fs.mjs CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  stringify,
16
16
  stringifySlide,
17
17
  verifyConfig
18
- } from "./chunk-7UHTFYFF.mjs";
18
+ } from "./chunk-U4NHYXZX.mjs";
19
19
 
20
20
  // src/fs.ts
21
21
  import { promises as fs } from "node:fs";
package/dist/index.mjs CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  stringify,
16
16
  stringifySlide,
17
17
  verifyConfig
18
- } from "./chunk-7UHTFYFF.mjs";
18
+ } from "./chunk-U4NHYXZX.mjs";
19
19
  export {
20
20
  detectFeatures,
21
21
  filterDisabled,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/parser",
3
- "version": "0.43.14",
3
+ "version": "0.44.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.14"
43
+ "@slidev/types": "0.44.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && tsup src/index.ts src/core.ts src/fs.ts",