@slidev/parser 0.49.29 → 0.50.0-beta.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/dist/chunk-KUD5POMT.mjs +37 -0
- package/dist/{chunk-3LX2JHFR.mjs → chunk-QBSOSQIN.mjs} +24 -42
- package/dist/core.d.mts +2 -10
- package/dist/core.mjs +5 -3
- package/dist/fs.d.mts +2 -1
- package/dist/fs.mjs +7 -4
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +5 -3
- package/dist/utils.d.mts +10 -0
- package/dist/utils.mjs +8 -0
- package/package.json +8 -4
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { isNumber, range, uniq } from "@antfu/utils";
|
|
3
|
+
function parseRangeString(total, rangeStr) {
|
|
4
|
+
if (!rangeStr || rangeStr === "all" || rangeStr === "*")
|
|
5
|
+
return range(1, total + 1);
|
|
6
|
+
if (rangeStr === "none")
|
|
7
|
+
return [];
|
|
8
|
+
const pages = [];
|
|
9
|
+
for (const part of rangeStr.split(/[,;]/g)) {
|
|
10
|
+
if (!part.includes("-")) {
|
|
11
|
+
pages.push(+part);
|
|
12
|
+
} else {
|
|
13
|
+
const [start, end] = part.split("-", 2);
|
|
14
|
+
pages.push(
|
|
15
|
+
...range(+start, !end ? total + 1 : +end + 1)
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return uniq(pages).filter((i) => i <= total).sort((a, b) => a - b);
|
|
20
|
+
}
|
|
21
|
+
function parseAspectRatio(str) {
|
|
22
|
+
if (isNumber(str))
|
|
23
|
+
return str;
|
|
24
|
+
if (!Number.isNaN(+str))
|
|
25
|
+
return +str;
|
|
26
|
+
const [wStr = "", hStr = ""] = str.split(/[:/x|]/);
|
|
27
|
+
const w = Number.parseFloat(wStr.trim());
|
|
28
|
+
const h = Number.parseFloat(hStr.trim());
|
|
29
|
+
if (Number.isNaN(w) || Number.isNaN(h) || h === 0)
|
|
30
|
+
throw new Error(`Invalid aspect ratio "${str}"`);
|
|
31
|
+
return w / h;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
parseRangeString,
|
|
36
|
+
parseAspectRatio
|
|
37
|
+
};
|
|
@@ -1,42 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseAspectRatio
|
|
3
|
+
} from "./chunk-KUD5POMT.mjs";
|
|
4
|
+
|
|
1
5
|
// src/core.ts
|
|
2
|
-
import YAML from "yaml";
|
|
3
6
|
import { ensurePrefix } from "@antfu/utils";
|
|
4
|
-
|
|
5
|
-
// src/utils.ts
|
|
6
|
-
import { isNumber, range, uniq } from "@antfu/utils";
|
|
7
|
-
function parseRangeString(total, rangeStr) {
|
|
8
|
-
if (!rangeStr || rangeStr === "all" || rangeStr === "*")
|
|
9
|
-
return range(1, total + 1);
|
|
10
|
-
if (rangeStr === "none")
|
|
11
|
-
return [];
|
|
12
|
-
const pages = [];
|
|
13
|
-
for (const part of rangeStr.split(/[,;]/g)) {
|
|
14
|
-
if (!part.includes("-")) {
|
|
15
|
-
pages.push(+part);
|
|
16
|
-
} else {
|
|
17
|
-
const [start, end] = part.split("-", 2);
|
|
18
|
-
pages.push(
|
|
19
|
-
...range(+start, !end ? total + 1 : +end + 1)
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return uniq(pages).filter((i) => i <= total).sort((a, b) => a - b);
|
|
24
|
-
}
|
|
25
|
-
function parseAspectRatio(str) {
|
|
26
|
-
if (isNumber(str))
|
|
27
|
-
return str;
|
|
28
|
-
if (!Number.isNaN(+str))
|
|
29
|
-
return +str;
|
|
30
|
-
const [wStr = "", hStr = ""] = str.split(/[:/x|]/);
|
|
31
|
-
const w = Number.parseFloat(wStr.trim());
|
|
32
|
-
const h = Number.parseFloat(hStr.trim());
|
|
33
|
-
if (Number.isNaN(w) || Number.isNaN(h) || h === 0)
|
|
34
|
-
throw new Error(`Invalid aspect ratio "${str}"`);
|
|
35
|
-
return w / h;
|
|
36
|
-
}
|
|
7
|
+
import YAML from "yaml";
|
|
37
8
|
|
|
38
9
|
// src/config.ts
|
|
39
|
-
import { toArray, uniq
|
|
10
|
+
import { toArray, uniq } from "@antfu/utils";
|
|
40
11
|
function getDefaultConfig() {
|
|
41
12
|
return {
|
|
42
13
|
theme: "default",
|
|
@@ -74,6 +45,7 @@ function getDefaultConfig() {
|
|
|
74
45
|
transition: null,
|
|
75
46
|
editor: true,
|
|
76
47
|
contextMenu: null,
|
|
48
|
+
overviewSnapshots: false,
|
|
77
49
|
wakeLock: true,
|
|
78
50
|
remote: false,
|
|
79
51
|
mdc: false
|
|
@@ -106,6 +78,8 @@ function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
|
|
|
106
78
|
console.warn(`[slidev] "shikiji" is merged back to "shiki", you can safely change it "highlighter: shiki"`);
|
|
107
79
|
config.highlighter = "shiki";
|
|
108
80
|
}
|
|
81
|
+
if (config.highlighter === "prism")
|
|
82
|
+
throw new Error(`[slidev] "prism" support has been dropped. Please use "highlighter: shiki" instead`);
|
|
109
83
|
if (config.colorSchema !== "dark" && config.colorSchema !== "light")
|
|
110
84
|
config.colorSchema = "auto";
|
|
111
85
|
if (themeColorSchema && config.colorSchema === "auto")
|
|
@@ -116,7 +90,7 @@ function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
|
|
|
116
90
|
return config;
|
|
117
91
|
}
|
|
118
92
|
function verifyConfig(config, themeMeta = {}, warn = (v) => console.warn(`[slidev] ${v}`)) {
|
|
119
|
-
const themeHightlighter =
|
|
93
|
+
const themeHightlighter = themeMeta.highlighter === "shiki" ? themeMeta.highlighter : void 0;
|
|
120
94
|
const themeColorSchema = ["light", "dark"].includes(themeMeta.colorSchema || "") ? themeMeta.colorSchema : void 0;
|
|
121
95
|
if (themeColorSchema && config.colorSchema !== themeColorSchema)
|
|
122
96
|
warn(`Color schema "${config.colorSchema}" does not supported by the theme`);
|
|
@@ -139,7 +113,7 @@ function resolveFonts(fonts = {}) {
|
|
|
139
113
|
const weights = toArray(fonts.weights || "200,400,600").flatMap((i) => i.toString().split(/,\s*/g)).map((i) => i.trim());
|
|
140
114
|
const custom = toArray(fonts.custom).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
141
115
|
const local = toArray(fonts.local).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
142
|
-
const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ?
|
|
116
|
+
const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ? uniq([...sans, ...serif, ...mono, ...custom]) : [];
|
|
143
117
|
webfonts.filter((i) => local.includes(i));
|
|
144
118
|
function toQuoted(font) {
|
|
145
119
|
if (/^(['"]).*\1$/.test(font))
|
|
@@ -147,7 +121,7 @@ function resolveFonts(fonts = {}) {
|
|
|
147
121
|
return `"${font}"`;
|
|
148
122
|
}
|
|
149
123
|
if (fallbacks) {
|
|
150
|
-
sans =
|
|
124
|
+
sans = uniq([
|
|
151
125
|
...sans.map(toQuoted),
|
|
152
126
|
"ui-sans-serif",
|
|
153
127
|
"system-ui",
|
|
@@ -164,7 +138,7 @@ function resolveFonts(fonts = {}) {
|
|
|
164
138
|
'"Segoe UI Symbol"',
|
|
165
139
|
'"Noto Color Emoji"'
|
|
166
140
|
]);
|
|
167
|
-
serif =
|
|
141
|
+
serif = uniq([
|
|
168
142
|
...serif.map(toQuoted),
|
|
169
143
|
"ui-serif",
|
|
170
144
|
"Georgia",
|
|
@@ -173,7 +147,7 @@ function resolveFonts(fonts = {}) {
|
|
|
173
147
|
"Times",
|
|
174
148
|
"serif"
|
|
175
149
|
]);
|
|
176
|
-
mono =
|
|
150
|
+
mono = uniq([
|
|
177
151
|
...mono.map(toQuoted),
|
|
178
152
|
"ui-monospace",
|
|
179
153
|
"SFMono-Regular",
|
|
@@ -282,6 +256,7 @@ function parseSlide(raw, options = {}) {
|
|
|
282
256
|
let note;
|
|
283
257
|
const frontmatter = matterResult.data || {};
|
|
284
258
|
let content = matterResult.content.trim();
|
|
259
|
+
const revision = hash(raw.trim());
|
|
285
260
|
const comments = Array.from(content.matchAll(/<!--([\s\S]*?)-->/g));
|
|
286
261
|
if (comments.length) {
|
|
287
262
|
const last = comments[comments.length - 1];
|
|
@@ -305,6 +280,7 @@ function parseSlide(raw, options = {}) {
|
|
|
305
280
|
raw,
|
|
306
281
|
title,
|
|
307
282
|
level,
|
|
283
|
+
revision,
|
|
308
284
|
content,
|
|
309
285
|
frontmatter,
|
|
310
286
|
frontmatterStyle: matterResult.type,
|
|
@@ -460,10 +436,16 @@ function scanMonacoReferencedMods(md) {
|
|
|
460
436
|
deps: Array.from(deps)
|
|
461
437
|
};
|
|
462
438
|
}
|
|
439
|
+
function hash(str) {
|
|
440
|
+
let hash2 = 0;
|
|
441
|
+
for (let i = 0; i < str.length; i++) {
|
|
442
|
+
hash2 = (hash2 << 5) - hash2 + str.charCodeAt(i);
|
|
443
|
+
hash2 |= 0;
|
|
444
|
+
}
|
|
445
|
+
return hash2.toString(36).slice(0, 12);
|
|
446
|
+
}
|
|
463
447
|
|
|
464
448
|
export {
|
|
465
|
-
parseRangeString,
|
|
466
|
-
parseAspectRatio,
|
|
467
449
|
getDefaultConfig,
|
|
468
450
|
resolveConfig,
|
|
469
451
|
verifyConfig,
|
package/dist/core.d.mts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { SlidevConfig, SlidevThemeMeta, FontOptions, ResolvedFontOptions, SlidevMarkdown, SourceSlideInfo, SlidevDetectedFeatures, SlidevPreparserExtension } 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;
|
|
2
|
+
export { parseAspectRatio, parseRangeString } from './utils.mjs';
|
|
11
3
|
|
|
12
4
|
declare function getDefaultConfig(): SlidevConfig;
|
|
13
5
|
declare function resolveConfig(headmatter: any, themeMeta?: SlidevThemeMeta, filepath?: string, verify?: boolean): SlidevConfig;
|
|
@@ -27,4 +19,4 @@ declare function parseSlide(raw: string, options?: SlidevParserOptions): Omit<So
|
|
|
27
19
|
declare function parse(markdown: string, filepath: string, extensions?: SlidevPreparserExtension[], options?: SlidevParserOptions): Promise<SlidevMarkdown>;
|
|
28
20
|
declare function parseSync(markdown: string, filepath: string, options?: SlidevParserOptions): SlidevMarkdown;
|
|
29
21
|
|
|
30
|
-
export { type SlidevParserOptions, detectFeatures, getDefaultConfig, parse,
|
|
22
|
+
export { type SlidevParserOptions, detectFeatures, getDefaultConfig, parse, parseSlide, parseSync, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig };
|
package/dist/core.mjs
CHANGED
|
@@ -2,8 +2,6 @@ import {
|
|
|
2
2
|
detectFeatures,
|
|
3
3
|
getDefaultConfig,
|
|
4
4
|
parse,
|
|
5
|
-
parseAspectRatio,
|
|
6
|
-
parseRangeString,
|
|
7
5
|
parseSlide,
|
|
8
6
|
parseSync,
|
|
9
7
|
prettify,
|
|
@@ -13,7 +11,11 @@ import {
|
|
|
13
11
|
stringify,
|
|
14
12
|
stringifySlide,
|
|
15
13
|
verifyConfig
|
|
16
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-QBSOSQIN.mjs";
|
|
15
|
+
import {
|
|
16
|
+
parseAspectRatio,
|
|
17
|
+
parseRangeString
|
|
18
|
+
} from "./chunk-KUD5POMT.mjs";
|
|
17
19
|
export {
|
|
18
20
|
detectFeatures,
|
|
19
21
|
getDefaultConfig,
|
package/dist/fs.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PreparserExtensionLoader, SlidevData, SlidevMarkdown } from '@slidev/types';
|
|
2
|
-
export { SlidevParserOptions, detectFeatures, getDefaultConfig, parse,
|
|
2
|
+
export { SlidevParserOptions, detectFeatures, getDefaultConfig, parse, parseSlide, parseSync, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig } from './core.mjs';
|
|
3
|
+
export { parseAspectRatio, parseRangeString } from './utils.mjs';
|
|
3
4
|
|
|
4
5
|
declare function injectPreparserExtensionLoader(fn: PreparserExtensionLoader): void;
|
|
5
6
|
/**
|
package/dist/fs.mjs
CHANGED
|
@@ -2,8 +2,6 @@ import {
|
|
|
2
2
|
detectFeatures,
|
|
3
3
|
getDefaultConfig,
|
|
4
4
|
parse,
|
|
5
|
-
parseAspectRatio,
|
|
6
|
-
parseRangeString,
|
|
7
5
|
parseSlide,
|
|
8
6
|
parseSync,
|
|
9
7
|
prettify,
|
|
@@ -13,13 +11,17 @@ import {
|
|
|
13
11
|
stringify,
|
|
14
12
|
stringifySlide,
|
|
15
13
|
verifyConfig
|
|
16
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-QBSOSQIN.mjs";
|
|
15
|
+
import {
|
|
16
|
+
parseAspectRatio,
|
|
17
|
+
parseRangeString
|
|
18
|
+
} from "./chunk-KUD5POMT.mjs";
|
|
17
19
|
|
|
18
20
|
// src/fs.ts
|
|
19
21
|
import fs from "node:fs";
|
|
20
22
|
import { dirname, resolve } from "node:path";
|
|
21
|
-
import YAML from "yaml";
|
|
22
23
|
import { slash } from "@antfu/utils";
|
|
24
|
+
import YAML from "yaml";
|
|
23
25
|
var preparserExtensionLoader = null;
|
|
24
26
|
function injectPreparserExtensionLoader(fn) {
|
|
25
27
|
preparserExtensionLoader = fn;
|
|
@@ -94,6 +96,7 @@ async function load(userRoot, filepath, loadedSource = {}, mode) {
|
|
|
94
96
|
slides.push({
|
|
95
97
|
frontmatter: { ...slide.frontmatter, ...frontmatterOverride },
|
|
96
98
|
content: slide.content,
|
|
99
|
+
revision: slide.revision,
|
|
97
100
|
frontmatterRaw: slide.frontmatterRaw,
|
|
98
101
|
note: slide.note,
|
|
99
102
|
title: slide.title,
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { SlidevParserOptions, detectFeatures, getDefaultConfig, parse,
|
|
1
|
+
export { SlidevParserOptions, detectFeatures, getDefaultConfig, parse, parseSlide, parseSync, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig } from './core.mjs';
|
|
2
|
+
export { parseAspectRatio, parseRangeString } from './utils.mjs';
|
|
2
3
|
import '@slidev/types';
|
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,6 @@ import {
|
|
|
2
2
|
detectFeatures,
|
|
3
3
|
getDefaultConfig,
|
|
4
4
|
parse,
|
|
5
|
-
parseAspectRatio,
|
|
6
|
-
parseRangeString,
|
|
7
5
|
parseSlide,
|
|
8
6
|
parseSync,
|
|
9
7
|
prettify,
|
|
@@ -13,7 +11,11 @@ import {
|
|
|
13
11
|
stringify,
|
|
14
12
|
stringifySlide,
|
|
15
13
|
verifyConfig
|
|
16
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-QBSOSQIN.mjs";
|
|
15
|
+
import {
|
|
16
|
+
parseAspectRatio,
|
|
17
|
+
parseRangeString
|
|
18
|
+
} from "./chunk-KUD5POMT.mjs";
|
|
17
19
|
export {
|
|
18
20
|
detectFeatures,
|
|
19
21
|
getDefaultConfig,
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 1,3-5,8 => [1, 3, 4, 5, 8]
|
|
3
|
+
*/
|
|
4
|
+
declare function parseRangeString(total: number, rangeStr?: string): number[];
|
|
5
|
+
/**
|
|
6
|
+
* Accepts `16/9` `1:1` `3x4`
|
|
7
|
+
*/
|
|
8
|
+
declare function parseAspectRatio(str: string | number): number;
|
|
9
|
+
|
|
10
|
+
export { parseAspectRatio, parseRangeString };
|
package/dist/utils.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slidev/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0-beta.10",
|
|
4
4
|
"description": "Markdown parser for Slidev",
|
|
5
5
|
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"./fs": {
|
|
24
24
|
"types": "./dist/fs.d.mts",
|
|
25
25
|
"import": "./dist/fs.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./utils": {
|
|
28
|
+
"types": "./dist/utils.d.mts",
|
|
29
|
+
"import": "./dist/utils.mjs"
|
|
26
30
|
}
|
|
27
31
|
},
|
|
28
32
|
"main": "dist/index.mjs",
|
|
@@ -37,11 +41,11 @@
|
|
|
37
41
|
},
|
|
38
42
|
"dependencies": {
|
|
39
43
|
"@antfu/utils": "^0.7.10",
|
|
40
|
-
"yaml": "^2.
|
|
41
|
-
"@slidev/types": "0.
|
|
44
|
+
"yaml": "^2.6.1",
|
|
45
|
+
"@slidev/types": "0.50.0-beta.10"
|
|
42
46
|
},
|
|
43
47
|
"scripts": {
|
|
44
|
-
"build": "rimraf dist && tsup src/index.ts src/core.ts src/fs.ts",
|
|
48
|
+
"build": "rimraf dist && tsup src/index.ts src/core.ts src/fs.ts src/utils.ts",
|
|
45
49
|
"dev": "nr build --watch"
|
|
46
50
|
}
|
|
47
51
|
}
|