@astrojs/markdown-remark 7.0.0-alpha.0 → 7.0.0-beta.10
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/rehype-images.js +20 -4
- package/dist/rehype-prism.js +1 -1
- package/dist/shiki-engine-default.d.ts +2 -0
- package/dist/shiki-engine-default.js +7 -0
- package/dist/shiki-engine-workerd.d.ts +2 -0
- package/dist/shiki-engine-workerd.js +7 -0
- package/dist/shiki.d.ts +2 -1
- package/dist/shiki.js +56 -2
- package/dist/types.d.ts +2 -0
- package/package.json +14 -9
package/dist/rehype-images.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
|
+
const HAST_PRESERVED_PROPERTIES = [
|
|
3
|
+
// HAST: className -> HTML: class
|
|
4
|
+
"className",
|
|
5
|
+
// HAST: htmlFor -> HTML: for
|
|
6
|
+
"htmlFor"
|
|
7
|
+
];
|
|
2
8
|
function rehypeImages() {
|
|
3
9
|
return function(tree, file) {
|
|
4
10
|
if (!file.data.astro?.localImagePaths?.length && !file.data.astro?.remoteImagePaths?.length) {
|
|
@@ -9,11 +15,11 @@ function rehypeImages() {
|
|
|
9
15
|
if (node.tagName !== "img") return;
|
|
10
16
|
if (typeof node.properties?.src !== "string") return;
|
|
11
17
|
const src = decodeURI(node.properties.src);
|
|
12
|
-
let
|
|
18
|
+
let imageProperties;
|
|
13
19
|
if (file.data.astro?.localImagePaths?.includes(src)) {
|
|
14
|
-
|
|
20
|
+
imageProperties = { ...node.properties, src };
|
|
15
21
|
} else if (file.data.astro?.remoteImagePaths?.includes(src)) {
|
|
16
|
-
|
|
22
|
+
imageProperties = {
|
|
17
23
|
// By default, markdown images won't have width and height set. However, just in case another user plugin does set these, we should respect them.
|
|
18
24
|
inferSize: "width" in node.properties && "height" in node.properties ? void 0 : true,
|
|
19
25
|
...node.properties,
|
|
@@ -22,9 +28,19 @@ function rehypeImages() {
|
|
|
22
28
|
} else {
|
|
23
29
|
return;
|
|
24
30
|
}
|
|
31
|
+
const hastProperties = {};
|
|
32
|
+
for (const key of HAST_PRESERVED_PROPERTIES) {
|
|
33
|
+
if (key in imageProperties) {
|
|
34
|
+
hastProperties[key] = imageProperties[key];
|
|
35
|
+
delete imageProperties[key];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
25
38
|
const index = imageOccurrenceMap.get(node.properties.src) || 0;
|
|
26
39
|
imageOccurrenceMap.set(node.properties.src, index + 1);
|
|
27
|
-
node.properties = {
|
|
40
|
+
node.properties = {
|
|
41
|
+
...hastProperties,
|
|
42
|
+
__ASTRO_IMAGE_: JSON.stringify({ ...imageProperties, index })
|
|
43
|
+
};
|
|
28
44
|
});
|
|
29
45
|
};
|
|
30
46
|
}
|
package/dist/rehype-prism.js
CHANGED
|
@@ -7,7 +7,7 @@ const rehypePrism = (excludeLangs) => {
|
|
|
7
7
|
(code, language) => {
|
|
8
8
|
let { html, classLanguage } = runHighlighterWithAstro(language, code);
|
|
9
9
|
return Promise.resolve(
|
|
10
|
-
`<pre class="${classLanguage}" data-language="${language}"><code
|
|
10
|
+
`<pre class="${classLanguage}" data-language="${language}"><code class="${classLanguage}">${html}</code></pre>`
|
|
11
11
|
);
|
|
12
12
|
},
|
|
13
13
|
excludeLangs
|
package/dist/shiki.d.ts
CHANGED
|
@@ -40,4 +40,5 @@ export interface ShikiHighlighterHighlightOptions {
|
|
|
40
40
|
*/
|
|
41
41
|
meta?: string;
|
|
42
42
|
}
|
|
43
|
-
export declare function createShikiHighlighter(
|
|
43
|
+
export declare function createShikiHighlighter(options?: CreateShikiHighlighterOptions): Promise<ShikiHighlighter>;
|
|
44
|
+
export type { ThemePresets };
|
package/dist/shiki.js
CHANGED
|
@@ -3,21 +3,68 @@ import {
|
|
|
3
3
|
createHighlighter,
|
|
4
4
|
isSpecialLang
|
|
5
5
|
} from "shiki";
|
|
6
|
+
import { loadShikiEngine } from "#shiki-engine";
|
|
6
7
|
let _cssVariablesTheme;
|
|
7
8
|
const cssVariablesTheme = () => _cssVariablesTheme ?? (_cssVariablesTheme = createCssVariablesTheme({
|
|
8
9
|
variablePrefix: "--astro-code-"
|
|
9
10
|
}));
|
|
10
|
-
|
|
11
|
+
const cachedHighlighters = /* @__PURE__ */ new Map();
|
|
12
|
+
function clearShikiHighlighterCache() {
|
|
13
|
+
cachedHighlighters.clear();
|
|
14
|
+
}
|
|
15
|
+
function createShikiHighlighter(options) {
|
|
16
|
+
const key = getCacheKey(options);
|
|
17
|
+
let highlighterPromise = cachedHighlighters.get(key);
|
|
18
|
+
if (!highlighterPromise) {
|
|
19
|
+
highlighterPromise = createShikiHighlighterInternal(options);
|
|
20
|
+
cachedHighlighters.set(key, highlighterPromise);
|
|
21
|
+
}
|
|
22
|
+
return ensureLanguagesLoaded(highlighterPromise, options?.langs);
|
|
23
|
+
}
|
|
24
|
+
function getCacheKey(options) {
|
|
25
|
+
const keyCache = [];
|
|
26
|
+
const { theme, themes, langAlias } = options ?? {};
|
|
27
|
+
if (theme) {
|
|
28
|
+
keyCache.push(theme);
|
|
29
|
+
}
|
|
30
|
+
if (themes) {
|
|
31
|
+
keyCache.push(Object.entries(themes).sort());
|
|
32
|
+
}
|
|
33
|
+
if (langAlias) {
|
|
34
|
+
keyCache.push(Object.entries(langAlias).sort());
|
|
35
|
+
}
|
|
36
|
+
return keyCache.length > 0 ? JSON.stringify(keyCache) : "";
|
|
37
|
+
}
|
|
38
|
+
async function ensureLanguagesLoaded(promise, langs) {
|
|
39
|
+
const highlighter = await promise;
|
|
40
|
+
if (!langs) {
|
|
41
|
+
return highlighter;
|
|
42
|
+
}
|
|
43
|
+
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
44
|
+
for (const lang of langs) {
|
|
45
|
+
if (typeof lang === "string" && (isSpecialLang(lang) || loadedLanguages.includes(lang))) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
await highlighter.loadLanguage(lang);
|
|
49
|
+
}
|
|
50
|
+
return highlighter;
|
|
51
|
+
}
|
|
52
|
+
let shikiEngine = void 0;
|
|
53
|
+
async function createShikiHighlighterInternal({
|
|
11
54
|
langs = [],
|
|
12
55
|
theme = "github-dark",
|
|
13
56
|
themes = {},
|
|
14
57
|
langAlias = {}
|
|
15
58
|
} = {}) {
|
|
16
59
|
theme = theme === "css-variables" ? cssVariablesTheme() : theme;
|
|
60
|
+
if (shikiEngine === void 0) {
|
|
61
|
+
shikiEngine = await loadShikiEngine();
|
|
62
|
+
}
|
|
17
63
|
const highlighter = await createHighlighter({
|
|
18
64
|
langs: ["plaintext", ...langs],
|
|
19
65
|
langAlias,
|
|
20
|
-
themes: Object.values(themes).length ? Object.values(themes) : [theme]
|
|
66
|
+
themes: Object.values(themes).length ? Object.values(themes) : [theme],
|
|
67
|
+
engine: shikiEngine
|
|
21
68
|
});
|
|
22
69
|
async function highlight(code, lang = "plaintext", options, to) {
|
|
23
70
|
const resolvedLang = langAlias[lang] ?? lang;
|
|
@@ -98,6 +145,12 @@ async function createShikiHighlighter({
|
|
|
98
145
|
},
|
|
99
146
|
codeToHtml(code, lang, options = {}) {
|
|
100
147
|
return highlight(code, lang, options, "html");
|
|
148
|
+
},
|
|
149
|
+
loadLanguage(...newLangs) {
|
|
150
|
+
return highlighter.loadLanguage(...newLangs);
|
|
151
|
+
},
|
|
152
|
+
getLoadedLanguages() {
|
|
153
|
+
return highlighter.getLoadedLanguages();
|
|
101
154
|
}
|
|
102
155
|
};
|
|
103
156
|
}
|
|
@@ -105,5 +158,6 @@ function normalizePropAsString(value) {
|
|
|
105
158
|
return Array.isArray(value) ? value.join(" ") : value;
|
|
106
159
|
}
|
|
107
160
|
export {
|
|
161
|
+
clearShikiHighlighterCache,
|
|
108
162
|
createShikiHighlighter
|
|
109
163
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -54,6 +54,8 @@ export interface MarkdownProcessor {
|
|
|
54
54
|
render: (content: string, opts?: MarkdownProcessorRenderOptions) => Promise<MarkdownProcessorRenderResult>;
|
|
55
55
|
}
|
|
56
56
|
export interface MarkdownProcessorRenderOptions {
|
|
57
|
+
/** The URL of the file being rendered, used for resolving relative image paths */
|
|
58
|
+
fileURL?: URL;
|
|
57
59
|
/** Used for frontmatter injection plugins */
|
|
58
60
|
frontmatter?: Record<string, any>;
|
|
59
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,12 +13,17 @@
|
|
|
13
13
|
"homepage": "https://astro.build",
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"exports": {
|
|
16
|
-
".": "./dist/index.js"
|
|
16
|
+
".": "./dist/index.js",
|
|
17
|
+
"./shiki": "./dist/shiki.js"
|
|
17
18
|
},
|
|
18
19
|
"imports": {
|
|
19
20
|
"#import-plugin": {
|
|
20
21
|
"browser": "./dist/import-plugin-browser.js",
|
|
21
22
|
"default": "./dist/import-plugin-default.js"
|
|
23
|
+
},
|
|
24
|
+
"#shiki-engine": {
|
|
25
|
+
"workerd": "./dist/shiki-engine-workerd.js",
|
|
26
|
+
"default": "./dist/shiki-engine-default.js"
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
29
|
"files": [
|
|
@@ -28,7 +33,7 @@
|
|
|
28
33
|
"github-slugger": "^2.0.0",
|
|
29
34
|
"hast-util-from-html": "^2.0.3",
|
|
30
35
|
"hast-util-to-text": "^4.0.2",
|
|
31
|
-
"js-yaml": "^4.1.
|
|
36
|
+
"js-yaml": "^4.1.1",
|
|
32
37
|
"mdast-util-definitions": "^6.0.0",
|
|
33
38
|
"rehype-raw": "^7.0.0",
|
|
34
39
|
"rehype-stringify": "^10.0.1",
|
|
@@ -36,15 +41,15 @@
|
|
|
36
41
|
"remark-parse": "^11.0.0",
|
|
37
42
|
"remark-rehype": "^11.1.2",
|
|
38
43
|
"remark-smartypants": "^3.0.2",
|
|
39
|
-
"shiki": "^
|
|
40
|
-
"smol-toml": "^1.
|
|
44
|
+
"shiki": "^4.0.0",
|
|
45
|
+
"smol-toml": "^1.6.0",
|
|
41
46
|
"unified": "^11.0.5",
|
|
42
47
|
"unist-util-remove-position": "^5.0.0",
|
|
43
|
-
"unist-util-visit": "^5.
|
|
48
|
+
"unist-util-visit": "^5.1.0",
|
|
44
49
|
"unist-util-visit-parents": "^6.0.2",
|
|
45
50
|
"vfile": "^6.0.3",
|
|
46
|
-
"@astrojs/prism": "4.0.0-
|
|
47
|
-
"@astrojs/internal-helpers": "0.
|
|
51
|
+
"@astrojs/prism": "4.0.0-beta.2",
|
|
52
|
+
"@astrojs/internal-helpers": "0.8.0-beta.2"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
50
55
|
"@types/estree": "^1.0.8",
|
|
@@ -52,7 +57,7 @@
|
|
|
52
57
|
"@types/js-yaml": "^4.0.9",
|
|
53
58
|
"@types/mdast": "^4.0.4",
|
|
54
59
|
"@types/unist": "^3.0.3",
|
|
55
|
-
"esbuild": "^0.
|
|
60
|
+
"esbuild": "^0.27.3",
|
|
56
61
|
"mdast-util-mdx-expression": "^2.0.1",
|
|
57
62
|
"astro-scripts": "0.0.14"
|
|
58
63
|
},
|