@slidev/parser 0.27.20 → 0.28.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.
@@ -21,7 +21,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  // src/core.ts
22
22
  import YAML from "js-yaml";
23
23
 
24
- // ../../node_modules/.pnpm/@antfu+utils@0.3.0/node_modules/@antfu/utils/dist/index.mjs
24
+ // ../../node_modules/.pnpm/@antfu+utils@0.4.0/node_modules/@antfu/utils/dist/index.mjs
25
25
  function toArray(array) {
26
26
  array = array || [];
27
27
  if (Array.isArray(array))
@@ -48,6 +48,7 @@ function range(...args) {
48
48
  }
49
49
  return arr;
50
50
  }
51
+ var toString = (v) => Object.prototype.toString.call(v);
51
52
  function notNullish(v) {
52
53
  return v != null;
53
54
  }
@@ -55,7 +56,7 @@ function isTruthy(v) {
55
56
  return Boolean(v);
56
57
  }
57
58
  var isNumber = (val) => typeof val === "number";
58
- var isObject = (val) => toString.call(val) === "[object Object]";
59
+ var isObject = (val) => toString(val) === "[object Object]";
59
60
  function objectMap(obj, fn) {
60
61
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => fn(k, v)).filter(notNullish));
61
62
  }
@@ -287,10 +288,20 @@ function parseSlide(raw) {
287
288
  content = content.slice(0, last.index).trim();
288
289
  }
289
290
  }
290
- const title = frontmatter.title || frontmatter.name || ((_b = (_a = content.match(/^#+ (.*)$/m)) == null ? void 0 : _a[1]) == null ? void 0 : _b.trim());
291
+ let title;
292
+ let level;
293
+ if (frontmatter.title || frontmatter.name) {
294
+ title = frontmatter.title || frontmatter.name;
295
+ level = frontmatter.level || 1;
296
+ } else {
297
+ const match = content.match(/^(#+) (.*)$/m);
298
+ title = (_a = match == null ? void 0 : match[2]) == null ? void 0 : _a.trim();
299
+ level = (_b = match == null ? void 0 : match[1]) == null ? void 0 : _b.length;
300
+ }
291
301
  return {
292
302
  raw,
293
303
  title,
304
+ level,
294
305
  content,
295
306
  frontmatter,
296
307
  note
@@ -313,14 +324,14 @@ function parse(markdown, filepath, themeMeta) {
313
324
  start = end + 1;
314
325
  }
315
326
  for (let i = 0; i < lines.length; i++) {
316
- const line = lines[i].trimRight();
327
+ const line = lines[i].trimEnd();
317
328
  if (line.match(/^---+/)) {
318
329
  slice(i);
319
330
  const next = lines[i + 1];
320
331
  if (line.match(/^---([^-].*)?$/) && !(next == null ? void 0 : next.match(/^\s*$/))) {
321
332
  start = i;
322
333
  for (i += 1; i < lines.length; i++) {
323
- if (lines[i].trimRight().match(/^---$/))
334
+ if (lines[i].trimEnd().match(/^---$/))
324
335
  break;
325
336
  }
326
337
  }
@@ -21,7 +21,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  // src/core.ts
22
22
  var _jsyaml = require('js-yaml'); var _jsyaml2 = _interopRequireDefault(_jsyaml);
23
23
 
24
- // ../../node_modules/.pnpm/@antfu+utils@0.3.0/node_modules/@antfu/utils/dist/index.mjs
24
+ // ../../node_modules/.pnpm/@antfu+utils@0.4.0/node_modules/@antfu/utils/dist/index.mjs
25
25
  function toArray(array) {
26
26
  array = array || [];
27
27
  if (Array.isArray(array))
@@ -48,6 +48,7 @@ function range(...args) {
48
48
  }
49
49
  return arr;
50
50
  }
51
+ var toString = (v) => Object.prototype.toString.call(v);
51
52
  function notNullish(v) {
52
53
  return v != null;
53
54
  }
@@ -55,7 +56,7 @@ function isTruthy(v) {
55
56
  return Boolean(v);
56
57
  }
57
58
  var isNumber = (val) => typeof val === "number";
58
- var isObject = (val) => toString.call(val) === "[object Object]";
59
+ var isObject = (val) => toString(val) === "[object Object]";
59
60
  function objectMap(obj, fn) {
60
61
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => fn(k, v)).filter(notNullish));
61
62
  }
@@ -287,10 +288,20 @@ function parseSlide(raw) {
287
288
  content = content.slice(0, last.index).trim();
288
289
  }
289
290
  }
290
- const title = frontmatter.title || frontmatter.name || ((_b = (_a = content.match(/^#+ (.*)$/m)) == null ? void 0 : _a[1]) == null ? void 0 : _b.trim());
291
+ let title;
292
+ let level;
293
+ if (frontmatter.title || frontmatter.name) {
294
+ title = frontmatter.title || frontmatter.name;
295
+ level = frontmatter.level || 1;
296
+ } else {
297
+ const match = content.match(/^(#+) (.*)$/m);
298
+ title = (_a = match == null ? void 0 : match[2]) == null ? void 0 : _a.trim();
299
+ level = (_b = match == null ? void 0 : match[1]) == null ? void 0 : _b.length;
300
+ }
291
301
  return {
292
302
  raw,
293
303
  title,
304
+ level,
294
305
  content,
295
306
  frontmatter,
296
307
  note
@@ -313,14 +324,14 @@ function parse(markdown, filepath, themeMeta) {
313
324
  start = end + 1;
314
325
  }
315
326
  for (let i = 0; i < lines.length; i++) {
316
- const line = lines[i].trimRight();
327
+ const line = lines[i].trimEnd();
317
328
  if (line.match(/^---+/)) {
318
329
  slice(i);
319
330
  const next = lines[i + 1];
320
331
  if (line.match(/^---([^-].*)?$/) && !(next == null ? void 0 : next.match(/^\s*$/))) {
321
332
  start = i;
322
333
  for (i += 1; i < lines.length; i++) {
323
- if (lines[i].trimRight().match(/^---$/))
334
+ if (lines[i].trimEnd().match(/^---$/))
324
335
  break;
325
336
  }
326
337
  }
package/dist/core.js CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
 
15
15
 
16
- var _chunkVFP6MEJGjs = require('./chunk-VFP6MEJG.js');
16
+ var _chunkWBX4FRCIjs = require('./chunk-WBX4FRCI.js');
17
17
 
18
18
 
19
19
 
@@ -29,4 +29,4 @@ var _chunkVFP6MEJGjs = require('./chunk-VFP6MEJG.js');
29
29
 
30
30
 
31
31
 
32
- exports.detectFeatures = _chunkVFP6MEJGjs.detectFeatures; exports.filterDisabled = _chunkVFP6MEJGjs.filterDisabled; exports.mergeFeatureFlags = _chunkVFP6MEJGjs.mergeFeatureFlags; exports.parse = _chunkVFP6MEJGjs.parse; exports.parseAspectRatio = _chunkVFP6MEJGjs.parseAspectRatio; exports.parseRangeString = _chunkVFP6MEJGjs.parseRangeString; exports.parseSlide = _chunkVFP6MEJGjs.parseSlide; exports.prettify = _chunkVFP6MEJGjs.prettify; exports.prettifySlide = _chunkVFP6MEJGjs.prettifySlide; exports.resolveConfig = _chunkVFP6MEJGjs.resolveConfig; exports.resolveFonts = _chunkVFP6MEJGjs.resolveFonts; exports.scanMonacoModules = _chunkVFP6MEJGjs.scanMonacoModules; exports.stringify = _chunkVFP6MEJGjs.stringify; exports.stringifySlide = _chunkVFP6MEJGjs.stringifySlide;
32
+ exports.detectFeatures = _chunkWBX4FRCIjs.detectFeatures; exports.filterDisabled = _chunkWBX4FRCIjs.filterDisabled; exports.mergeFeatureFlags = _chunkWBX4FRCIjs.mergeFeatureFlags; exports.parse = _chunkWBX4FRCIjs.parse; exports.parseAspectRatio = _chunkWBX4FRCIjs.parseAspectRatio; exports.parseRangeString = _chunkWBX4FRCIjs.parseRangeString; exports.parseSlide = _chunkWBX4FRCIjs.parseSlide; exports.prettify = _chunkWBX4FRCIjs.prettify; exports.prettifySlide = _chunkWBX4FRCIjs.prettifySlide; exports.resolveConfig = _chunkWBX4FRCIjs.resolveConfig; exports.resolveFonts = _chunkWBX4FRCIjs.resolveFonts; exports.scanMonacoModules = _chunkWBX4FRCIjs.scanMonacoModules; exports.stringify = _chunkWBX4FRCIjs.stringify; exports.stringifySlide = _chunkWBX4FRCIjs.stringifySlide;
package/dist/core.mjs CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  scanMonacoModules,
14
14
  stringify,
15
15
  stringifySlide
16
- } from "./chunk-4LEQMYU6.mjs";
16
+ } from "./chunk-HINA34KW.mjs";
17
17
  export {
18
18
  detectFeatures,
19
19
  filterDisabled,
package/dist/fs.js CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
 
16
16
 
17
- var _chunkVFP6MEJGjs = require('./chunk-VFP6MEJG.js');
17
+ var _chunkWBX4FRCIjs = require('./chunk-WBX4FRCI.js');
18
18
 
19
19
  // src/fs.ts
20
20
  var _fs = require('fs');
@@ -22,7 +22,7 @@ var _path = require('path');
22
22
  async function load(filepath, themeMeta, content) {
23
23
  const dir = _path.dirname.call(void 0, filepath);
24
24
  const markdown = content != null ? content : await _fs.promises.readFile(filepath, "utf-8");
25
- const data = _chunkVFP6MEJGjs.parse.call(void 0, markdown, filepath, themeMeta);
25
+ const data = _chunkWBX4FRCIjs.parse.call(void 0, markdown, filepath, themeMeta);
26
26
  const entries = /* @__PURE__ */ new Set([
27
27
  filepath
28
28
  ]);
@@ -31,15 +31,15 @@ async function load(filepath, themeMeta, content) {
31
31
  continue;
32
32
  const path = _path.resolve.call(void 0, dir, slide.frontmatter.src);
33
33
  const raw = await _fs.promises.readFile(path, "utf-8");
34
- const source = _chunkVFP6MEJGjs.parseSlide.call(void 0, raw);
35
- const inline = _chunkVFP6MEJGjs.__spreadValues.call(void 0, {}, slide);
36
- slide.source = _chunkVFP6MEJGjs.__spreadValues.call(void 0, {
34
+ const source = _chunkWBX4FRCIjs.parseSlide.call(void 0, raw);
35
+ const inline = _chunkWBX4FRCIjs.__spreadValues.call(void 0, {}, slide);
36
+ slide.source = _chunkWBX4FRCIjs.__spreadValues.call(void 0, {
37
37
  filepath: path
38
38
  }, source);
39
39
  slide.inline = inline;
40
40
  Object.assign(slide, slide.source);
41
- slide.frontmatter = _chunkVFP6MEJGjs.__spreadValues.call(void 0, _chunkVFP6MEJGjs.__spreadValues.call(void 0, {}, slide.source.frontmatter), inline.frontmatter);
42
- data.features = _chunkVFP6MEJGjs.mergeFeatureFlags.call(void 0, data.features, _chunkVFP6MEJGjs.detectFeatures.call(void 0, raw));
41
+ slide.frontmatter = _chunkWBX4FRCIjs.__spreadValues.call(void 0, _chunkWBX4FRCIjs.__spreadValues.call(void 0, {}, slide.source.frontmatter), inline.frontmatter);
42
+ data.features = _chunkWBX4FRCIjs.mergeFeatureFlags.call(void 0, data.features, _chunkWBX4FRCIjs.detectFeatures.call(void 0, raw));
43
43
  entries.add(path);
44
44
  }
45
45
  data.entries = Array.from(entries);
@@ -47,10 +47,10 @@ async function load(filepath, themeMeta, content) {
47
47
  }
48
48
  async function save(data, filepath) {
49
49
  filepath = filepath || data.filepath;
50
- await _fs.promises.writeFile(filepath, _chunkVFP6MEJGjs.stringify.call(void 0, data), "utf-8");
50
+ await _fs.promises.writeFile(filepath, _chunkWBX4FRCIjs.stringify.call(void 0, data), "utf-8");
51
51
  }
52
52
  async function saveExternalSlide(slide) {
53
- await _fs.promises.writeFile(slide.filepath, _chunkVFP6MEJGjs.stringifySlide.call(void 0, slide), "utf-8");
53
+ await _fs.promises.writeFile(slide.filepath, _chunkWBX4FRCIjs.stringifySlide.call(void 0, slide), "utf-8");
54
54
  }
55
55
 
56
56
 
@@ -70,4 +70,4 @@ async function saveExternalSlide(slide) {
70
70
 
71
71
 
72
72
 
73
- exports.detectFeatures = _chunkVFP6MEJGjs.detectFeatures; exports.filterDisabled = _chunkVFP6MEJGjs.filterDisabled; exports.load = load; exports.mergeFeatureFlags = _chunkVFP6MEJGjs.mergeFeatureFlags; exports.parse = _chunkVFP6MEJGjs.parse; exports.parseAspectRatio = _chunkVFP6MEJGjs.parseAspectRatio; exports.parseRangeString = _chunkVFP6MEJGjs.parseRangeString; exports.parseSlide = _chunkVFP6MEJGjs.parseSlide; exports.prettify = _chunkVFP6MEJGjs.prettify; exports.prettifySlide = _chunkVFP6MEJGjs.prettifySlide; exports.resolveConfig = _chunkVFP6MEJGjs.resolveConfig; exports.resolveFonts = _chunkVFP6MEJGjs.resolveFonts; exports.save = save; exports.saveExternalSlide = saveExternalSlide; exports.scanMonacoModules = _chunkVFP6MEJGjs.scanMonacoModules; exports.stringify = _chunkVFP6MEJGjs.stringify; exports.stringifySlide = _chunkVFP6MEJGjs.stringifySlide;
73
+ exports.detectFeatures = _chunkWBX4FRCIjs.detectFeatures; exports.filterDisabled = _chunkWBX4FRCIjs.filterDisabled; exports.load = load; exports.mergeFeatureFlags = _chunkWBX4FRCIjs.mergeFeatureFlags; exports.parse = _chunkWBX4FRCIjs.parse; exports.parseAspectRatio = _chunkWBX4FRCIjs.parseAspectRatio; exports.parseRangeString = _chunkWBX4FRCIjs.parseRangeString; exports.parseSlide = _chunkWBX4FRCIjs.parseSlide; exports.prettify = _chunkWBX4FRCIjs.prettify; exports.prettifySlide = _chunkWBX4FRCIjs.prettifySlide; exports.resolveConfig = _chunkWBX4FRCIjs.resolveConfig; exports.resolveFonts = _chunkWBX4FRCIjs.resolveFonts; exports.save = save; exports.saveExternalSlide = saveExternalSlide; exports.scanMonacoModules = _chunkWBX4FRCIjs.scanMonacoModules; exports.stringify = _chunkWBX4FRCIjs.stringify; exports.stringifySlide = _chunkWBX4FRCIjs.stringifySlide;
package/dist/fs.mjs CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  scanMonacoModules,
15
15
  stringify,
16
16
  stringifySlide
17
- } from "./chunk-4LEQMYU6.mjs";
17
+ } from "./chunk-HINA34KW.mjs";
18
18
 
19
19
  // src/fs.ts
20
20
  import { promises as fs } from "fs";
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
 
15
15
 
16
- var _chunkVFP6MEJGjs = require('./chunk-VFP6MEJG.js');
16
+ var _chunkWBX4FRCIjs = require('./chunk-WBX4FRCI.js');
17
17
 
18
18
 
19
19
 
@@ -29,4 +29,4 @@ var _chunkVFP6MEJGjs = require('./chunk-VFP6MEJG.js');
29
29
 
30
30
 
31
31
 
32
- exports.detectFeatures = _chunkVFP6MEJGjs.detectFeatures; exports.filterDisabled = _chunkVFP6MEJGjs.filterDisabled; exports.mergeFeatureFlags = _chunkVFP6MEJGjs.mergeFeatureFlags; exports.parse = _chunkVFP6MEJGjs.parse; exports.parseAspectRatio = _chunkVFP6MEJGjs.parseAspectRatio; exports.parseRangeString = _chunkVFP6MEJGjs.parseRangeString; exports.parseSlide = _chunkVFP6MEJGjs.parseSlide; exports.prettify = _chunkVFP6MEJGjs.prettify; exports.prettifySlide = _chunkVFP6MEJGjs.prettifySlide; exports.resolveConfig = _chunkVFP6MEJGjs.resolveConfig; exports.resolveFonts = _chunkVFP6MEJGjs.resolveFonts; exports.scanMonacoModules = _chunkVFP6MEJGjs.scanMonacoModules; exports.stringify = _chunkVFP6MEJGjs.stringify; exports.stringifySlide = _chunkVFP6MEJGjs.stringifySlide;
32
+ exports.detectFeatures = _chunkWBX4FRCIjs.detectFeatures; exports.filterDisabled = _chunkWBX4FRCIjs.filterDisabled; exports.mergeFeatureFlags = _chunkWBX4FRCIjs.mergeFeatureFlags; exports.parse = _chunkWBX4FRCIjs.parse; exports.parseAspectRatio = _chunkWBX4FRCIjs.parseAspectRatio; exports.parseRangeString = _chunkWBX4FRCIjs.parseRangeString; exports.parseSlide = _chunkWBX4FRCIjs.parseSlide; exports.prettify = _chunkWBX4FRCIjs.prettify; exports.prettifySlide = _chunkWBX4FRCIjs.prettifySlide; exports.resolveConfig = _chunkWBX4FRCIjs.resolveConfig; exports.resolveFonts = _chunkWBX4FRCIjs.resolveFonts; exports.scanMonacoModules = _chunkWBX4FRCIjs.scanMonacoModules; exports.stringify = _chunkWBX4FRCIjs.stringify; exports.stringifySlide = _chunkWBX4FRCIjs.stringifySlide;
package/dist/index.mjs CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  scanMonacoModules,
14
14
  stringify,
15
15
  stringifySlide
16
- } from "./chunk-4LEQMYU6.mjs";
16
+ } from "./chunk-HINA34KW.mjs";
17
17
  export {
18
18
  detectFeatures,
19
19
  filterDisabled,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/parser",
3
- "version": "0.27.20",
3
+ "version": "0.28.0",
4
4
  "description": "Markdown parser for Slidev",
5
5
  "homepage": "https://sli.dev",
6
6
  "bugs": "https://github.com/slidevjs/slidev/issues",
@@ -29,14 +29,14 @@
29
29
  "./fs": {
30
30
  "import": "./dist/fs.mjs",
31
31
  "require": "./dist/fs.js",
32
- "types": "./dist/fs.d.ts"
32
+ "types": "./fs.d.ts"
33
33
  }
34
34
  },
35
35
  "main": "dist/index.js",
36
36
  "module": "dist/index.mjs",
37
37
  "types": "dist/index.d.ts",
38
38
  "dependencies": {
39
- "@slidev/types": "0.27.20",
39
+ "@slidev/types": "0.28.0",
40
40
  "js-yaml": "^4.1.0"
41
41
  },
42
42
  "engines": {
@@ -45,5 +45,6 @@
45
45
  "scripts": {
46
46
  "build": "rimraf dist && tsup src/index.ts src/core.ts src/fs.ts --format cjs,esm --dts --splitting",
47
47
  "dev": "nr build --watch"
48
- }
48
+ },
49
+ "readme": "# @slidev/parser\n\n[![NPM version](https://img.shields.io/npm/v/@slidev/parser?color=3AB9D4&label=)](https://www.npmjs.com/package/@slidev/parser)\n\nSlides markdown parser for [Slidev](https://sli.dev).\n\nLearn more about the [Syntax](https://sli.dev/guide/syntax.html)\n\nRefer to the TypeScript definitions for API.\n\n## License\n\nMIT License © 2021 [Anthony Fu](https://github.com/antfu)\n\n"
49
50
  }