@slidev/parser 52.10.0 → 52.11.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/fs.d.mts +1 -1
- package/dist/fs.mjs +8 -6
- package/package.json +3 -3
package/dist/fs.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ declare function injectPreparserExtensionLoader(fn: PreparserExtensionLoader): v
|
|
|
9
9
|
* because config and themeMeta depends on the theme to be loaded.
|
|
10
10
|
*/
|
|
11
11
|
type LoadedSlidevData = Omit<SlidevData, 'config' | 'themeMeta'>;
|
|
12
|
-
declare function load(userRoot: string, filepath: string,
|
|
12
|
+
declare function load(userRoot: string, filepath: string, sources?: Record<string, string> | ((path: string) => Promise<string>), mode?: string): Promise<LoadedSlidevData>;
|
|
13
13
|
declare function save(markdown: SlidevMarkdown): Promise<string>;
|
|
14
14
|
//#endregion
|
|
15
15
|
export { LoadedSlidevData, SlidevParserOptions, TimesplitInput, TimesplitOutput, detectFeatures, getDefaultConfig, injectPreparserExtensionLoader, load, parse, parseAspectRatio, parseRangeString, parseSlide, parseSync, parseTimeString, parseTimesplits, prettify, prettifySlide, resolveConfig, resolveFonts, save, stringify, stringifySlide, verifyConfig };
|
package/dist/fs.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as
|
|
|
2
2
|
import { a as prettify, c as stringifySlide, d as resolveFonts, f as verifyConfig, i as parseSync, l as getDefaultConfig, n as parse, o as prettifySlide, r as parseSlide, s as stringify, t as detectFeatures, u as resolveConfig } from "./core-LJx9ovOy.mjs";
|
|
3
3
|
import { slash } from "@antfu/utils";
|
|
4
4
|
import YAML from "yaml";
|
|
5
|
-
import
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
6
7
|
import { dirname, resolve } from "node:path";
|
|
7
8
|
|
|
8
9
|
//#region src/fs.ts
|
|
@@ -10,8 +11,9 @@ let preparserExtensionLoader = null;
|
|
|
10
11
|
function injectPreparserExtensionLoader(fn) {
|
|
11
12
|
preparserExtensionLoader = fn;
|
|
12
13
|
}
|
|
13
|
-
async function load(userRoot, filepath,
|
|
14
|
-
const
|
|
14
|
+
async function load(userRoot, filepath, sources = {}, mode) {
|
|
15
|
+
const loadSource = typeof sources === "function" ? sources : async (path) => sources[path] ?? readFile(path, "utf-8");
|
|
16
|
+
const markdown = await loadSource(filepath);
|
|
15
17
|
let extensions;
|
|
16
18
|
if (preparserExtensionLoader) {
|
|
17
19
|
const lines = markdown.split(/\r?\n/g);
|
|
@@ -30,7 +32,7 @@ async function load(userRoot, filepath, loadedSource = {}, mode) {
|
|
|
30
32
|
async function loadMarkdown(path, range$1, frontmatterOverride, importers) {
|
|
31
33
|
let md = markdownFiles[path];
|
|
32
34
|
if (!md) {
|
|
33
|
-
md = await parse(
|
|
35
|
+
md = await parse(await loadSource(path), path, extensions);
|
|
34
36
|
markdownFiles[path] = md;
|
|
35
37
|
watchFiles[path] = /* @__PURE__ */ new Set();
|
|
36
38
|
}
|
|
@@ -61,7 +63,7 @@ async function load(userRoot, filepath, loadedSource = {}, mode) {
|
|
|
61
63
|
...frontmatterOverride
|
|
62
64
|
};
|
|
63
65
|
delete frontmatterOverride.src;
|
|
64
|
-
if (!
|
|
66
|
+
if (!existsSync(path)) {
|
|
65
67
|
md.errors ??= [];
|
|
66
68
|
md.errors.push({
|
|
67
69
|
row: slide.start,
|
|
@@ -98,7 +100,7 @@ async function load(userRoot, filepath, loadedSource = {}, mode) {
|
|
|
98
100
|
}
|
|
99
101
|
async function save(markdown) {
|
|
100
102
|
const fileContent = stringify(markdown);
|
|
101
|
-
|
|
103
|
+
await writeFile(markdown.filepath, fileContent, "utf-8");
|
|
102
104
|
return fileContent;
|
|
103
105
|
}
|
|
104
106
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slidev/parser",
|
|
3
|
-
"version": "52.
|
|
3
|
+
"version": "52.11.0",
|
|
4
4
|
"description": "Markdown parser for Slidev",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@antfu/utils": "^9.3.0",
|
|
33
|
-
"yaml": "^2.8.
|
|
34
|
-
"@slidev/types": "52.
|
|
33
|
+
"yaml": "^2.8.2",
|
|
34
|
+
"@slidev/types": "52.11.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsdown",
|