@astrojs/markdown-remark 2.1.3 → 2.2.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/.turbo/turbo-build.log +4 -5
- package/CHANGELOG.md +20 -0
- package/dist/frontmatter-injection.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -2
- package/dist/remark-collect-images.d.ts +1 -1
- package/dist/remark-collect-images.js +3 -3
- package/dist/remark-shiki.js +17 -0
- package/package.json +5 -5
- package/src/frontmatter-injection.ts +1 -1
- package/src/index.ts +3 -2
- package/src/remark-collect-images.ts +9 -10
- package/src/remark-shiki.ts +20 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[35m@astrojs/markdown-remark:build: [0m
|
|
1
|
+
|
|
2
|
+
> @astrojs/markdown-remark@2.2.0 build /home/runner/work/astro/astro/packages/markdown/remark
|
|
3
|
+
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
|
|
4
|
+
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @astrojs/markdown-remark
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#6932](https://github.com/withastro/astro/pull/6932) [`49514e4ce`](https://github.com/withastro/astro/commit/49514e4ce40fedb39bf7decd2c296258efbdafc7) Thanks [@bluwy](https://github.com/bluwy)! - Upgrade shiki to v0.14.1. This updates the shiki theme colors and adds the theme name to the `pre` tag, e.g. `<pre class="astro-code github-dark">`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`818252acd`](https://github.com/withastro/astro/commit/818252acda3c00499cea51ffa0f26d4c2ccd3a02), [`80e3d4d3d`](https://github.com/withastro/astro/commit/80e3d4d3d0f7719d8eae5435bba3805503057511), [`3326492b9`](https://github.com/withastro/astro/commit/3326492b94f76ed2b0154dd9b9a1a9eb883c1e31), [`cac4a321e`](https://github.com/withastro/astro/commit/cac4a321e814fb805eb0e3ced469e25261a50885), [`831b67cdb`](https://github.com/withastro/astro/commit/831b67cdb8250f93f66e3b171fab024652bf80f2), [`49514e4ce`](https://github.com/withastro/astro/commit/49514e4ce40fedb39bf7decd2c296258efbdafc7), [`0883fd487`](https://github.com/withastro/astro/commit/0883fd4875548a613df122f0b87a1ca8b7a7cf7d)]:
|
|
12
|
+
- astro@2.4.0
|
|
13
|
+
|
|
14
|
+
## 2.1.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#6824](https://github.com/withastro/astro/pull/6824) [`2511d58d5`](https://github.com/withastro/astro/commit/2511d58d586af080a78e5ef8a63020b3e17770db) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Add support for using optimized and relative images in MDX files with `experimental.assets`
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`8539eb164`](https://github.com/withastro/astro/commit/8539eb1643864ae7e0f5a080915cd75535f7101b), [`a9c22994e`](https://github.com/withastro/astro/commit/a9c22994e41f92a586d8946988d29e3c62148778), [`948a6d7be`](https://github.com/withastro/astro/commit/948a6d7be0c76fd1dd8550270bd29821075f799c)]:
|
|
21
|
+
- astro@2.3.0
|
|
22
|
+
|
|
3
23
|
## 2.1.3
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AstroMarkdownOptions, MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
|
|
2
2
|
export { rehypeHeadingIds } from './rehype-collect-headings.js';
|
|
3
|
+
export { remarkCollectImages } from './remark-collect-images.js';
|
|
3
4
|
export * from './types.js';
|
|
4
5
|
export declare const markdownConfigDefaults: Omit<Required<AstroMarkdownOptions>, 'drafts'>;
|
|
5
6
|
/** Shared utility for rendering markdown */
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toRemarkInitializeAstroData } from "./frontmatter-injection.js";
|
|
2
2
|
import { loadPlugins } from "./load-plugins.js";
|
|
3
3
|
import { rehypeHeadingIds } from "./rehype-collect-headings.js";
|
|
4
|
-
import
|
|
4
|
+
import { remarkCollectImages } from "./remark-collect-images.js";
|
|
5
5
|
import remarkPrism from "./remark-prism.js";
|
|
6
6
|
import scopedStyles from "./remark-scoped-styles.js";
|
|
7
7
|
import remarkShiki from "./remark-shiki.js";
|
|
@@ -15,6 +15,7 @@ import { unified } from "unified";
|
|
|
15
15
|
import { VFile } from "vfile";
|
|
16
16
|
import { rehypeImages } from "./rehype-images.js";
|
|
17
17
|
import { rehypeHeadingIds as rehypeHeadingIds2 } from "./rehype-collect-headings.js";
|
|
18
|
+
import { remarkCollectImages as remarkCollectImages2 } from "./remark-collect-images.js";
|
|
18
19
|
export * from "./types.js";
|
|
19
20
|
const markdownConfigDefaults = {
|
|
20
21
|
syntaxHighlight: "shiki",
|
|
@@ -69,7 +70,7 @@ async function renderMarkdown(content, opts) {
|
|
|
69
70
|
parser.use([remarkPrism(scopedClassName)]);
|
|
70
71
|
}
|
|
71
72
|
if (opts.experimentalAssets) {
|
|
72
|
-
parser.use([
|
|
73
|
+
parser.use([remarkCollectImages]);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
parser.use([
|
|
@@ -127,5 +128,6 @@ ${err.message}`;
|
|
|
127
128
|
export {
|
|
128
129
|
markdownConfigDefaults,
|
|
129
130
|
rehypeHeadingIds2 as rehypeHeadingIds,
|
|
131
|
+
remarkCollectImages2 as remarkCollectImages,
|
|
130
132
|
renderMarkdown
|
|
131
133
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { MarkdownVFile } from './types';
|
|
2
|
-
export
|
|
2
|
+
export declare function remarkCollectImages(): (tree: any, vfile: MarkdownVFile) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
|
-
function
|
|
3
|
-
return
|
|
2
|
+
function remarkCollectImages() {
|
|
3
|
+
return function(tree, vfile) {
|
|
4
4
|
if (typeof (vfile == null ? void 0 : vfile.path) !== "string")
|
|
5
5
|
return;
|
|
6
6
|
const imagePaths = /* @__PURE__ */ new Set();
|
|
@@ -23,5 +23,5 @@ function isValidUrl(str) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
export {
|
|
26
|
-
|
|
26
|
+
remarkCollectImages
|
|
27
27
|
};
|
package/dist/remark-shiki.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
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
|
+
};
|
|
4
20
|
const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }, scopedClassName) => {
|
|
21
|
+
theme = normalizeTheme(theme);
|
|
5
22
|
const cacheID = typeof theme === "string" ? theme : theme.name;
|
|
6
23
|
let highlighterAsync = highlighterCacheAsync.get(cacheID);
|
|
7
24
|
if (!highlighterAsync) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
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.
|
|
20
|
+
"astro": "^2.4.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@astrojs/prism": "^2.1.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"remark-parse": "^10.0.1",
|
|
30
30
|
"remark-rehype": "^10.1.0",
|
|
31
31
|
"remark-smartypants": "^2.0.0",
|
|
32
|
-
"shiki": "^0.
|
|
32
|
+
"shiki": "^0.14.1",
|
|
33
33
|
"unified": "^10.1.2",
|
|
34
34
|
"unist-util-visit": "^4.1.0",
|
|
35
35
|
"vfile": "^5.3.2"
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"@types/mdast": "^3.0.10",
|
|
43
43
|
"@types/mocha": "^9.1.1",
|
|
44
44
|
"@types/unist": "^2.0.6",
|
|
45
|
-
"astro-scripts": "0.0.14",
|
|
46
45
|
"chai": "^4.3.6",
|
|
47
46
|
"mdast-util-mdx-expression": "^1.3.1",
|
|
48
|
-
"mocha": "^9.2.2"
|
|
47
|
+
"mocha": "^9.2.2",
|
|
48
|
+
"astro-scripts": "0.0.14"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"prepublish": "pnpm build",
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
import { toRemarkInitializeAstroData } from './frontmatter-injection.js';
|
|
9
9
|
import { loadPlugins } from './load-plugins.js';
|
|
10
10
|
import { rehypeHeadingIds } from './rehype-collect-headings.js';
|
|
11
|
-
import
|
|
11
|
+
import { remarkCollectImages } from './remark-collect-images.js';
|
|
12
12
|
import remarkPrism from './remark-prism.js';
|
|
13
13
|
import scopedStyles from './remark-scoped-styles.js';
|
|
14
14
|
import remarkShiki from './remark-shiki.js';
|
|
@@ -24,6 +24,7 @@ import { VFile } from 'vfile';
|
|
|
24
24
|
import { rehypeImages } from './rehype-images.js';
|
|
25
25
|
|
|
26
26
|
export { rehypeHeadingIds } from './rehype-collect-headings.js';
|
|
27
|
+
export { remarkCollectImages } from './remark-collect-images.js';
|
|
27
28
|
export * from './types.js';
|
|
28
29
|
|
|
29
30
|
export const markdownConfigDefaults: Omit<Required<AstroMarkdownOptions>, 'drafts'> = {
|
|
@@ -96,7 +97,7 @@ export async function renderMarkdown(
|
|
|
96
97
|
|
|
97
98
|
if (opts.experimentalAssets) {
|
|
98
99
|
// Apply later in case user plugins resolve relative image paths
|
|
99
|
-
parser.use([
|
|
100
|
+
parser.use([remarkCollectImages]);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
@@ -2,18 +2,17 @@ import type { Image } from 'mdast';
|
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
3
|
import type { MarkdownVFile } from './types';
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
return ()
|
|
7
|
-
|
|
8
|
-
if (typeof vfile?.path !== 'string') return;
|
|
5
|
+
export function remarkCollectImages() {
|
|
6
|
+
return function (tree: any, vfile: MarkdownVFile) {
|
|
7
|
+
if (typeof vfile?.path !== 'string') return;
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const imagePaths = new Set<string>();
|
|
10
|
+
visit(tree, 'image', (node: Image) => {
|
|
11
|
+
if (shouldOptimizeImage(node.url)) imagePaths.add(node.url);
|
|
12
|
+
});
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
vfile.data.imagePaths = imagePaths;
|
|
15
|
+
};
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
function shouldOptimizeImage(src: string) {
|
package/src/remark-shiki.ts
CHANGED
|
@@ -10,10 +10,30 @@ import type { ShikiConfig } from './types.js';
|
|
|
10
10
|
*/
|
|
11
11
|
const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();
|
|
12
12
|
|
|
13
|
+
// Map of old theme names to new names to preserve compatibility when we upgrade shiki
|
|
14
|
+
const compatThemes: Record<string, string> = {
|
|
15
|
+
'material-darker': 'material-theme-darker',
|
|
16
|
+
'material-default': 'material-theme',
|
|
17
|
+
'material-lighter': 'material-theme-lighter',
|
|
18
|
+
'material-ocean': 'material-theme-ocean',
|
|
19
|
+
'material-palenight': 'material-theme-palenight',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const normalizeTheme = (theme: string | shiki.IShikiTheme) => {
|
|
23
|
+
if (typeof theme === 'string') {
|
|
24
|
+
return compatThemes[theme] || theme;
|
|
25
|
+
} else if (compatThemes[theme.name]) {
|
|
26
|
+
return { ...theme, name: compatThemes[theme.name] };
|
|
27
|
+
} else {
|
|
28
|
+
return theme;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
13
32
|
const remarkShiki = async (
|
|
14
33
|
{ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig,
|
|
15
34
|
scopedClassName?: string | null
|
|
16
35
|
) => {
|
|
36
|
+
theme = normalizeTheme(theme);
|
|
17
37
|
const cacheID: string = typeof theme === 'string' ? theme : theme.name;
|
|
18
38
|
let highlighterAsync = highlighterCacheAsync.get(cacheID);
|
|
19
39
|
if (!highlighterAsync) {
|