@astrojs/markdown-remark 4.0.1 → 4.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/import-plugin-browser.d.ts +2 -0
- package/dist/import-plugin-browser.js +7 -0
- package/dist/import-plugin-default.d.ts +2 -0
- package/dist/import-plugin-default.js +18 -0
- package/dist/index.js +2 -1
- package/dist/load-plugins.js +4 -13
- package/dist/rehype-images.js +8 -2
- package/dist/shiki.d.ts +1 -1
- package/dist/shiki.js +61 -60
- package/dist/types.d.ts +5 -3
- package/package.json +9 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { resolve as importMetaResolve } from "import-meta-resolve";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
let cwdUrlStr;
|
|
5
|
+
async function importPlugin(p) {
|
|
6
|
+
try {
|
|
7
|
+
const importResult2 = await import(p);
|
|
8
|
+
return importResult2.default;
|
|
9
|
+
} catch {
|
|
10
|
+
}
|
|
11
|
+
cwdUrlStr ??= pathToFileURL(path.join(process.cwd(), "package.json")).toString();
|
|
12
|
+
const resolved = importMetaResolve(p, cwdUrlStr);
|
|
13
|
+
const importResult = await import(resolved);
|
|
14
|
+
return importResult.default;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
importPlugin
|
|
18
|
+
};
|
package/dist/index.js
CHANGED
package/dist/load-plugins.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
-
const cwdUrlStr = pathToFileURL(path.join(process.cwd(), "package.json")).toString();
|
|
1
|
+
import { importPlugin as _importPlugin } from "#import-plugin";
|
|
5
2
|
async function importPlugin(p) {
|
|
6
3
|
if (typeof p === "string") {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} catch {
|
|
11
|
-
}
|
|
12
|
-
const resolved = importMetaResolve(p, cwdUrlStr);
|
|
13
|
-
const importResult = await import(resolved);
|
|
14
|
-
return importResult.default;
|
|
4
|
+
return await _importPlugin(p);
|
|
5
|
+
} else {
|
|
6
|
+
return p;
|
|
15
7
|
}
|
|
16
|
-
return p;
|
|
17
8
|
}
|
|
18
9
|
function loadPlugins(items) {
|
|
19
10
|
return items.map((p) => {
|
package/dist/rehype-images.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
2
|
function rehypeImages() {
|
|
3
3
|
return () => function(tree, file) {
|
|
4
|
+
const imageOccurrenceMap = /* @__PURE__ */ new Map();
|
|
4
5
|
visit(tree, (node) => {
|
|
5
6
|
if (node.type !== "element")
|
|
6
7
|
return;
|
|
@@ -8,8 +9,13 @@ function rehypeImages() {
|
|
|
8
9
|
return;
|
|
9
10
|
if (node.properties?.src) {
|
|
10
11
|
if (file.data.imagePaths?.has(node.properties.src)) {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
const { ...props } = node.properties;
|
|
13
|
+
const index = imageOccurrenceMap.get(node.properties.src) || 0;
|
|
14
|
+
imageOccurrenceMap.set(node.properties.src, index + 1);
|
|
15
|
+
node.properties["__ASTRO_IMAGE_"] = JSON.stringify({ ...props, index });
|
|
16
|
+
Object.keys(props).forEach((prop) => {
|
|
17
|
+
delete node.properties[prop];
|
|
18
|
+
});
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
});
|
package/dist/shiki.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export interface ShikiHighlighter {
|
|
|
4
4
|
inline?: boolean;
|
|
5
5
|
}): string;
|
|
6
6
|
}
|
|
7
|
-
export declare function createShikiHighlighter({ langs, theme, experimentalThemes, wrap, }?: ShikiConfig): Promise<ShikiHighlighter>;
|
|
7
|
+
export declare function createShikiHighlighter({ langs, theme, experimentalThemes, wrap, transformers, }?: ShikiConfig): Promise<ShikiHighlighter>;
|
package/dist/shiki.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
import { bundledLanguages, getHighlighter } from "shikiji";
|
|
1
|
+
import { bundledLanguages, createCssVariablesTheme, getHighlighter } from "shikiji";
|
|
2
2
|
import { visit } from "unist-util-visit";
|
|
3
3
|
const ASTRO_COLOR_REPLACEMENTS = {
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"#000004": "var(--astro-code-token-constant)",
|
|
7
|
-
"#000005": "var(--astro-code-token-string)",
|
|
8
|
-
"#000006": "var(--astro-code-token-comment)",
|
|
9
|
-
"#000007": "var(--astro-code-token-keyword)",
|
|
10
|
-
"#000008": "var(--astro-code-token-parameter)",
|
|
11
|
-
"#000009": "var(--astro-code-token-function)",
|
|
12
|
-
"#000010": "var(--astro-code-token-string-expression)",
|
|
13
|
-
"#000011": "var(--astro-code-token-punctuation)",
|
|
14
|
-
"#000012": "var(--astro-code-token-link)"
|
|
4
|
+
"--astro-code-foreground": "--astro-code-color-text",
|
|
5
|
+
"--astro-code-background": "--astro-code-color-background"
|
|
15
6
|
};
|
|
16
7
|
const COLOR_REPLACEMENT_REGEX = new RegExp(
|
|
17
8
|
`(${Object.keys(ASTRO_COLOR_REPLACEMENTS).join("|")})`,
|
|
18
9
|
"g"
|
|
19
10
|
);
|
|
11
|
+
let _cssVariablesTheme;
|
|
12
|
+
const cssVariablesTheme = () => _cssVariablesTheme ?? (_cssVariablesTheme = createCssVariablesTheme({ variablePrefix: "--astro-code-" }));
|
|
20
13
|
async function createShikiHighlighter({
|
|
21
14
|
langs = [],
|
|
22
15
|
theme = "github-dark",
|
|
23
16
|
experimentalThemes = {},
|
|
24
|
-
wrap = false
|
|
17
|
+
wrap = false,
|
|
18
|
+
transformers = []
|
|
25
19
|
} = {}) {
|
|
26
20
|
const themes = experimentalThemes;
|
|
21
|
+
theme = theme === "css-variables" ? cssVariablesTheme() : theme;
|
|
27
22
|
const highlighter = await getHighlighter({
|
|
28
23
|
langs: langs.length ? langs : Object.keys(bundledLanguages),
|
|
29
24
|
themes: Object.values(themes).length ? Object.values(themes) : [theme]
|
|
@@ -40,61 +35,67 @@ async function createShikiHighlighter({
|
|
|
40
35
|
return highlighter.codeToHtml(code, {
|
|
41
36
|
...themeOptions,
|
|
42
37
|
lang,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
38
|
+
transformers: [
|
|
39
|
+
{
|
|
40
|
+
pre(node) {
|
|
41
|
+
if (inline) {
|
|
42
|
+
node.tagName = "code";
|
|
43
|
+
}
|
|
44
|
+
const classValue = normalizePropAsString(node.properties.class) ?? "";
|
|
45
|
+
const styleValue = normalizePropAsString(node.properties.style) ?? "";
|
|
46
|
+
node.properties.class = classValue.replace(/shiki/g, "astro-code");
|
|
47
|
+
if (wrap === false) {
|
|
48
|
+
node.properties.style = styleValue + "; overflow-x: auto;";
|
|
49
|
+
} else if (wrap === true) {
|
|
50
|
+
node.properties.style = styleValue + "; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;";
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
line(node) {
|
|
54
|
+
if (lang === "diff") {
|
|
55
|
+
const innerSpanNode = node.children[0];
|
|
56
|
+
const innerSpanTextNode = innerSpanNode?.type === "element" && innerSpanNode.children?.[0];
|
|
57
|
+
if (innerSpanTextNode && innerSpanTextNode.type === "text") {
|
|
58
|
+
const start = innerSpanTextNode.value[0];
|
|
59
|
+
if (start === "+" || start === "-") {
|
|
60
|
+
innerSpanTextNode.value = innerSpanTextNode.value.slice(1);
|
|
61
|
+
innerSpanNode.children.unshift({
|
|
62
|
+
type: "element",
|
|
63
|
+
tagName: "span",
|
|
64
|
+
properties: { style: "user-select: none;" },
|
|
65
|
+
children: [{ type: "text", value: start }]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
71
68
|
}
|
|
72
69
|
}
|
|
70
|
+
},
|
|
71
|
+
code(node) {
|
|
72
|
+
if (inline) {
|
|
73
|
+
return node.children[0];
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
root(node) {
|
|
77
|
+
if (Object.values(experimentalThemes).length) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const themeName = typeof theme === "string" ? theme : theme.name;
|
|
81
|
+
if (themeName === "css-variables") {
|
|
82
|
+
visit(node, "element", (child) => {
|
|
83
|
+
if (child.properties?.style) {
|
|
84
|
+
child.properties.style = replaceCssVariables(child.properties.style);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
73
88
|
}
|
|
74
89
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return node.children[0];
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
root(node) {
|
|
81
|
-
if (Object.values(experimentalThemes).length) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const themeName = typeof theme === "string" ? theme : theme.name;
|
|
85
|
-
if (themeName === "css-variables") {
|
|
86
|
-
visit(node, "element", (child) => {
|
|
87
|
-
if (child.properties?.style) {
|
|
88
|
-
child.properties.style = replaceCssVariables(child.properties.style);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
90
|
+
...transformers
|
|
91
|
+
]
|
|
94
92
|
});
|
|
95
93
|
}
|
|
96
94
|
};
|
|
97
95
|
}
|
|
96
|
+
function normalizePropAsString(value) {
|
|
97
|
+
return Array.isArray(value) ? value.join(" ") : value;
|
|
98
|
+
}
|
|
98
99
|
function replaceCssVariables(str) {
|
|
99
100
|
return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match);
|
|
100
101
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as hast from 'hast';
|
|
2
2
|
import type * as mdast from 'mdast';
|
|
3
3
|
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
4
|
-
import type { BuiltinTheme, LanguageRegistration, ThemeRegistration, ThemeRegistrationRaw } from 'shikiji';
|
|
4
|
+
import type { BuiltinTheme, LanguageRegistration, ShikijiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shikiji';
|
|
5
5
|
import type * as unified from 'unified';
|
|
6
6
|
import type { VFile } from 'vfile';
|
|
7
7
|
export type { Node } from 'unist';
|
|
@@ -13,11 +13,13 @@ export type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlug
|
|
|
13
13
|
export type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, hast.Root>;
|
|
14
14
|
export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
|
|
15
15
|
export type RemarkRehype = RemarkRehypeOptions;
|
|
16
|
+
export type ThemePresets = BuiltinTheme | 'css-variables';
|
|
16
17
|
export interface ShikiConfig {
|
|
17
18
|
langs?: LanguageRegistration[];
|
|
18
|
-
theme?:
|
|
19
|
-
experimentalThemes?: Record<string,
|
|
19
|
+
theme?: ThemePresets | ThemeRegistration | ThemeRegistrationRaw;
|
|
20
|
+
experimentalThemes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
|
|
20
21
|
wrap?: boolean | null;
|
|
22
|
+
transformers?: ShikijiTransformer[];
|
|
21
23
|
}
|
|
22
24
|
export interface AstroMarkdownOptions {
|
|
23
25
|
syntaxHighlight?: 'shiki' | 'prism' | false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
".": "./dist/index.js",
|
|
17
17
|
"./dist/internal.js": "./dist/internal.js"
|
|
18
18
|
},
|
|
19
|
+
"imports": {
|
|
20
|
+
"#import-plugin": {
|
|
21
|
+
"browser": "./dist/import-plugin-browser.js",
|
|
22
|
+
"default": "./dist/import-plugin-default.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
19
25
|
"files": [
|
|
20
26
|
"dist"
|
|
21
27
|
],
|
|
@@ -30,7 +36,7 @@
|
|
|
30
36
|
"remark-parse": "^11.0.0",
|
|
31
37
|
"remark-rehype": "^11.0.0",
|
|
32
38
|
"remark-smartypants": "^2.0.0",
|
|
33
|
-
"shikiji": "^0.
|
|
39
|
+
"shikiji": "^0.9.18",
|
|
34
40
|
"unified": "^11.0.4",
|
|
35
41
|
"unist-util-visit": "^5.0.0",
|
|
36
42
|
"vfile": "^6.0.1"
|
|
@@ -43,6 +49,7 @@
|
|
|
43
49
|
"@types/mocha": "^10.0.4",
|
|
44
50
|
"@types/unist": "^3.0.2",
|
|
45
51
|
"chai": "^4.3.7",
|
|
52
|
+
"esbuild": "^0.19.6",
|
|
46
53
|
"mdast-util-mdx-expression": "^2.0.0",
|
|
47
54
|
"mocha": "^10.2.0",
|
|
48
55
|
"astro-scripts": "0.0.14"
|