@astrojs/markdown-remark 2.1.1 → 2.1.2
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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +9 -0
- package/dist/index.js +2 -2
- package/dist/rehype-images.d.ts +1 -1
- package/dist/rehype-images.js +3 -34
- package/dist/remark-collect-images.d.ts +1 -3
- package/dist/remark-collect-images.js +1 -14
- package/dist/types.d.ts +0 -4
- package/package.json +2 -2
- package/src/index.ts +2 -2
- package/src/rehype-images.ts +4 -43
- package/src/remark-collect-images.ts +1 -16
- package/src/types.ts +0 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[35m@astrojs/markdown-remark:build: [0mcache hit, replaying output [
|
|
1
|
+
[35m@astrojs/markdown-remark:build: [0mcache hit, replaying output [2m56144f20e07435ef[0m
|
|
2
2
|
[35m@astrojs/markdown-remark:build: [0m
|
|
3
|
-
[35m@astrojs/markdown-remark:build: [0m> @astrojs/markdown-remark@2.1.
|
|
3
|
+
[35m@astrojs/markdown-remark:build: [0m> @astrojs/markdown-remark@2.1.2 build /home/runner/work/astro/astro/packages/markdown/remark
|
|
4
4
|
[35m@astrojs/markdown-remark:build: [0m> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
|
|
5
5
|
[35m@astrojs/markdown-remark:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @astrojs/markdown-remark
|
|
2
2
|
|
|
3
|
+
## 2.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#6604](https://github.com/withastro/astro/pull/6604) [`7f7a8504b`](https://github.com/withastro/astro/commit/7f7a8504b5c2df4c99d3025931860c0d50992510) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Fix using optimized images in Markdown not working
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`7f7a8504b`](https://github.com/withastro/astro/commit/7f7a8504b5c2df4c99d3025931860c0d50992510), [`38e6ec21e`](https://github.com/withastro/astro/commit/38e6ec21e266ad8765d8ca2293034123b34e839a), [`f42f47dc6`](https://github.com/withastro/astro/commit/f42f47dc6a91cdb6534dab0ecbf9e8e85f00ba40)]:
|
|
10
|
+
- astro@2.1.5
|
|
11
|
+
|
|
3
12
|
## 2.1.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -69,7 +69,7 @@ async function renderMarkdown(content, opts) {
|
|
|
69
69
|
parser.use([remarkPrism(scopedClassName)]);
|
|
70
70
|
}
|
|
71
71
|
if (opts.experimentalAssets) {
|
|
72
|
-
parser.use([toRemarkCollectImages(
|
|
72
|
+
parser.use([toRemarkCollectImages()]);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
parser.use([
|
|
@@ -86,7 +86,7 @@ async function renderMarkdown(content, opts) {
|
|
|
86
86
|
parser.use([[plugin, pluginOpts]]);
|
|
87
87
|
});
|
|
88
88
|
if (opts.experimentalAssets) {
|
|
89
|
-
parser.use(rehypeImages(
|
|
89
|
+
parser.use(rehypeImages());
|
|
90
90
|
}
|
|
91
91
|
if (!isPerformanceBenchmark) {
|
|
92
92
|
parser.use([rehypeHeadingIds]);
|
package/dist/rehype-images.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { MarkdownVFile } from './types.js';
|
|
2
|
-
export declare function rehypeImages(
|
|
2
|
+
export declare function rehypeImages(): () => (tree: any, file: MarkdownVFile) => void;
|
package/dist/rehype-images.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { join as pathJoin } from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
1
|
import { visit } from "unist-util-visit";
|
|
4
|
-
|
|
5
|
-
function rehypeImages(imageService, assetsDir, getImageMetadata) {
|
|
2
|
+
function rehypeImages() {
|
|
6
3
|
return () => function(tree, file) {
|
|
7
4
|
visit(tree, (node) => {
|
|
8
5
|
var _a;
|
|
9
|
-
if (!assetsDir)
|
|
10
|
-
return;
|
|
11
6
|
if (node.type !== "element")
|
|
12
7
|
return;
|
|
13
8
|
if (node.tagName !== "img")
|
|
@@ -16,31 +11,8 @@ function rehypeImages(imageService, assetsDir, getImageMetadata) {
|
|
|
16
11
|
if (file.dirname) {
|
|
17
12
|
if (!isRelativePath(node.properties.src) && !isAliasedPath(node.properties.src))
|
|
18
13
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
fileURL = new URL(stripAliasPath(node.properties.src), assetsDir);
|
|
22
|
-
} else {
|
|
23
|
-
fileURL = pathToFileURL(pathJoin(file.dirname, node.properties.src));
|
|
24
|
-
}
|
|
25
|
-
const fileData = getImageMetadata(fileURLToPath(fileURL));
|
|
26
|
-
fileURL.searchParams.append("origWidth", fileData.width.toString());
|
|
27
|
-
fileURL.searchParams.append("origHeight", fileData.height.toString());
|
|
28
|
-
fileURL.searchParams.append("origFormat", fileData.type.toString());
|
|
29
|
-
let options = {
|
|
30
|
-
src: {
|
|
31
|
-
src: fileURL,
|
|
32
|
-
width: fileData.width,
|
|
33
|
-
height: fileData.height,
|
|
34
|
-
format: fileData.type
|
|
35
|
-
},
|
|
36
|
-
alt: node.properties.alt
|
|
37
|
-
};
|
|
38
|
-
const validatedOptions = imageService.validateOptions ? imageService.validateOptions(options) : options;
|
|
39
|
-
const imageURL = imageService.getURL(validatedOptions);
|
|
40
|
-
node.properties = Object.assign(node.properties, {
|
|
41
|
-
src: imageURL,
|
|
42
|
-
...imageService.getHTMLAttributes !== void 0 ? imageService.getHTMLAttributes(validatedOptions) : {}
|
|
43
|
-
});
|
|
14
|
+
node.properties["__ASTRO_IMAGE_"] = node.properties.src;
|
|
15
|
+
delete node.properties.src;
|
|
44
16
|
}
|
|
45
17
|
}
|
|
46
18
|
});
|
|
@@ -49,9 +21,6 @@ function rehypeImages(imageService, assetsDir, getImageMetadata) {
|
|
|
49
21
|
function isAliasedPath(path) {
|
|
50
22
|
return path.startsWith("~/assets");
|
|
51
23
|
}
|
|
52
|
-
function stripAliasPath(path) {
|
|
53
|
-
return path.replace("~/assets/", "");
|
|
54
|
-
}
|
|
55
24
|
function isRelativePath(path) {
|
|
56
25
|
return startsWithDotDotSlash(path) || startsWithDotSlash(path);
|
|
57
26
|
}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import type { VFile } from 'vfile';
|
|
2
|
-
|
|
3
|
-
export default function toRemarkCollectImages(resolveImage: OptionalResolveImage): () => (tree: any, vfile: VFile) => Promise<void>;
|
|
4
|
-
export {};
|
|
2
|
+
export default function toRemarkCollectImages(): () => (tree: any, vfile: VFile) => Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
|
-
function toRemarkCollectImages(
|
|
2
|
+
function toRemarkCollectImages() {
|
|
3
3
|
return () => async function(tree, vfile) {
|
|
4
4
|
if (typeof (vfile == null ? void 0 : vfile.path) !== "string")
|
|
5
5
|
return;
|
|
@@ -7,19 +7,6 @@ function toRemarkCollectImages(resolveImage) {
|
|
|
7
7
|
visit(tree, "image", function raiseError(node) {
|
|
8
8
|
imagePaths.add(node.url);
|
|
9
9
|
});
|
|
10
|
-
if (imagePaths.size === 0) {
|
|
11
|
-
vfile.data.imagePaths = [];
|
|
12
|
-
return;
|
|
13
|
-
} else if (resolveImage) {
|
|
14
|
-
const mapping = /* @__PURE__ */ new Map();
|
|
15
|
-
for (const path of Array.from(imagePaths)) {
|
|
16
|
-
const id = await resolveImage(path);
|
|
17
|
-
mapping.set(path, id);
|
|
18
|
-
}
|
|
19
|
-
visit(tree, "image", function raiseError(node) {
|
|
20
|
-
node.url = mapping.get(node.url);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
10
|
vfile.data.imagePaths = Array.from(imagePaths);
|
|
24
11
|
};
|
|
25
12
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -47,10 +47,6 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
|
|
|
47
47
|
/** Used for frontmatter injection plugins */
|
|
48
48
|
frontmatter?: Record<string, any>;
|
|
49
49
|
experimentalAssets?: boolean;
|
|
50
|
-
imageService?: any;
|
|
51
|
-
assetsDir?: URL;
|
|
52
|
-
resolveImage?: (path: string) => Promise<string>;
|
|
53
|
-
getImageMetadata?: any;
|
|
54
50
|
}
|
|
55
51
|
export interface MarkdownHeading {
|
|
56
52
|
depth: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./dist/internal.js": "./dist/internal.js"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"astro": "^2.1.
|
|
20
|
+
"astro": "^2.1.5"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@astrojs/prism": "^2.1.0",
|
package/src/index.ts
CHANGED
|
@@ -96,7 +96,7 @@ export async function renderMarkdown(
|
|
|
96
96
|
|
|
97
97
|
if (opts.experimentalAssets) {
|
|
98
98
|
// Apply later in case user plugins resolve relative image paths
|
|
99
|
-
parser.use([toRemarkCollectImages(
|
|
99
|
+
parser.use([toRemarkCollectImages()]);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -116,7 +116,7 @@ export async function renderMarkdown(
|
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
if (opts.experimentalAssets) {
|
|
119
|
-
parser.use(rehypeImages(
|
|
119
|
+
parser.use(rehypeImages());
|
|
120
120
|
}
|
|
121
121
|
if (!isPerformanceBenchmark) {
|
|
122
122
|
parser.use([rehypeHeadingIds]);
|
package/src/rehype-images.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { join as pathJoin } from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
1
|
import { visit } from 'unist-util-visit';
|
|
4
|
-
import {
|
|
5
|
-
import type { ImageMetadata, MarkdownVFile } from './types.js';
|
|
2
|
+
import type { MarkdownVFile } from './types.js';
|
|
6
3
|
|
|
7
|
-
export function rehypeImages(
|
|
4
|
+
export function rehypeImages() {
|
|
8
5
|
return () =>
|
|
9
6
|
function (tree: any, file: MarkdownVFile) {
|
|
10
7
|
visit(tree, (node) => {
|
|
11
|
-
if (!assetsDir) return;
|
|
12
8
|
if (node.type !== 'element') return;
|
|
13
9
|
if (node.tagName !== 'img') return;
|
|
14
10
|
|
|
@@ -16,39 +12,8 @@ export function rehypeImages(imageService: any, assetsDir: URL | undefined, getI
|
|
|
16
12
|
if (file.dirname) {
|
|
17
13
|
if (!isRelativePath(node.properties.src) && !isAliasedPath(node.properties.src)) return;
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
fileURL = new URL(stripAliasPath(node.properties.src), assetsDir);
|
|
22
|
-
} else {
|
|
23
|
-
fileURL = pathToFileURL(pathJoin(file.dirname, node.properties.src));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const fileData = getImageMetadata!(fileURLToPath(fileURL)) as ImageMetadata;
|
|
27
|
-
fileURL.searchParams.append('origWidth', fileData.width.toString());
|
|
28
|
-
fileURL.searchParams.append('origHeight', fileData.height.toString());
|
|
29
|
-
fileURL.searchParams.append('origFormat', fileData.type.toString());
|
|
30
|
-
|
|
31
|
-
let options = {
|
|
32
|
-
src: {
|
|
33
|
-
src: fileURL,
|
|
34
|
-
width: fileData.width,
|
|
35
|
-
height: fileData.height,
|
|
36
|
-
format: fileData.type,
|
|
37
|
-
},
|
|
38
|
-
alt: node.properties.alt,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const validatedOptions = imageService.validateOptions
|
|
42
|
-
? imageService.validateOptions(options)
|
|
43
|
-
: options;
|
|
44
|
-
|
|
45
|
-
const imageURL = imageService.getURL(validatedOptions);
|
|
46
|
-
node.properties = Object.assign(node.properties, {
|
|
47
|
-
src: imageURL,
|
|
48
|
-
...(imageService.getHTMLAttributes !== undefined
|
|
49
|
-
? imageService.getHTMLAttributes(validatedOptions)
|
|
50
|
-
: {}),
|
|
51
|
-
});
|
|
15
|
+
node.properties['__ASTRO_IMAGE_'] = node.properties.src;
|
|
16
|
+
delete node.properties.src;
|
|
52
17
|
}
|
|
53
18
|
}
|
|
54
19
|
});
|
|
@@ -59,10 +24,6 @@ function isAliasedPath(path: string) {
|
|
|
59
24
|
return path.startsWith('~/assets');
|
|
60
25
|
}
|
|
61
26
|
|
|
62
|
-
function stripAliasPath(path: string) {
|
|
63
|
-
return path.replace('~/assets/', '');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
27
|
function isRelativePath(path: string) {
|
|
67
28
|
return startsWithDotDotSlash(path) || startsWithDotSlash(path);
|
|
68
29
|
}
|
|
@@ -2,9 +2,7 @@ import type { Image } from 'mdast';
|
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
3
|
import type { VFile } from 'vfile';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default function toRemarkCollectImages(resolveImage: OptionalResolveImage) {
|
|
5
|
+
export default function toRemarkCollectImages() {
|
|
8
6
|
return () =>
|
|
9
7
|
async function (tree: any, vfile: VFile) {
|
|
10
8
|
if (typeof vfile?.path !== 'string') return;
|
|
@@ -13,19 +11,6 @@ export default function toRemarkCollectImages(resolveImage: OptionalResolveImage
|
|
|
13
11
|
visit(tree, 'image', function raiseError(node: Image) {
|
|
14
12
|
imagePaths.add(node.url);
|
|
15
13
|
});
|
|
16
|
-
if (imagePaths.size === 0) {
|
|
17
|
-
vfile.data.imagePaths = [];
|
|
18
|
-
return;
|
|
19
|
-
} else if (resolveImage) {
|
|
20
|
-
const mapping = new Map<string, string>();
|
|
21
|
-
for (const path of Array.from(imagePaths)) {
|
|
22
|
-
const id = await resolveImage(path);
|
|
23
|
-
mapping.set(path, id);
|
|
24
|
-
}
|
|
25
|
-
visit(tree, 'image', function raiseError(node: Image) {
|
|
26
|
-
node.url = mapping.get(node.url)!;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
14
|
|
|
30
15
|
vfile.data.imagePaths = Array.from(imagePaths);
|
|
31
16
|
};
|
package/src/types.ts
CHANGED
|
@@ -68,10 +68,6 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
|
|
|
68
68
|
/** Used for frontmatter injection plugins */
|
|
69
69
|
frontmatter?: Record<string, any>;
|
|
70
70
|
experimentalAssets?: boolean;
|
|
71
|
-
imageService?: any;
|
|
72
|
-
assetsDir?: URL;
|
|
73
|
-
resolveImage?: (path: string) => Promise<string>;
|
|
74
|
-
getImageMetadata?: any;
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
export interface MarkdownHeading {
|