@slidev/parser 0.50.0-beta.1 → 0.50.0-beta.11
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-47YLTX76.mjs +37 -0
- package/dist/{chunk-B5TCG27R.mjs → chunk-JZNWQ6OH.mjs} +14 -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 indexes = [];
|
|
9
|
+
for (const part of rangeStr.split(/[,;]/g)) {
|
|
10
|
+
if (!part.includes("-")) {
|
|
11
|
+
indexes.push(+part);
|
|
12
|
+
} else {
|
|
13
|
+
const [start, end] = part.split("-", 2);
|
|
14
|
+
indexes.push(
|
|
15
|
+
...range(+start, !end ? total + 1 : +end + 1)
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return uniq(indexes).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-47YLTX76.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",
|
|
@@ -69,9 +38,11 @@ function getDefaultConfig() {
|
|
|
69
38
|
drawings: {},
|
|
70
39
|
plantUmlServer: "https://www.plantuml.com/plantuml",
|
|
71
40
|
codeCopy: true,
|
|
41
|
+
author: "",
|
|
72
42
|
record: "dev",
|
|
73
43
|
css: "unocss",
|
|
74
44
|
presenter: true,
|
|
45
|
+
browserExporter: "dev",
|
|
75
46
|
htmlAttrs: {},
|
|
76
47
|
transition: null,
|
|
77
48
|
editor: true,
|
|
@@ -109,6 +80,8 @@ function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
|
|
|
109
80
|
console.warn(`[slidev] "shikiji" is merged back to "shiki", you can safely change it "highlighter: shiki"`);
|
|
110
81
|
config.highlighter = "shiki";
|
|
111
82
|
}
|
|
83
|
+
if (config.highlighter === "prism")
|
|
84
|
+
throw new Error(`[slidev] "prism" support has been dropped. Please use "highlighter: shiki" instead`);
|
|
112
85
|
if (config.colorSchema !== "dark" && config.colorSchema !== "light")
|
|
113
86
|
config.colorSchema = "auto";
|
|
114
87
|
if (themeColorSchema && config.colorSchema === "auto")
|
|
@@ -119,7 +92,7 @@ function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
|
|
|
119
92
|
return config;
|
|
120
93
|
}
|
|
121
94
|
function verifyConfig(config, themeMeta = {}, warn = (v) => console.warn(`[slidev] ${v}`)) {
|
|
122
|
-
const themeHightlighter =
|
|
95
|
+
const themeHightlighter = themeMeta.highlighter === "shiki" ? themeMeta.highlighter : void 0;
|
|
123
96
|
const themeColorSchema = ["light", "dark"].includes(themeMeta.colorSchema || "") ? themeMeta.colorSchema : void 0;
|
|
124
97
|
if (themeColorSchema && config.colorSchema !== themeColorSchema)
|
|
125
98
|
warn(`Color schema "${config.colorSchema}" does not supported by the theme`);
|
|
@@ -142,7 +115,7 @@ function resolveFonts(fonts = {}) {
|
|
|
142
115
|
const weights = toArray(fonts.weights || "200,400,600").flatMap((i) => i.toString().split(/,\s*/g)).map((i) => i.trim());
|
|
143
116
|
const custom = toArray(fonts.custom).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
144
117
|
const local = toArray(fonts.local).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
145
|
-
const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ?
|
|
118
|
+
const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ? uniq([...sans, ...serif, ...mono, ...custom]) : [];
|
|
146
119
|
webfonts.filter((i) => local.includes(i));
|
|
147
120
|
function toQuoted(font) {
|
|
148
121
|
if (/^(['"]).*\1$/.test(font))
|
|
@@ -150,7 +123,7 @@ function resolveFonts(fonts = {}) {
|
|
|
150
123
|
return `"${font}"`;
|
|
151
124
|
}
|
|
152
125
|
if (fallbacks) {
|
|
153
|
-
sans =
|
|
126
|
+
sans = uniq([
|
|
154
127
|
...sans.map(toQuoted),
|
|
155
128
|
"ui-sans-serif",
|
|
156
129
|
"system-ui",
|
|
@@ -167,7 +140,7 @@ function resolveFonts(fonts = {}) {
|
|
|
167
140
|
'"Segoe UI Symbol"',
|
|
168
141
|
'"Noto Color Emoji"'
|
|
169
142
|
]);
|
|
170
|
-
serif =
|
|
143
|
+
serif = uniq([
|
|
171
144
|
...serif.map(toQuoted),
|
|
172
145
|
"ui-serif",
|
|
173
146
|
"Georgia",
|
|
@@ -176,7 +149,7 @@ function resolveFonts(fonts = {}) {
|
|
|
176
149
|
"Times",
|
|
177
150
|
"serif"
|
|
178
151
|
]);
|
|
179
|
-
mono =
|
|
152
|
+
mono = uniq([
|
|
180
153
|
...mono.map(toQuoted),
|
|
181
154
|
"ui-monospace",
|
|
182
155
|
"SFMono-Regular",
|
|
@@ -475,8 +448,6 @@ function hash(str) {
|
|
|
475
448
|
}
|
|
476
449
|
|
|
477
450
|
export {
|
|
478
|
-
parseRangeString,
|
|
479
|
-
parseAspectRatio,
|
|
480
451
|
getDefaultConfig,
|
|
481
452
|
resolveConfig,
|
|
482
453
|
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-JZNWQ6OH.mjs";
|
|
15
|
+
import {
|
|
16
|
+
parseAspectRatio,
|
|
17
|
+
parseRangeString
|
|
18
|
+
} from "./chunk-47YLTX76.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-JZNWQ6OH.mjs";
|
|
15
|
+
import {
|
|
16
|
+
parseAspectRatio,
|
|
17
|
+
parseRangeString
|
|
18
|
+
} from "./chunk-47YLTX76.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-JZNWQ6OH.mjs";
|
|
15
|
+
import {
|
|
16
|
+
parseAspectRatio,
|
|
17
|
+
parseRangeString
|
|
18
|
+
} from "./chunk-47YLTX76.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.11",
|
|
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.11"
|
|
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
|
}
|