@astrojs/markdown-remark 6.0.1 → 6.1.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/frontmatter.js +14 -5
- package/dist/import-plugin-default.js +8 -2
- package/package.json +4 -3
package/dist/frontmatter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import yaml from "js-yaml";
|
|
2
|
+
import * as toml from "smol-toml";
|
|
2
3
|
function isFrontmatterValid(frontmatter) {
|
|
3
4
|
try {
|
|
4
5
|
JSON.stringify(frontmatter);
|
|
@@ -7,16 +8,21 @@ function isFrontmatterValid(frontmatter) {
|
|
|
7
8
|
}
|
|
8
9
|
return typeof frontmatter === "object" && frontmatter !== null;
|
|
9
10
|
}
|
|
10
|
-
const frontmatterRE = /(?:^\uFEFF?|^\s*\n)
|
|
11
|
+
const frontmatterRE = /(?:^\uFEFF?|^\s*\n)(?:---|\+\+\+)([\s\S]*?\n)(?:---|\+\+\+)/;
|
|
12
|
+
const frontmatterTypeRE = /(?:^\uFEFF?|^\s*\n)(---|\+\+\+)/;
|
|
11
13
|
function extractFrontmatter(code) {
|
|
12
14
|
return frontmatterRE.exec(code)?.[1];
|
|
13
15
|
}
|
|
16
|
+
function getFrontmatterParser(code) {
|
|
17
|
+
return frontmatterTypeRE.exec(code)?.[1] === "+++" ? ["+++", toml.parse] : ["---", yaml.load];
|
|
18
|
+
}
|
|
14
19
|
function parseFrontmatter(code, options) {
|
|
15
20
|
const rawFrontmatter = extractFrontmatter(code);
|
|
16
21
|
if (rawFrontmatter == null) {
|
|
17
22
|
return { frontmatter: {}, rawFrontmatter: "", content: code };
|
|
18
23
|
}
|
|
19
|
-
const
|
|
24
|
+
const [delims, parser] = getFrontmatterParser(code);
|
|
25
|
+
const parsed = parser(rawFrontmatter);
|
|
20
26
|
const frontmatter = parsed && typeof parsed === "object" ? parsed : {};
|
|
21
27
|
let content;
|
|
22
28
|
switch (options?.frontmatter ?? "remove") {
|
|
@@ -24,16 +30,19 @@ function parseFrontmatter(code, options) {
|
|
|
24
30
|
content = code;
|
|
25
31
|
break;
|
|
26
32
|
case "remove":
|
|
27
|
-
content = code.replace(
|
|
33
|
+
content = code.replace(`${delims}${rawFrontmatter}${delims}`, "");
|
|
28
34
|
break;
|
|
29
35
|
case "empty-with-spaces":
|
|
30
36
|
content = code.replace(
|
|
31
|
-
|
|
37
|
+
`${delims}${rawFrontmatter}${delims}`,
|
|
32
38
|
` ${rawFrontmatter.replace(/[^\r\n]/g, " ")} `
|
|
33
39
|
);
|
|
34
40
|
break;
|
|
35
41
|
case "empty-with-lines":
|
|
36
|
-
content = code.replace(
|
|
42
|
+
content = code.replace(
|
|
43
|
+
`${delims}${rawFrontmatter}${delims}`,
|
|
44
|
+
rawFrontmatter.replace(/[^\r\n]/g, "")
|
|
45
|
+
);
|
|
37
46
|
break;
|
|
38
47
|
}
|
|
39
48
|
return {
|
|
@@ -4,13 +4,19 @@ import { resolve as importMetaResolve } from "import-meta-resolve";
|
|
|
4
4
|
let cwdUrlStr;
|
|
5
5
|
async function importPlugin(p) {
|
|
6
6
|
try {
|
|
7
|
-
const importResult2 = await import(
|
|
7
|
+
const importResult2 = await import(
|
|
8
|
+
/* @vite-ignore */
|
|
9
|
+
p
|
|
10
|
+
);
|
|
8
11
|
return importResult2.default;
|
|
9
12
|
} catch {
|
|
10
13
|
}
|
|
11
14
|
cwdUrlStr ??= pathToFileURL(path.join(process.cwd(), "package.json")).toString();
|
|
12
15
|
const resolved = importMetaResolve(p, cwdUrlStr);
|
|
13
|
-
const importResult = await import(
|
|
16
|
+
const importResult = await import(
|
|
17
|
+
/* @vite-ignore */
|
|
18
|
+
resolved
|
|
19
|
+
);
|
|
14
20
|
return importResult.default;
|
|
15
21
|
}
|
|
16
22
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"remark-parse": "^11.0.0",
|
|
38
38
|
"remark-rehype": "^11.1.1",
|
|
39
39
|
"remark-smartypants": "^3.0.2",
|
|
40
|
-
"shiki": "^1.
|
|
40
|
+
"shiki": "^1.29.1",
|
|
41
|
+
"smol-toml": "^1.3.1",
|
|
41
42
|
"unified": "^11.0.5",
|
|
42
43
|
"unist-util-remove-position": "^5.0.0",
|
|
43
44
|
"unist-util-visit": "^5.0.0",
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"@types/js-yaml": "^4.0.9",
|
|
52
53
|
"@types/mdast": "^4.0.4",
|
|
53
54
|
"@types/unist": "^3.0.3",
|
|
54
|
-
"esbuild": "^0.
|
|
55
|
+
"esbuild": "^0.24.2",
|
|
55
56
|
"mdast-util-mdx-expression": "^2.0.1",
|
|
56
57
|
"astro-scripts": "0.0.14"
|
|
57
58
|
},
|