@slidev/parser 0.50.0-beta.1 → 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-B5TCG27R.mjs → chunk-QBSOSQIN.mjs} +12 -43
- package/dist/core.d.mts +2 -10
- package/dist/core.mjs +5 -3
- package/dist/fs.d.mts +2 -1
- package/dist/fs.mjs +5 -3
- 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,44 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseAspectRatio
|
|
3
|
+
} from "./chunk-KUD5POMT.mjs";
|
|
4
|
+
|
|
1
5
|
// src/core.ts
|
|
2
6
|
import { ensurePrefix } from "@antfu/utils";
|
|
3
7
|
import YAML from "yaml";
|
|
4
8
|
|
|
5
9
|
// src/config.ts
|
|
6
|
-
import { toArray, uniq
|
|
7
|
-
|
|
8
|
-
// src/utils.ts
|
|
9
|
-
import { isNumber, range, uniq } from "@antfu/utils";
|
|
10
|
-
function parseRangeString(total, rangeStr) {
|
|
11
|
-
if (!rangeStr || rangeStr === "all" || rangeStr === "*")
|
|
12
|
-
return range(1, total + 1);
|
|
13
|
-
if (rangeStr === "none")
|
|
14
|
-
return [];
|
|
15
|
-
const pages = [];
|
|
16
|
-
for (const part of rangeStr.split(/[,;]/g)) {
|
|
17
|
-
if (!part.includes("-")) {
|
|
18
|
-
pages.push(+part);
|
|
19
|
-
} else {
|
|
20
|
-
const [start, end] = part.split("-", 2);
|
|
21
|
-
pages.push(
|
|
22
|
-
...range(+start, !end ? total + 1 : +end + 1)
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return uniq(pages).filter((i) => i <= total).sort((a, b) => a - b);
|
|
27
|
-
}
|
|
28
|
-
function parseAspectRatio(str) {
|
|
29
|
-
if (isNumber(str))
|
|
30
|
-
return str;
|
|
31
|
-
if (!Number.isNaN(+str))
|
|
32
|
-
return +str;
|
|
33
|
-
const [wStr = "", hStr = ""] = str.split(/[:/x|]/);
|
|
34
|
-
const w = Number.parseFloat(wStr.trim());
|
|
35
|
-
const h = Number.parseFloat(hStr.trim());
|
|
36
|
-
if (Number.isNaN(w) || Number.isNaN(h) || h === 0)
|
|
37
|
-
throw new Error(`Invalid aspect ratio "${str}"`);
|
|
38
|
-
return w / h;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/config.ts
|
|
10
|
+
import { toArray, uniq } from "@antfu/utils";
|
|
42
11
|
function getDefaultConfig() {
|
|
43
12
|
return {
|
|
44
13
|
theme: "default",
|
|
@@ -109,6 +78,8 @@ function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
|
|
|
109
78
|
console.warn(`[slidev] "shikiji" is merged back to "shiki", you can safely change it "highlighter: shiki"`);
|
|
110
79
|
config.highlighter = "shiki";
|
|
111
80
|
}
|
|
81
|
+
if (config.highlighter === "prism")
|
|
82
|
+
throw new Error(`[slidev] "prism" support has been dropped. Please use "highlighter: shiki" instead`);
|
|
112
83
|
if (config.colorSchema !== "dark" && config.colorSchema !== "light")
|
|
113
84
|
config.colorSchema = "auto";
|
|
114
85
|
if (themeColorSchema && config.colorSchema === "auto")
|
|
@@ -119,7 +90,7 @@ function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
|
|
|
119
90
|
return config;
|
|
120
91
|
}
|
|
121
92
|
function verifyConfig(config, themeMeta = {}, warn = (v) => console.warn(`[slidev] ${v}`)) {
|
|
122
|
-
const themeHightlighter =
|
|
93
|
+
const themeHightlighter = themeMeta.highlighter === "shiki" ? themeMeta.highlighter : void 0;
|
|
123
94
|
const themeColorSchema = ["light", "dark"].includes(themeMeta.colorSchema || "") ? themeMeta.colorSchema : void 0;
|
|
124
95
|
if (themeColorSchema && config.colorSchema !== themeColorSchema)
|
|
125
96
|
warn(`Color schema "${config.colorSchema}" does not supported by the theme`);
|
|
@@ -142,7 +113,7 @@ function resolveFonts(fonts = {}) {
|
|
|
142
113
|
const weights = toArray(fonts.weights || "200,400,600").flatMap((i) => i.toString().split(/,\s*/g)).map((i) => i.trim());
|
|
143
114
|
const custom = toArray(fonts.custom).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
144
115
|
const local = toArray(fonts.local).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
145
|
-
const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ?
|
|
116
|
+
const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ? uniq([...sans, ...serif, ...mono, ...custom]) : [];
|
|
146
117
|
webfonts.filter((i) => local.includes(i));
|
|
147
118
|
function toQuoted(font) {
|
|
148
119
|
if (/^(['"]).*\1$/.test(font))
|
|
@@ -150,7 +121,7 @@ function resolveFonts(fonts = {}) {
|
|
|
150
121
|
return `"${font}"`;
|
|
151
122
|
}
|
|
152
123
|
if (fallbacks) {
|
|
153
|
-
sans =
|
|
124
|
+
sans = uniq([
|
|
154
125
|
...sans.map(toQuoted),
|
|
155
126
|
"ui-sans-serif",
|
|
156
127
|
"system-ui",
|
|
@@ -167,7 +138,7 @@ function resolveFonts(fonts = {}) {
|
|
|
167
138
|
'"Segoe UI Symbol"',
|
|
168
139
|
'"Noto Color Emoji"'
|
|
169
140
|
]);
|
|
170
|
-
serif =
|
|
141
|
+
serif = uniq([
|
|
171
142
|
...serif.map(toQuoted),
|
|
172
143
|
"ui-serif",
|
|
173
144
|
"Georgia",
|
|
@@ -176,7 +147,7 @@ function resolveFonts(fonts = {}) {
|
|
|
176
147
|
"Times",
|
|
177
148
|
"serif"
|
|
178
149
|
]);
|
|
179
|
-
mono =
|
|
150
|
+
mono = uniq([
|
|
180
151
|
...mono.map(toQuoted),
|
|
181
152
|
"ui-monospace",
|
|
182
153
|
"SFMono-Regular",
|
|
@@ -475,8 +446,6 @@ function hash(str) {
|
|
|
475
446
|
}
|
|
476
447
|
|
|
477
448
|
export {
|
|
478
|
-
parseRangeString,
|
|
479
|
-
parseAspectRatio,
|
|
480
449
|
getDefaultConfig,
|
|
481
450
|
resolveConfig,
|
|
482
451
|
verifyConfig,
|
package/dist/core.d.mts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { SlidevConfig, SlidevThemeMeta, FontOptions, ResolvedFontOptions, SlidevMarkdown, SourceSlideInfo, SlidevDetectedFeatures, SlidevPreparserExtension } from '@slidev/types';
|
|
2
|
+
export { parseAspectRatio, parseRangeString } from './utils.mjs';
|
|
2
3
|
|
|
3
4
|
declare function getDefaultConfig(): SlidevConfig;
|
|
4
5
|
declare function resolveConfig(headmatter: any, themeMeta?: SlidevThemeMeta, filepath?: string, verify?: boolean): SlidevConfig;
|
|
5
6
|
declare function verifyConfig(config: SlidevConfig, themeMeta?: SlidevThemeMeta, warn?: (v: string) => void): void;
|
|
6
7
|
declare function resolveFonts(fonts?: FontOptions): ResolvedFontOptions;
|
|
7
8
|
|
|
8
|
-
/**
|
|
9
|
-
* 1,3-5,8 => [1, 3, 4, 5, 8]
|
|
10
|
-
*/
|
|
11
|
-
declare function parseRangeString(total: number, rangeStr?: string): number[];
|
|
12
|
-
/**
|
|
13
|
-
* Accepts `16/9` `1:1` `3x4`
|
|
14
|
-
*/
|
|
15
|
-
declare function parseAspectRatio(str: string | number): number;
|
|
16
|
-
|
|
17
9
|
interface SlidevParserOptions {
|
|
18
10
|
noParseYAML?: boolean;
|
|
19
11
|
preserveCR?: boolean;
|
|
@@ -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,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
|
|
|
18
20
|
// src/fs.ts
|
|
19
21
|
import fs from "node:fs";
|
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.50.0-beta.
|
|
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.50.0-beta.
|
|
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
|
}
|