@astrojs/markdown-remark 5.1.0 → 5.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/dist/frontmatter-injection.d.ts +1 -1
- package/dist/highlight.d.ts +1 -1
- package/dist/rehype-collect-headings.js +7 -14
- package/dist/rehype-images.js +2 -4
- package/dist/remark-collect-images.js +3 -5
- package/dist/shiki.d.ts +1 -1
- package/dist/shiki.js +2 -0
- package/dist/types.d.ts +3 -2
- package/package.json +14 -16
package/dist/highlight.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ type Highlighter = (code: string, language: string, options?: {
|
|
|
8
8
|
* @param tree
|
|
9
9
|
* The hast tree in which to syntax highlight code blocks.
|
|
10
10
|
* @param highlighter
|
|
11
|
-
* A
|
|
11
|
+
* A function which receives the code and language, and returns the HTML of a syntax
|
|
12
12
|
* highlighted `<pre>` element.
|
|
13
13
|
*/
|
|
14
14
|
export declare function highlightCodeBlocks(tree: Root, highlighter: Highlighter): Promise<void>;
|
|
@@ -10,14 +10,11 @@ function rehypeHeadingIds() {
|
|
|
10
10
|
const isMDX = isMDXFile(file);
|
|
11
11
|
const astroData = safelyGetAstroData(file.data);
|
|
12
12
|
visit(tree, (node) => {
|
|
13
|
-
if (node.type !== "element")
|
|
14
|
-
return;
|
|
13
|
+
if (node.type !== "element") return;
|
|
15
14
|
const { tagName } = node;
|
|
16
|
-
if (tagName[0] !== "h")
|
|
17
|
-
return;
|
|
15
|
+
if (tagName[0] !== "h") return;
|
|
18
16
|
const [, level] = tagName.match(/h([0-6])/) ?? [];
|
|
19
|
-
if (!level)
|
|
20
|
-
return;
|
|
17
|
+
if (!level) return;
|
|
21
18
|
const depth = Number.parseInt(level);
|
|
22
19
|
let text = "";
|
|
23
20
|
visit(node, (child, __, parent) => {
|
|
@@ -50,8 +47,7 @@ function rehypeHeadingIds() {
|
|
|
50
47
|
node.properties = node.properties || {};
|
|
51
48
|
if (typeof node.properties.id !== "string") {
|
|
52
49
|
let slug = slugger.slug(text);
|
|
53
|
-
if (slug.endsWith("-"))
|
|
54
|
-
slug = slug.slice(0, -1);
|
|
50
|
+
if (slug.endsWith("-")) slug = slug.slice(0, -1);
|
|
55
51
|
node.properties.id = slug;
|
|
56
52
|
}
|
|
57
53
|
headings.push({ depth, slug: node.properties.id, text });
|
|
@@ -63,8 +59,7 @@ function isMDXFile(file) {
|
|
|
63
59
|
return Boolean(file.history[0]?.endsWith(".mdx"));
|
|
64
60
|
}
|
|
65
61
|
function getMdxFrontmatterVariablePath(node) {
|
|
66
|
-
if (!node.data?.estree || node.data.estree.body.length !== 1)
|
|
67
|
-
return new Error();
|
|
62
|
+
if (!node.data?.estree || node.data.estree.body.length !== 1) return new Error();
|
|
68
63
|
const statement = node.data.estree.body[0];
|
|
69
64
|
if (statement?.type !== "ExpressionStatement" || statement.expression.type !== "MemberExpression")
|
|
70
65
|
return new Error();
|
|
@@ -76,15 +71,13 @@ function getMdxFrontmatterVariablePath(node) {
|
|
|
76
71
|
);
|
|
77
72
|
expression = expression.object;
|
|
78
73
|
}
|
|
79
|
-
if (expression.type !== "Identifier" || expression.name !== "frontmatter")
|
|
80
|
-
return new Error();
|
|
74
|
+
if (expression.type !== "Identifier" || expression.name !== "frontmatter") return new Error();
|
|
81
75
|
return expressionPath.reverse();
|
|
82
76
|
}
|
|
83
77
|
function getMdxFrontmatterVariableValue(astroData, path) {
|
|
84
78
|
let value = astroData.frontmatter;
|
|
85
79
|
for (const key of path) {
|
|
86
|
-
if (!value[key])
|
|
87
|
-
return void 0;
|
|
80
|
+
if (!value[key]) return void 0;
|
|
88
81
|
value = value[key];
|
|
89
82
|
}
|
|
90
83
|
return value;
|
package/dist/rehype-images.js
CHANGED
|
@@ -3,10 +3,8 @@ function rehypeImages() {
|
|
|
3
3
|
return () => function(tree, file) {
|
|
4
4
|
const imageOccurrenceMap = /* @__PURE__ */ new Map();
|
|
5
5
|
visit(tree, (node) => {
|
|
6
|
-
if (node.type !== "element")
|
|
7
|
-
|
|
8
|
-
if (node.tagName !== "img")
|
|
9
|
-
return;
|
|
6
|
+
if (node.type !== "element") return;
|
|
7
|
+
if (node.tagName !== "img") return;
|
|
10
8
|
if (node.properties?.src) {
|
|
11
9
|
node.properties.src = decodeURI(node.properties.src);
|
|
12
10
|
if (file.data.imagePaths?.has(node.properties.src)) {
|
|
@@ -2,20 +2,18 @@ import { definitions } from "mdast-util-definitions";
|
|
|
2
2
|
import { visit } from "unist-util-visit";
|
|
3
3
|
function remarkCollectImages() {
|
|
4
4
|
return function(tree, vfile) {
|
|
5
|
-
if (typeof vfile?.path !== "string")
|
|
6
|
-
return;
|
|
5
|
+
if (typeof vfile?.path !== "string") return;
|
|
7
6
|
const definition = definitions(tree);
|
|
8
7
|
const imagePaths = /* @__PURE__ */ new Set();
|
|
9
8
|
visit(tree, ["image", "imageReference"], (node) => {
|
|
10
9
|
if (node.type === "image") {
|
|
11
|
-
if (shouldOptimizeImage(node.url))
|
|
12
|
-
imagePaths.add(node.url);
|
|
10
|
+
if (shouldOptimizeImage(node.url)) imagePaths.add(decodeURI(node.url));
|
|
13
11
|
}
|
|
14
12
|
if (node.type === "imageReference") {
|
|
15
13
|
const imageDefinition = definition(node.identifier);
|
|
16
14
|
if (imageDefinition) {
|
|
17
15
|
if (shouldOptimizeImage(imageDefinition.url))
|
|
18
|
-
imagePaths.add(imageDefinition.url);
|
|
16
|
+
imagePaths.add(decodeURI(imageDefinition.url));
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
19
|
});
|
package/dist/shiki.d.ts
CHANGED
|
@@ -9,4 +9,4 @@ export interface ShikiHighlighter {
|
|
|
9
9
|
meta?: string;
|
|
10
10
|
}): Promise<string>;
|
|
11
11
|
}
|
|
12
|
-
export declare function createShikiHighlighter({ langs, theme, themes, wrap, transformers, }?: ShikiConfig): Promise<ShikiHighlighter>;
|
|
12
|
+
export declare function createShikiHighlighter({ langs, theme, themes, defaultColor, wrap, transformers, }?: ShikiConfig): Promise<ShikiHighlighter>;
|
package/dist/shiki.js
CHANGED
|
@@ -18,6 +18,7 @@ async function createShikiHighlighter({
|
|
|
18
18
|
langs = [],
|
|
19
19
|
theme = "github-dark",
|
|
20
20
|
themes = {},
|
|
21
|
+
defaultColor,
|
|
21
22
|
wrap = false,
|
|
22
23
|
transformers = []
|
|
23
24
|
} = {}) {
|
|
@@ -43,6 +44,7 @@ async function createShikiHighlighter({
|
|
|
43
44
|
const inline = options?.inline ?? false;
|
|
44
45
|
return highlighter.codeToHtml(code, {
|
|
45
46
|
...themeOptions,
|
|
47
|
+
defaultColor,
|
|
46
48
|
lang,
|
|
47
49
|
// NOTE: while we can spread `options.attributes` here so that Shiki can auto-serialize this as rendered
|
|
48
50
|
// attributes on the top-level tag, it's not clear whether it is fine to pass all attributes as meta, as
|
package/dist/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type * as mdast from 'mdast';
|
|
|
3
3
|
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
4
4
|
import type { BuiltinTheme, LanguageRegistration, ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
|
|
5
5
|
import type * as unified from 'unified';
|
|
6
|
-
import type { VFile } from 'vfile';
|
|
6
|
+
import type { DataMap, VFile } from 'vfile';
|
|
7
7
|
export type { Node } from 'unist';
|
|
8
8
|
export type MarkdownAstroData = {
|
|
9
9
|
frontmatter: Record<string, any>;
|
|
@@ -18,6 +18,7 @@ export interface ShikiConfig {
|
|
|
18
18
|
langs?: LanguageRegistration[];
|
|
19
19
|
theme?: ThemePresets | ThemeRegistration | ThemeRegistrationRaw;
|
|
20
20
|
themes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
|
|
21
|
+
defaultColor?: 'light' | 'dark' | string | false;
|
|
21
22
|
wrap?: boolean | null;
|
|
22
23
|
transformers?: ShikiTransformer[];
|
|
23
24
|
}
|
|
@@ -51,7 +52,7 @@ export interface MarkdownHeading {
|
|
|
51
52
|
text: string;
|
|
52
53
|
}
|
|
53
54
|
export interface MarkdownVFile extends VFile {
|
|
54
|
-
data: {
|
|
55
|
+
data: Record<string, unknown> & Partial<DataMap> & {
|
|
55
56
|
__astroHeadings?: MarkdownHeading[];
|
|
56
57
|
imagePaths?: Set<string>;
|
|
57
58
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,33 +26,31 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@astrojs/prism": "^3.1.0",
|
|
30
29
|
"github-slugger": "^2.0.0",
|
|
31
|
-
"hast-util-from-html": "^2.0.
|
|
32
|
-
"hast-util-to-text": "^4.0.
|
|
33
|
-
"import-meta-resolve": "^4.
|
|
30
|
+
"hast-util-from-html": "^2.0.1",
|
|
31
|
+
"hast-util-to-text": "^4.0.2",
|
|
32
|
+
"import-meta-resolve": "^4.1.0",
|
|
34
33
|
"mdast-util-definitions": "^6.0.0",
|
|
35
34
|
"rehype-raw": "^7.0.0",
|
|
36
35
|
"rehype-stringify": "^10.0.0",
|
|
37
36
|
"remark-gfm": "^4.0.0",
|
|
38
37
|
"remark-parse": "^11.0.0",
|
|
39
|
-
"remark-rehype": "^11.
|
|
40
|
-
"remark-smartypants": "^
|
|
41
|
-
"shiki": "^1.
|
|
42
|
-
"unified": "^11.0.
|
|
38
|
+
"remark-rehype": "^11.1.0",
|
|
39
|
+
"remark-smartypants": "^3.0.2",
|
|
40
|
+
"shiki": "^1.10.3",
|
|
41
|
+
"unified": "^11.0.5",
|
|
43
42
|
"unist-util-remove-position": "^5.0.0",
|
|
44
43
|
"unist-util-visit": "^5.0.0",
|
|
45
|
-
"unist-util-visit-parents": "^6.0.
|
|
46
|
-
"vfile": "^6.0.
|
|
44
|
+
"unist-util-visit-parents": "^6.0.1",
|
|
45
|
+
"vfile": "^6.0.2",
|
|
46
|
+
"@astrojs/prism": "3.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/chai": "^4.3.10",
|
|
50
49
|
"@types/estree": "^1.0.5",
|
|
51
|
-
"@types/hast": "^3.0.
|
|
52
|
-
"@types/mdast": "^4.0.
|
|
53
|
-
"@types/mocha": "^10.0.4",
|
|
50
|
+
"@types/hast": "^3.0.4",
|
|
51
|
+
"@types/mdast": "^4.0.4",
|
|
54
52
|
"@types/unist": "^3.0.2",
|
|
55
|
-
"esbuild": "^0.
|
|
53
|
+
"esbuild": "^0.21.5",
|
|
56
54
|
"mdast-util-mdx-expression": "^2.0.0",
|
|
57
55
|
"astro-scripts": "0.0.14"
|
|
58
56
|
},
|