@astrojs/mdx 4.0.7 → 4.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.
|
@@ -51,75 +51,95 @@ function getImageComponentAttributes(props) {
|
|
|
51
51
|
}
|
|
52
52
|
function rehypeImageToComponent() {
|
|
53
53
|
return function(tree, file) {
|
|
54
|
-
if (!file.data.astro?.
|
|
54
|
+
if (!file.data.astro?.localImagePaths?.length && !file.data.astro?.remoteImagePaths?.length)
|
|
55
|
+
return;
|
|
55
56
|
const importsStatements = [];
|
|
56
57
|
const importedImages = /* @__PURE__ */ new Map();
|
|
57
58
|
visit(tree, "element", (node, index, parent) => {
|
|
58
|
-
if (
|
|
59
|
-
return;
|
|
59
|
+
if (node.tagName !== "img" || !node.properties.src) return;
|
|
60
60
|
const src = decodeURI(String(node.properties.src));
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
const isLocalImage = file.data.astro?.localImagePaths?.includes(src);
|
|
62
|
+
const isRemoteImage = file.data.astro?.remoteImagePaths?.includes(src);
|
|
63
|
+
let element;
|
|
64
|
+
if (isLocalImage) {
|
|
65
|
+
let importName = importedImages.get(src);
|
|
66
|
+
if (!importName) {
|
|
67
|
+
importName = `__${importedImages.size}_${src.replace(/\W/g, "_")}__`;
|
|
68
|
+
importsStatements.push({
|
|
69
|
+
type: "mdxjsEsm",
|
|
70
|
+
value: "",
|
|
71
|
+
data: {
|
|
72
|
+
estree: {
|
|
73
|
+
type: "Program",
|
|
74
|
+
sourceType: "module",
|
|
75
|
+
body: [
|
|
76
|
+
{
|
|
77
|
+
type: "ImportDeclaration",
|
|
78
|
+
source: {
|
|
79
|
+
type: "Literal",
|
|
80
|
+
value: src,
|
|
81
|
+
raw: JSON.stringify(src)
|
|
82
|
+
},
|
|
83
|
+
specifiers: [
|
|
84
|
+
{
|
|
85
|
+
type: "ImportDefaultSpecifier",
|
|
86
|
+
local: { type: "Identifier", name: importName }
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
88
92
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
93
|
+
});
|
|
94
|
+
importedImages.set(src, importName);
|
|
95
|
+
}
|
|
96
|
+
element = {
|
|
97
|
+
name: ASTRO_IMAGE_ELEMENT,
|
|
98
|
+
type: "mdxJsxFlowElement",
|
|
99
|
+
attributes: [
|
|
100
|
+
...getImageComponentAttributes(node.properties),
|
|
101
|
+
{
|
|
102
|
+
name: "src",
|
|
103
|
+
type: "mdxJsxAttribute",
|
|
104
|
+
value: {
|
|
105
|
+
type: "mdxJsxAttributeValueExpression",
|
|
106
|
+
value: importName,
|
|
107
|
+
data: {
|
|
108
|
+
estree: {
|
|
109
|
+
type: "Program",
|
|
110
|
+
sourceType: "module",
|
|
111
|
+
comments: [],
|
|
112
|
+
body: [
|
|
113
|
+
{
|
|
114
|
+
type: "ExpressionStatement",
|
|
115
|
+
expression: { type: "Identifier", name: importName }
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
122
|
+
],
|
|
123
|
+
children: []
|
|
124
|
+
};
|
|
125
|
+
} else if (isRemoteImage) {
|
|
126
|
+
element = {
|
|
127
|
+
name: ASTRO_IMAGE_ELEMENT,
|
|
128
|
+
type: "mdxJsxFlowElement",
|
|
129
|
+
attributes: [
|
|
130
|
+
...getImageComponentAttributes(node.properties),
|
|
131
|
+
{
|
|
132
|
+
name: "src",
|
|
133
|
+
type: "mdxJsxAttribute",
|
|
134
|
+
value: src
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
children: []
|
|
138
|
+
};
|
|
139
|
+
} else {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
parent.children.splice(index, 1, element);
|
|
123
143
|
});
|
|
124
144
|
tree.children.unshift(...importsStatements);
|
|
125
145
|
tree.children.unshift(
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/mdx",
|
|
3
3
|
"description": "Add support for MDX pages in your Astro site",
|
|
4
|
-
"version": "4.0
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"source-map": "^0.7.4",
|
|
41
41
|
"unist-util-visit": "^5.0.0",
|
|
42
42
|
"vfile": "^6.0.3",
|
|
43
|
-
"@astrojs/markdown-remark": "6.0
|
|
43
|
+
"@astrojs/markdown-remark": "6.2.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"astro": "^5.0.0"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/hast": "^3.0.4",
|
|
51
51
|
"@types/mdast": "^4.0.4",
|
|
52
52
|
"cheerio": "1.0.0",
|
|
53
|
-
"linkedom": "^0.18.
|
|
53
|
+
"linkedom": "^0.18.7",
|
|
54
54
|
"mdast-util-mdx": "^3.0.0",
|
|
55
55
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
56
56
|
"mdast-util-to-string": "^4.0.0",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"remark-rehype": "^11.1.1",
|
|
61
61
|
"remark-shiki-twoslash": "^3.1.3",
|
|
62
62
|
"remark-toc": "^9.0.0",
|
|
63
|
-
"shiki": "^1.29.
|
|
63
|
+
"shiki": "^1.29.2",
|
|
64
64
|
"unified": "^11.0.5",
|
|
65
|
-
"vite": "^6.0.
|
|
66
|
-
"astro": "5.
|
|
65
|
+
"vite": "^6.0.11",
|
|
66
|
+
"astro": "5.4.0",
|
|
67
67
|
"astro-scripts": "0.0.14"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|