@astrojs/mdx 1.0.1 → 1.0.3
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/index.js +2 -0
- package/dist/plugins.js +7 -4
- package/package.json +4 -7
- package/dist/remark-prism.d.ts +0 -2
- package/dist/remark-prism.js +0 -17
- package/dist/remark-shiki.d.ts +0 -3
- package/dist/remark-shiki.js +0 -69
package/dist/index.js
CHANGED
package/dist/plugins.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
rehypeHeadingIds,
|
|
3
|
+
remarkCollectImages,
|
|
4
|
+
remarkPrism,
|
|
5
|
+
remarkShiki
|
|
6
|
+
} from "@astrojs/markdown-remark";
|
|
2
7
|
import {
|
|
3
8
|
InvalidAstroDataError,
|
|
4
9
|
safelyGetAstroData
|
|
@@ -12,8 +17,6 @@ import { rehypeInjectHeadingsExport } from "./rehype-collect-headings.js";
|
|
|
12
17
|
import rehypeMetaString from "./rehype-meta-string.js";
|
|
13
18
|
import { rehypeOptimizeStatic } from "./rehype-optimize-static.js";
|
|
14
19
|
import { remarkImageToComponent } from "./remark-images-to-component.js";
|
|
15
|
-
import remarkPrism from "./remark-prism.js";
|
|
16
|
-
import remarkShiki from "./remark-shiki.js";
|
|
17
20
|
import { jsToTreeNode } from "./utils.js";
|
|
18
21
|
const isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);
|
|
19
22
|
function recmaInjectImportMetaEnvPlugin({
|
|
@@ -91,7 +94,7 @@ async function getRemarkPlugins(mdxOptions) {
|
|
|
91
94
|
remarkPlugins = [...remarkPlugins, ...mdxOptions.remarkPlugins];
|
|
92
95
|
if (!isPerformanceBenchmark) {
|
|
93
96
|
if (mdxOptions.syntaxHighlight === "shiki") {
|
|
94
|
-
remarkPlugins.push([
|
|
97
|
+
remarkPlugins.push([remarkShiki, mdxOptions.shikiConfig]);
|
|
95
98
|
}
|
|
96
99
|
if (mdxOptions.syntaxHighlight === "prism") {
|
|
97
100
|
remarkPlugins.push(remarkPrism);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/mdx",
|
|
3
3
|
"description": "Add support for MDX pages in your Astro site",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -36,18 +36,15 @@
|
|
|
36
36
|
"hast-util-to-html": "^8.0.4",
|
|
37
37
|
"kleur": "^4.1.4",
|
|
38
38
|
"rehype-raw": "^6.1.1",
|
|
39
|
-
"remark-frontmatter": "^4.0.1",
|
|
40
39
|
"remark-gfm": "^3.0.1",
|
|
41
40
|
"remark-smartypants": "^2.0.0",
|
|
42
|
-
"shiki": "^0.14.3",
|
|
43
41
|
"source-map": "^0.7.4",
|
|
44
42
|
"unist-util-visit": "^4.1.2",
|
|
45
43
|
"vfile": "^5.3.7",
|
|
46
|
-
"@astrojs/markdown-remark": "3.
|
|
47
|
-
"@astrojs/prism": "3.0.0"
|
|
44
|
+
"@astrojs/markdown-remark": "3.1.0"
|
|
48
45
|
},
|
|
49
46
|
"peerDependencies": {
|
|
50
|
-
"astro": "^3.0.
|
|
47
|
+
"astro": "^3.0.11"
|
|
51
48
|
},
|
|
52
49
|
"devDependencies": {
|
|
53
50
|
"@types/chai": "^4.3.5",
|
|
@@ -69,7 +66,7 @@
|
|
|
69
66
|
"remark-shiki-twoslash": "^3.1.3",
|
|
70
67
|
"remark-toc": "^8.0.1",
|
|
71
68
|
"vite": "^4.4.9",
|
|
72
|
-
"astro": "3.0.
|
|
69
|
+
"astro": "3.0.11",
|
|
73
70
|
"astro-scripts": "0.0.14"
|
|
74
71
|
},
|
|
75
72
|
"engines": {
|
package/dist/remark-prism.d.ts
DELETED
package/dist/remark-prism.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { runHighlighterWithAstro } from "@astrojs/prism/dist/highlighter";
|
|
2
|
-
import { visit } from "unist-util-visit";
|
|
3
|
-
function remarkPrism() {
|
|
4
|
-
return (tree) => visit(tree, "code", (node) => {
|
|
5
|
-
let { lang, value } = node;
|
|
6
|
-
node.type = "html";
|
|
7
|
-
let { html, classLanguage } = runHighlighterWithAstro(lang, value);
|
|
8
|
-
let classes = [classLanguage];
|
|
9
|
-
node.value = `<pre class="${classes.join(
|
|
10
|
-
" "
|
|
11
|
-
)}"><code class="${classLanguage}">${html}</code></pre>`;
|
|
12
|
-
return node;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
remarkPrism as default
|
|
17
|
-
};
|
package/dist/remark-shiki.d.ts
DELETED
package/dist/remark-shiki.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { getHighlighter } from "shiki";
|
|
2
|
-
import { visit } from "unist-util-visit";
|
|
3
|
-
const highlighterCacheAsync = /* @__PURE__ */ new Map();
|
|
4
|
-
const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }) => {
|
|
5
|
-
const cacheID = typeof theme === "string" ? theme : theme.name;
|
|
6
|
-
let highlighterAsync = highlighterCacheAsync.get(cacheID);
|
|
7
|
-
if (!highlighterAsync) {
|
|
8
|
-
highlighterAsync = getHighlighter({ theme }).then((hl) => {
|
|
9
|
-
hl.setColorReplacements({
|
|
10
|
-
"#000001": "var(--astro-code-color-text)",
|
|
11
|
-
"#000002": "var(--astro-code-color-background)",
|
|
12
|
-
"#000004": "var(--astro-code-token-constant)",
|
|
13
|
-
"#000005": "var(--astro-code-token-string)",
|
|
14
|
-
"#000006": "var(--astro-code-token-comment)",
|
|
15
|
-
"#000007": "var(--astro-code-token-keyword)",
|
|
16
|
-
"#000008": "var(--astro-code-token-parameter)",
|
|
17
|
-
"#000009": "var(--astro-code-token-function)",
|
|
18
|
-
"#000010": "var(--astro-code-token-string-expression)",
|
|
19
|
-
"#000011": "var(--astro-code-token-punctuation)",
|
|
20
|
-
"#000012": "var(--astro-code-token-link)"
|
|
21
|
-
});
|
|
22
|
-
return hl;
|
|
23
|
-
});
|
|
24
|
-
highlighterCacheAsync.set(cacheID, highlighterAsync);
|
|
25
|
-
}
|
|
26
|
-
const highlighter = await highlighterAsync;
|
|
27
|
-
for (const lang of langs) {
|
|
28
|
-
await highlighter.loadLanguage(lang);
|
|
29
|
-
}
|
|
30
|
-
return () => (tree) => {
|
|
31
|
-
visit(tree, "code", (node) => {
|
|
32
|
-
let lang;
|
|
33
|
-
if (typeof node.lang === "string") {
|
|
34
|
-
const langExists = highlighter.getLoadedLanguages().includes(node.lang);
|
|
35
|
-
if (langExists) {
|
|
36
|
-
lang = node.lang;
|
|
37
|
-
} else {
|
|
38
|
-
console.warn(`The language "${node.lang}" doesn't exist, falling back to plaintext.`);
|
|
39
|
-
lang = "plaintext";
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
lang = "plaintext";
|
|
43
|
-
}
|
|
44
|
-
let html = highlighter.codeToHtml(node.value, { lang });
|
|
45
|
-
html = html.replace(/<pre class="(.*?)shiki(.*?)"/, `<pre class="$1astro-code$2"`);
|
|
46
|
-
if (node.lang === "diff") {
|
|
47
|
-
html = html.replace(
|
|
48
|
-
/<span class="line"><span style="(.*?)">([\+|\-])/g,
|
|
49
|
-
'<span class="line"><span style="$1"><span style="user-select: none;">$2</span>'
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
if (wrap === false) {
|
|
53
|
-
html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto;"');
|
|
54
|
-
} else if (wrap === true) {
|
|
55
|
-
html = html.replace(
|
|
56
|
-
/style="(.*?)"/,
|
|
57
|
-
'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"'
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
node.type = "html";
|
|
61
|
-
node.value = html;
|
|
62
|
-
node.children = [];
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
var remark_shiki_default = remarkShiki;
|
|
67
|
-
export {
|
|
68
|
-
remark_shiki_default as default
|
|
69
|
-
};
|