@slidev/parser 52.19.1 → 52.20.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.
- package/dist/core.d.mts +15 -15
- package/dist/core.mjs +26 -7
- package/dist/fs.d.mts +7 -7
- package/dist/fs.mjs +8 -0
- package/dist/utils.mjs +4 -2
- package/package.json +3 -3
package/dist/core.d.mts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-DpcPp-I0.mjs";
|
|
2
2
|
import { FontOptions, ResolvedFontOptions, SlidevConfig, SlidevDetectedFeatures, SlidevMarkdown, SlidevPreparserExtension, SlidevThemeMeta, SourceSlideInfo } from "@slidev/types";
|
|
3
3
|
//#region src/config.d.ts
|
|
4
|
-
declare function getDefaultConfig(): SlidevConfig;
|
|
5
|
-
declare function resolveConfig(headmatter: any, themeMeta?: SlidevThemeMeta, filepath?: string, verify?: boolean): SlidevConfig;
|
|
6
|
-
declare function verifyConfig(config: SlidevConfig, themeMeta?: SlidevThemeMeta, warn?: (v: string) => void): void;
|
|
7
|
-
declare function resolveFonts(fonts?: FontOptions): ResolvedFontOptions;
|
|
4
|
+
export declare function getDefaultConfig(): SlidevConfig;
|
|
5
|
+
export declare function resolveConfig(headmatter: any, themeMeta?: SlidevThemeMeta, filepath?: string, verify?: boolean): SlidevConfig;
|
|
6
|
+
export declare function verifyConfig(config: SlidevConfig, themeMeta?: SlidevThemeMeta, warn?: (v: string) => void): void;
|
|
7
|
+
export declare function resolveFonts(fonts?: FontOptions): ResolvedFontOptions;
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/core.d.ts
|
|
10
|
-
interface SlidevParserOptions {
|
|
10
|
+
export interface SlidevParserOptions {
|
|
11
11
|
noParseYAML?: boolean;
|
|
12
12
|
preserveCR?: boolean;
|
|
13
13
|
}
|
|
14
|
-
declare function stringify(data: SlidevMarkdown): string;
|
|
15
|
-
declare function stringifySlide(data: SourceSlideInfo, idx?: number): string;
|
|
16
|
-
declare function prettifySlide(data: SourceSlideInfo): SourceSlideInfo;
|
|
17
|
-
declare function prettify(data: SlidevMarkdown): SlidevMarkdown;
|
|
14
|
+
export declare function stringify(data: SlidevMarkdown): string;
|
|
15
|
+
export declare function stringifySlide(data: SourceSlideInfo, idx?: number): string;
|
|
16
|
+
export declare function prettifySlide(data: SourceSlideInfo): SourceSlideInfo;
|
|
17
|
+
export declare function prettify(data: SlidevMarkdown): SlidevMarkdown;
|
|
18
18
|
/**
|
|
19
19
|
* Extract image URLs from slide content and frontmatter.
|
|
20
20
|
* Strips code blocks first to avoid false positives.
|
|
21
21
|
*/
|
|
22
|
-
declare function extractImagesUsage(content: string, frontmatter: Record<string, any>): string[];
|
|
23
|
-
declare function detectFeatures(code: string): SlidevDetectedFeatures;
|
|
24
|
-
declare function parseSlide(raw: string, options?: SlidevParserOptions): Omit<SourceSlideInfo, 'filepath' | 'index' | 'start' | 'contentStart' | 'end'>;
|
|
25
|
-
declare function parse(markdown: string, filepath: string, extensions?: SlidevPreparserExtension[], options?: SlidevParserOptions): Promise<SlidevMarkdown>;
|
|
26
|
-
declare function parseSync(markdown: string, filepath: string, options?: SlidevParserOptions): SlidevMarkdown;
|
|
22
|
+
export declare function extractImagesUsage(content: string, frontmatter: Record<string, any>): string[];
|
|
23
|
+
export declare function detectFeatures(code: string): SlidevDetectedFeatures;
|
|
24
|
+
export declare function parseSlide(raw: string, options?: SlidevParserOptions): Omit<SourceSlideInfo, 'filepath' | 'index' | 'start' | 'contentStart' | 'end'>;
|
|
25
|
+
export declare function parse(markdown: string, filepath: string, extensions?: SlidevPreparserExtension[], options?: SlidevParserOptions): Promise<SlidevMarkdown>;
|
|
26
|
+
export declare function parseSync(markdown: string, filepath: string, options?: SlidevParserOptions): SlidevMarkdown;
|
|
27
27
|
//#endregion
|
|
28
|
-
export {
|
|
28
|
+
export { TimesplitInput, TimesplitOutput, parseAspectRatio, parseRangeString, parseTimeString, parseTimesplits };
|
package/dist/core.mjs
CHANGED
|
@@ -81,7 +81,11 @@ function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
|
|
|
81
81
|
...headmatter.config?.fonts,
|
|
82
82
|
...headmatter?.fonts
|
|
83
83
|
}),
|
|
84
|
-
drawings: resolveDrawings(
|
|
84
|
+
drawings: resolveDrawings({
|
|
85
|
+
...themeMeta.defaults?.drawings,
|
|
86
|
+
...headmatter.config?.drawings,
|
|
87
|
+
...headmatter?.drawings
|
|
88
|
+
}, filepath),
|
|
85
89
|
htmlAttrs: {
|
|
86
90
|
...defaultConfig.htmlAttrs,
|
|
87
91
|
...themeMeta.defaults?.htmlAttrs,
|
|
@@ -204,6 +208,7 @@ const RE_TWEET_TAG = /<Tweet\b/;
|
|
|
204
208
|
const RE_BLUESKY_TAG = /<BlueSky\b/;
|
|
205
209
|
const RE_MERMAID_CODEBLOCK = /^```mermaid/m;
|
|
206
210
|
const RE_HEADING = /^(#+) (.*)$/m;
|
|
211
|
+
const RE_CODE_BLOCK = /^```[\s\S]+?^```/gm;
|
|
207
212
|
const RE_LEADING_BACKTICKS = /^\s*`+/;
|
|
208
213
|
const RE_CRLF = /\r?\n/g;
|
|
209
214
|
function advanceHtmlCommentState(line, inHtmlComment) {
|
|
@@ -261,6 +266,15 @@ function matter(code, options) {
|
|
|
261
266
|
};
|
|
262
267
|
}
|
|
263
268
|
const IMAGE_EXTENSIONS = /\.(?:png|jpe?g|gif|svg|webp|avif|ico|bmp|tiff?)$/i;
|
|
269
|
+
const RE_MD_IMAGE_TITLE = /\s+(?:"[^"]*"|'[^']*')\s*$/;
|
|
270
|
+
/**
|
|
271
|
+
* Strip the optional CommonMark title and the angle-bracket form from a
|
|
272
|
+
* markdown image destination, so `` yields `/x.png`.
|
|
273
|
+
*/
|
|
274
|
+
function normalizeMarkdownImageTarget(target) {
|
|
275
|
+
const url = target.trim().replace(RE_MD_IMAGE_TITLE, "").trim();
|
|
276
|
+
return url.startsWith("<") && url.endsWith(">") ? url.slice(1, -1).trim() : url;
|
|
277
|
+
}
|
|
264
278
|
/**
|
|
265
279
|
* Extract image URLs from slide content and frontmatter.
|
|
266
280
|
* Strips code blocks first to avoid false positives.
|
|
@@ -273,12 +287,17 @@ function extractImagesUsage(content, frontmatter) {
|
|
|
273
287
|
"background"
|
|
274
288
|
]) {
|
|
275
289
|
const val = frontmatter[key];
|
|
276
|
-
if (typeof val === "string" && val && !val.startsWith("data:"))
|
|
277
|
-
if (
|
|
278
|
-
|
|
290
|
+
if (typeof val === "string" && val && !val.startsWith("data:")) {
|
|
291
|
+
if (key === "background") {
|
|
292
|
+
if (IMAGE_EXTENSIONS.test(val) || val.startsWith("/") || val.startsWith("http")) images.add(val);
|
|
293
|
+
} else images.add(val);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const stripped = content.replace(RE_CODE_BLOCK, "");
|
|
297
|
+
for (const [, target] of stripped.matchAll(/!\[[^\]]*\]\(([^)]+)\)/g)) {
|
|
298
|
+
const url = normalizeMarkdownImageTarget(target);
|
|
299
|
+
if (url && !url.startsWith("data:")) images.add(url);
|
|
279
300
|
}
|
|
280
|
-
const stripped = content.replace(/^```[\s\S]+?^```/gm, "");
|
|
281
|
-
for (const [, url] of stripped.matchAll(/!\[[^\]]*\]\(([^)]+)\)/g)) if (url && !url.startsWith("data:")) images.add(url.trim());
|
|
282
301
|
for (const [, url] of stripped.matchAll(/\b(?:src|image)=["']([^"']+)["']/g)) if (url && !url.startsWith("data:") && !url.includes("{{") && IMAGE_EXTENSIONS.test(url)) images.add(url.trim());
|
|
283
302
|
for (const [, url] of stripped.matchAll(/:(?:src|image)=["']'([^']+)'["']/g)) if (url && !url.startsWith("data:") && IMAGE_EXTENSIONS.test(url)) images.add(url.trim());
|
|
284
303
|
for (const [, url] of stripped.matchAll(/url\(["']?([^"')]+)["']?\)/g)) if (url && !url.startsWith("data:") && IMAGE_EXTENSIONS.test(url)) images.add(url.trim());
|
|
@@ -311,7 +330,7 @@ function parseSlide(raw, options = {}) {
|
|
|
311
330
|
let level;
|
|
312
331
|
if (frontmatter.title || frontmatter.name) title = frontmatter.title || frontmatter.name;
|
|
313
332
|
else {
|
|
314
|
-
const match = content.match(RE_HEADING);
|
|
333
|
+
const match = content.replace(RE_CODE_BLOCK, "").match(RE_HEADING);
|
|
315
334
|
title = match?.[2]?.trim();
|
|
316
335
|
level = match?.[1]?.length;
|
|
317
336
|
}
|
package/dist/fs.d.mts
CHANGED
|
@@ -7,9 +7,9 @@ import { PreparserExtensionLoader, SlidevData, SlidevMarkdown } from "@slidev/ty
|
|
|
7
7
|
* Inlined here (rather than imported from the `slidev` package) because
|
|
8
8
|
* `@slidev/parser` must stay independent of `@slidev/slidev`.
|
|
9
9
|
*/
|
|
10
|
-
declare function isPathInsideRoots(filePath: string, roots: string[]): boolean;
|
|
11
|
-
declare function injectPreparserExtensionLoader(fn: PreparserExtensionLoader): void;
|
|
12
|
-
interface LoadRootsInfo {
|
|
10
|
+
export declare function isPathInsideRoots(filePath: string, roots: string[]): boolean;
|
|
11
|
+
export declare function injectPreparserExtensionLoader(fn: PreparserExtensionLoader): void;
|
|
12
|
+
export interface LoadRootsInfo {
|
|
13
13
|
roots: string[];
|
|
14
14
|
userRoot: string;
|
|
15
15
|
/**
|
|
@@ -23,8 +23,8 @@ interface LoadRootsInfo {
|
|
|
23
23
|
* Slidev data without config and themeMeta,
|
|
24
24
|
* because config and themeMeta depends on the theme to be loaded.
|
|
25
25
|
*/
|
|
26
|
-
type LoadedSlidevData = Omit<SlidevData, 'config' | 'themeMeta'>;
|
|
27
|
-
declare function load(options: LoadRootsInfo, filepath: string, sources?: Record<string, string> | ((path: string) => Promise<string>), mode?: string): Promise<LoadedSlidevData>;
|
|
28
|
-
declare function save(markdown: SlidevMarkdown): Promise<string>;
|
|
26
|
+
export type LoadedSlidevData = Omit<SlidevData, 'config' | 'themeMeta'>;
|
|
27
|
+
export declare function load(options: LoadRootsInfo, filepath: string, sources?: Record<string, string> | ((path: string) => Promise<string>), mode?: string): Promise<LoadedSlidevData>;
|
|
28
|
+
export declare function save(markdown: SlidevMarkdown): Promise<string>;
|
|
29
29
|
//#endregion
|
|
30
|
-
export {
|
|
30
|
+
export { SlidevParserOptions, TimesplitInput, TimesplitOutput, detectFeatures, extractImagesUsage, getDefaultConfig, parse, parseAspectRatio, parseRangeString, parseSlide, parseSync, parseTimeString, parseTimesplits, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig };
|
package/dist/fs.mjs
CHANGED
|
@@ -54,6 +54,14 @@ async function load(options, filepath, sources = {}, mode) {
|
|
|
54
54
|
const directImporter = importers?.at(-1);
|
|
55
55
|
for (const index of parseRangeString(md.slides.length, range)) {
|
|
56
56
|
const subSlide = md.slides[index - 1];
|
|
57
|
+
if (!subSlide) {
|
|
58
|
+
md.errors ??= [];
|
|
59
|
+
md.errors.push({
|
|
60
|
+
row: 0,
|
|
61
|
+
message: `Slide ${index} does not exist in "${path}", which has ${md.slides.length} slides`
|
|
62
|
+
});
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
57
65
|
try {
|
|
58
66
|
await loadSlide(md, subSlide, frontmatterOverride, importers);
|
|
59
67
|
} catch (e) {
|
package/dist/utils.mjs
CHANGED
|
@@ -40,8 +40,10 @@ function parseTimeString(timestamp) {
|
|
|
40
40
|
else throw new TypeError("Invalid timestamp format");
|
|
41
41
|
if (Number.isNaN(h) || Number.isNaN(m) || Number.isNaN(s)) throw new TypeError("Invalid timestamp format");
|
|
42
42
|
seconds = (h || 0) * 3600 + (m || 0) * 60 + (s || 0);
|
|
43
|
-
} else if (!RE_ALPHA.test(timestamp))
|
|
44
|
-
|
|
43
|
+
} else if (!RE_ALPHA.test(timestamp)) {
|
|
44
|
+
seconds = Number(timestamp);
|
|
45
|
+
if (Number.isNaN(seconds)) throw new TypeError("Invalid timestamp format");
|
|
46
|
+
} else {
|
|
45
47
|
const unitMap = {
|
|
46
48
|
s: 1,
|
|
47
49
|
sec: 1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slidev/parser",
|
|
3
|
-
"version": "52.
|
|
3
|
+
"version": "52.20.0",
|
|
4
4
|
"description": "Markdown parser for Slidev",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@antfu/utils": "^9.3.0",
|
|
33
|
+
"@slidev/types": "52.20.0",
|
|
33
34
|
"pathe": "^2.0.3",
|
|
34
|
-
"yaml": "^2.9.
|
|
35
|
-
"@slidev/types": "52.19.1"
|
|
35
|
+
"yaml": "^2.9.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"tsdown-stale-guard": "^0.1.3"
|