@astrojs/markdown-remark 2.2.1 → 3.0.0-rc.1
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-injection.d.ts +1 -1
- package/dist/index.js +6 -11
- package/dist/load-plugins.js +2 -2
- package/dist/rehype-collect-headings.js +4 -6
- package/dist/rehype-images.js +2 -3
- package/dist/remark-collect-images.js +1 -1
- package/dist/remark-prism.js +0 -1
- package/dist/remark-scoped-styles.js +1 -2
- package/dist/remark-shiki.js +0 -17
- package/dist/types.d.ts +1 -2
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -32,7 +32,6 @@ const markdownConfigDefaults = {
|
|
|
32
32
|
};
|
|
33
33
|
const isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);
|
|
34
34
|
async function renderMarkdown(content, opts) {
|
|
35
|
-
var _a;
|
|
36
35
|
let {
|
|
37
36
|
fileURL,
|
|
38
37
|
syntaxHighlight = markdownConfigDefaults.syntaxHighlight,
|
|
@@ -45,7 +44,7 @@ async function renderMarkdown(content, opts) {
|
|
|
45
44
|
frontmatter: userFrontmatter = {}
|
|
46
45
|
} = opts;
|
|
47
46
|
const input = new VFile({ value: content, path: fileURL });
|
|
48
|
-
const scopedClassName =
|
|
47
|
+
const scopedClassName = opts.$?.scopedClassName;
|
|
49
48
|
let parser = unified().use(markdown).use(toRemarkInitializeAstroData({ userFrontmatter })).use([]);
|
|
50
49
|
if (!isPerformanceBenchmark && gfm) {
|
|
51
50
|
if (gfm) {
|
|
@@ -69,9 +68,7 @@ async function renderMarkdown(content, opts) {
|
|
|
69
68
|
} else if (syntaxHighlight === "prism") {
|
|
70
69
|
parser.use([remarkPrism(scopedClassName)]);
|
|
71
70
|
}
|
|
72
|
-
|
|
73
|
-
parser.use([remarkCollectImages]);
|
|
74
|
-
}
|
|
71
|
+
parser.use([remarkCollectImages]);
|
|
75
72
|
}
|
|
76
73
|
parser.use([
|
|
77
74
|
[
|
|
@@ -86,9 +83,7 @@ async function renderMarkdown(content, opts) {
|
|
|
86
83
|
loadedRehypePlugins.forEach(([plugin, pluginOpts]) => {
|
|
87
84
|
parser.use([[plugin, pluginOpts]]);
|
|
88
85
|
});
|
|
89
|
-
|
|
90
|
-
parser.use(rehypeImages());
|
|
91
|
-
}
|
|
86
|
+
parser.use(rehypeImages());
|
|
92
87
|
if (!isPerformanceBenchmark) {
|
|
93
88
|
parser.use([rehypeHeadingIds]);
|
|
94
89
|
}
|
|
@@ -101,7 +96,7 @@ async function renderMarkdown(content, opts) {
|
|
|
101
96
|
console.error(err);
|
|
102
97
|
throw err;
|
|
103
98
|
}
|
|
104
|
-
const headings =
|
|
99
|
+
const headings = vfile?.data.__astroHeadings || [];
|
|
105
100
|
return {
|
|
106
101
|
metadata: { headings, source: content, html: String(vfile.value) },
|
|
107
102
|
code: String(vfile.value),
|
|
@@ -109,7 +104,7 @@ async function renderMarkdown(content, opts) {
|
|
|
109
104
|
};
|
|
110
105
|
}
|
|
111
106
|
function prefixError(err, prefix) {
|
|
112
|
-
if (err
|
|
107
|
+
if (err?.message) {
|
|
113
108
|
try {
|
|
114
109
|
err.message = `${prefix}:
|
|
115
110
|
${err.message}`;
|
|
@@ -121,7 +116,7 @@ ${err.message}`;
|
|
|
121
116
|
try {
|
|
122
117
|
wrappedError.stack = err.stack;
|
|
123
118
|
wrappedError.cause = err;
|
|
124
|
-
} catch
|
|
119
|
+
} catch {
|
|
125
120
|
}
|
|
126
121
|
return wrappedError;
|
|
127
122
|
}
|
package/dist/load-plugins.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve as importMetaResolve } from "import-meta-resolve";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { pathToFileURL } from "url";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
4
|
const cwdUrlStr = pathToFileURL(path.join(process.cwd(), "package.json")).toString();
|
|
5
5
|
async function importPlugin(p) {
|
|
6
6
|
if (typeof p === "string") {
|
|
@@ -15,7 +15,7 @@ function rehypeHeadingIds() {
|
|
|
15
15
|
const { tagName } = node;
|
|
16
16
|
if (tagName[0] !== "h")
|
|
17
17
|
return;
|
|
18
|
-
const [
|
|
18
|
+
const [, level] = tagName.match(/h([0-6])/) ?? [];
|
|
19
19
|
if (!level)
|
|
20
20
|
return;
|
|
21
21
|
const depth = Number.parseInt(level);
|
|
@@ -60,15 +60,13 @@ function rehypeHeadingIds() {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
function isMDXFile(file) {
|
|
63
|
-
|
|
64
|
-
return Boolean((_a = file.history[0]) == null ? void 0 : _a.endsWith(".mdx"));
|
|
63
|
+
return Boolean(file.history[0]?.endsWith(".mdx"));
|
|
65
64
|
}
|
|
66
65
|
function getMdxFrontmatterVariablePath(node) {
|
|
67
|
-
|
|
68
|
-
if (!((_a = node.data) == null ? void 0 : _a.estree) || node.data.estree.body.length !== 1)
|
|
66
|
+
if (!node.data?.estree || node.data.estree.body.length !== 1)
|
|
69
67
|
return new Error();
|
|
70
68
|
const statement = node.data.estree.body[0];
|
|
71
|
-
if (
|
|
69
|
+
if (statement?.type !== "ExpressionStatement" || statement.expression.type !== "MemberExpression")
|
|
72
70
|
return new Error();
|
|
73
71
|
let expression = statement.expression;
|
|
74
72
|
const expressionPath = [];
|
package/dist/rehype-images.js
CHANGED
|
@@ -2,13 +2,12 @@ import { visit } from "unist-util-visit";
|
|
|
2
2
|
function rehypeImages() {
|
|
3
3
|
return () => function(tree, file) {
|
|
4
4
|
visit(tree, (node) => {
|
|
5
|
-
var _a, _b;
|
|
6
5
|
if (node.type !== "element")
|
|
7
6
|
return;
|
|
8
7
|
if (node.tagName !== "img")
|
|
9
8
|
return;
|
|
10
|
-
if (
|
|
11
|
-
if (
|
|
9
|
+
if (node.properties?.src) {
|
|
10
|
+
if (file.data.imagePaths?.has(node.properties.src)) {
|
|
12
11
|
node.properties["__ASTRO_IMAGE_"] = node.properties.src;
|
|
13
12
|
delete node.properties.src;
|
|
14
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
2
|
function remarkCollectImages() {
|
|
3
3
|
return function(tree, vfile) {
|
|
4
|
-
if (typeof
|
|
4
|
+
if (typeof vfile?.path !== "string")
|
|
5
5
|
return;
|
|
6
6
|
const imagePaths = /* @__PURE__ */ new Set();
|
|
7
7
|
visit(tree, "image", (node) => {
|
package/dist/remark-prism.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { runHighlighterWithAstro } from "@astrojs/prism/dist/highlighter";
|
|
2
2
|
import { visit } from "unist-util-visit";
|
|
3
|
-
const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
|
|
4
3
|
function transformer(className) {
|
|
5
4
|
return function(tree) {
|
|
6
5
|
const visitor = (node) => {
|
|
@@ -2,11 +2,10 @@ import { visit } from "unist-util-visit";
|
|
|
2
2
|
const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
|
|
3
3
|
function scopedStyles(className) {
|
|
4
4
|
const visitor = (node) => {
|
|
5
|
-
var _a;
|
|
6
5
|
if (noVisit.has(node.type))
|
|
7
6
|
return;
|
|
8
7
|
const { data } = node;
|
|
9
|
-
let currentClassName =
|
|
8
|
+
let currentClassName = data?.hProperties?.class ?? "";
|
|
10
9
|
node.data = node.data || {};
|
|
11
10
|
node.data.hProperties = node.data.hProperties || {};
|
|
12
11
|
node.data.hProperties.class = `${className} ${currentClassName}`.trim();
|
package/dist/remark-shiki.js
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
import { getHighlighter } from "shiki";
|
|
2
2
|
import { visit } from "unist-util-visit";
|
|
3
3
|
const highlighterCacheAsync = /* @__PURE__ */ new Map();
|
|
4
|
-
const compatThemes = {
|
|
5
|
-
"material-darker": "material-theme-darker",
|
|
6
|
-
"material-default": "material-theme",
|
|
7
|
-
"material-lighter": "material-theme-lighter",
|
|
8
|
-
"material-ocean": "material-theme-ocean",
|
|
9
|
-
"material-palenight": "material-theme-palenight"
|
|
10
|
-
};
|
|
11
|
-
const normalizeTheme = (theme) => {
|
|
12
|
-
if (typeof theme === "string") {
|
|
13
|
-
return compatThemes[theme] || theme;
|
|
14
|
-
} else if (compatThemes[theme.name]) {
|
|
15
|
-
return { ...theme, name: compatThemes[theme.name] };
|
|
16
|
-
} else {
|
|
17
|
-
return theme;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
4
|
const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }, scopedClassName) => {
|
|
21
|
-
theme = normalizeTheme(theme);
|
|
22
5
|
const cacheID = typeof theme === "string" ? theme : theme.name;
|
|
23
6
|
let highlighterAsync = highlighterCacheAsync.get(cacheID);
|
|
24
7
|
if (!highlighterAsync) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as hast from 'hast';
|
|
2
2
|
import type * as mdast from 'mdast';
|
|
3
|
-
import type {
|
|
3
|
+
import type { one as Handler, all as Handlers, Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
4
4
|
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
|
5
5
|
import type * as unified from 'unified';
|
|
6
6
|
import type { VFile } from 'vfile';
|
|
@@ -46,7 +46,6 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
|
|
|
46
46
|
};
|
|
47
47
|
/** Used for frontmatter injection plugins */
|
|
48
48
|
frontmatter?: Record<string, any>;
|
|
49
|
-
experimentalAssets?: boolean;
|
|
50
49
|
}
|
|
51
50
|
export interface MarkdownHeading {
|
|
52
51
|
depth: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,33 +20,33 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"astro": "^
|
|
23
|
+
"astro": "^3.0.0-rc.5"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@astrojs/prism": "^
|
|
27
|
-
"github-slugger": "^1.
|
|
28
|
-
"import-meta-resolve": "^2.
|
|
26
|
+
"@astrojs/prism": "^3.0.0-rc.1",
|
|
27
|
+
"github-slugger": "^1.5.0",
|
|
28
|
+
"import-meta-resolve": "^2.2.2",
|
|
29
29
|
"rehype-raw": "^6.1.1",
|
|
30
30
|
"rehype-stringify": "^9.0.3",
|
|
31
31
|
"remark-gfm": "^3.0.1",
|
|
32
|
-
"remark-parse": "^10.0.
|
|
32
|
+
"remark-parse": "^10.0.2",
|
|
33
33
|
"remark-rehype": "^10.1.0",
|
|
34
34
|
"remark-smartypants": "^2.0.0",
|
|
35
35
|
"shiki": "^0.14.1",
|
|
36
36
|
"unified": "^10.1.2",
|
|
37
|
-
"unist-util-visit": "^4.1.
|
|
38
|
-
"vfile": "^5.3.
|
|
37
|
+
"unist-util-visit": "^4.1.2",
|
|
38
|
+
"vfile": "^5.3.7"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/chai": "^4.3.
|
|
42
|
-
"@types/estree": "^1.0.
|
|
41
|
+
"@types/chai": "^4.3.5",
|
|
42
|
+
"@types/estree": "^1.0.1",
|
|
43
43
|
"@types/github-slugger": "^1.3.0",
|
|
44
44
|
"@types/hast": "^2.3.4",
|
|
45
|
-
"@types/mdast": "^3.0.
|
|
45
|
+
"@types/mdast": "^3.0.11",
|
|
46
46
|
"@types/mocha": "^9.1.1",
|
|
47
47
|
"@types/unist": "^2.0.6",
|
|
48
|
-
"chai": "^4.3.
|
|
49
|
-
"mdast-util-mdx-expression": "^1.3.
|
|
48
|
+
"chai": "^4.3.7",
|
|
49
|
+
"mdast-util-mdx-expression": "^1.3.2",
|
|
50
50
|
"mocha": "^9.2.2",
|
|
51
51
|
"astro-scripts": "0.0.14"
|
|
52
52
|
},
|