@astrojs/mdx 1.0.2 → 1.1.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/index.js CHANGED
@@ -1,13 +1,15 @@
1
- import { markdownConfigDefaults } from "@astrojs/markdown-remark";
2
- import { toRemarkInitializeAstroData } from "@astrojs/markdown-remark/dist/internal.js";
3
- import { compile as mdxCompile } from "@mdx-js/mdx";
1
+ import { markdownConfigDefaults, setVfileFrontmatter } from "@astrojs/markdown-remark";
4
2
  import astroJSXRenderer from "astro/jsx/renderer.js";
5
3
  import { parse as parseESM } from "es-module-lexer";
6
4
  import fs from "node:fs/promises";
7
5
  import { fileURLToPath } from "node:url";
8
- import { SourceMapGenerator } from "source-map";
9
6
  import { VFile } from "vfile";
10
- import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from "./plugins.js";
7
+ import { createMdxProcessor } from "./plugins.js";
8
+ import {
9
+ ASTRO_IMAGE_ELEMENT,
10
+ ASTRO_IMAGE_IMPORT,
11
+ USES_ASTRO_IMAGE_FLAG
12
+ } from "./remark-images-to-component.js";
11
13
  import { getFileInfo, ignoreStringPlugins, parseFrontmatter } from "./utils.js";
12
14
  function mdx(partialMdxOptions = {}) {
13
15
  return {
@@ -50,20 +52,7 @@ function mdx(partialMdxOptions = {}) {
50
52
  extendMarkdownConfig ? config.markdown : markdownConfigDefaults
51
53
  )
52
54
  });
53
- const mdxPluginOpts = {
54
- remarkPlugins: await getRemarkPlugins(mdxOptions),
55
- rehypePlugins: getRehypePlugins(mdxOptions),
56
- recmaPlugins: mdxOptions.recmaPlugins,
57
- remarkRehypeOptions: mdxOptions.remarkRehype,
58
- jsx: true,
59
- jsxImportSource: "astro",
60
- // Note: disable `.md` (and other alternative extensions for markdown files like `.markdown`) support
61
- format: "mdx",
62
- mdExtensions: []
63
- };
64
- let importMetaEnv = {
65
- SITE: config.site
66
- };
55
+ let processor;
67
56
  updateConfig({
68
57
  vite: {
69
58
  plugins: [
@@ -71,7 +60,10 @@ function mdx(partialMdxOptions = {}) {
71
60
  name: "@mdx-js/rollup",
72
61
  enforce: "pre",
73
62
  configResolved(resolved) {
74
- importMetaEnv = { ...importMetaEnv, ...resolved.env };
63
+ processor = createMdxProcessor(mdxOptions, {
64
+ sourcemap: !!resolved.build.sourcemap,
65
+ importMetaEnv: { SITE: config.site, ...resolved.env }
66
+ });
75
67
  const jsxPluginIndex = resolved.plugins.findIndex((p) => p.name === "astro:jsx");
76
68
  if (jsxPluginIndex !== -1) {
77
69
  const myPluginIndex = resolved.plugins.findIndex(
@@ -92,21 +84,10 @@ function mdx(partialMdxOptions = {}) {
92
84
  const { fileId } = getFileInfo(id, config);
93
85
  const code = await fs.readFile(fileId, "utf-8");
94
86
  const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id);
87
+ const vfile = new VFile({ value: pageContent, path: id });
88
+ setVfileFrontmatter(vfile, frontmatter);
95
89
  try {
96
- const compiled = await mdxCompile(new VFile({ value: pageContent, path: id }), {
97
- ...mdxPluginOpts,
98
- elementAttributeNameCase: "html",
99
- remarkPlugins: [
100
- // Ensure `data.astro` is available to all remark plugins
101
- toRemarkInitializeAstroData({ userFrontmatter: frontmatter }),
102
- ...mdxPluginOpts.remarkPlugins ?? []
103
- ],
104
- recmaPlugins: [
105
- ...mdxPluginOpts.recmaPlugins ?? [],
106
- () => recmaInjectImportMetaEnvPlugin({ importMetaEnv })
107
- ],
108
- SourceMapGenerator: config.vite.build?.sourcemap ? SourceMapGenerator : void 0
109
- });
90
+ const compiled = await processor.process(vfile);
110
91
  return {
111
92
  code: escapeViteEnvReferences(String(compiled.value)),
112
93
  map: compiled.map
@@ -145,11 +126,19 @@ export const file = ${JSON.stringify(fileId)};`;
145
126
  }
146
127
  if (!moduleExports.find(({ n }) => n === "Content")) {
147
128
  const hasComponents = moduleExports.find(({ n }) => n === "components");
129
+ const usesAstroImage = moduleExports.find(
130
+ ({ n }) => n === USES_ASTRO_IMAGE_FLAG
131
+ );
132
+ let componentsCode = `{ Fragment${hasComponents ? ", ...components" : ""}, ...props.components,`;
133
+ if (usesAstroImage) {
134
+ componentsCode += ` ${JSON.stringify(ASTRO_IMAGE_ELEMENT)}: ${hasComponents ? "components.img ?? " : ""} props.components?.img ?? ${ASTRO_IMAGE_IMPORT}`;
135
+ }
136
+ componentsCode += " }";
148
137
  code = code.replace("export default MDXContent;", "");
149
138
  code += `
150
139
  export const Content = (props = {}) => MDXContent({
151
140
  ...props,
152
- components: { Fragment${hasComponents ? ", ...components" : ""}, ...props.components },
141
+ components: ${componentsCode},
153
142
  });
154
143
  export default Content;`;
155
144
  }
package/dist/plugins.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
2
- import type { VFile } from 'vfile';
1
+ import type { Processor } from 'unified';
3
2
  import type { MdxOptions } from './index.js';
4
- export declare function recmaInjectImportMetaEnvPlugin({ importMetaEnv, }: {
3
+ interface MdxProcessorExtraOptions {
4
+ sourcemap: boolean;
5
5
  importMetaEnv: Record<string, any>;
6
- }): (tree: any) => void;
7
- export declare function rehypeApplyFrontmatterExport(): (tree: any, vfile: VFile) => void;
8
- export declare function getRemarkPlugins(mdxOptions: MdxOptions): Promise<PluggableList>;
9
- export declare function getRehypePlugins(mdxOptions: MdxOptions): PluggableList;
6
+ }
7
+ export declare function createMdxProcessor(mdxOptions: MdxOptions, extraOptions: MdxProcessorExtraOptions): Processor;
8
+ export {};
package/dist/plugins.js CHANGED
@@ -1,84 +1,37 @@
1
- import { rehypeHeadingIds, remarkCollectImages } from "@astrojs/markdown-remark";
2
1
  import {
3
- InvalidAstroDataError,
4
- safelyGetAstroData
5
- } from "@astrojs/markdown-remark/dist/internal.js";
6
- import { nodeTypes } from "@mdx-js/mdx";
7
- import { visit as estreeVisit } from "estree-util-visit";
2
+ rehypeHeadingIds,
3
+ remarkCollectImages,
4
+ remarkPrism,
5
+ remarkShiki
6
+ } from "@astrojs/markdown-remark";
7
+ import { createProcessor, nodeTypes } from "@mdx-js/mdx";
8
8
  import rehypeRaw from "rehype-raw";
9
9
  import remarkGfm from "remark-gfm";
10
10
  import remarkSmartypants from "remark-smartypants";
11
+ import { SourceMapGenerator } from "source-map";
12
+ import { recmaInjectImportMetaEnv } from "./recma-inject-import-meta-env.js";
13
+ import { rehypeApplyFrontmatterExport } from "./rehype-apply-frontmatter-export.js";
11
14
  import { rehypeInjectHeadingsExport } from "./rehype-collect-headings.js";
12
15
  import rehypeMetaString from "./rehype-meta-string.js";
13
16
  import { rehypeOptimizeStatic } from "./rehype-optimize-static.js";
14
17
  import { remarkImageToComponent } from "./remark-images-to-component.js";
15
- import remarkPrism from "./remark-prism.js";
16
- import remarkShiki from "./remark-shiki.js";
17
- import { jsToTreeNode } from "./utils.js";
18
18
  const isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);
19
- function recmaInjectImportMetaEnvPlugin({
20
- importMetaEnv
21
- }) {
22
- return (tree) => {
23
- estreeVisit(tree, (node) => {
24
- if (node.type === "MemberExpression") {
25
- const envVarName = getImportMetaEnvVariableName(node);
26
- if (typeof envVarName === "string") {
27
- for (const key in node) {
28
- delete node[key];
29
- }
30
- const envVarLiteral = {
31
- type: "Literal",
32
- value: importMetaEnv[envVarName],
33
- raw: JSON.stringify(importMetaEnv[envVarName])
34
- };
35
- Object.assign(node, envVarLiteral);
36
- }
37
- }
38
- });
39
- };
19
+ function createMdxProcessor(mdxOptions, extraOptions) {
20
+ return createProcessor({
21
+ remarkPlugins: getRemarkPlugins(mdxOptions),
22
+ rehypePlugins: getRehypePlugins(mdxOptions),
23
+ recmaPlugins: getRecmaPlugins(mdxOptions, extraOptions.importMetaEnv),
24
+ remarkRehypeOptions: mdxOptions.remarkRehype,
25
+ jsx: true,
26
+ jsxImportSource: "astro",
27
+ // Note: disable `.md` (and other alternative extensions for markdown files like `.markdown`) support
28
+ format: "mdx",
29
+ mdExtensions: [],
30
+ elementAttributeNameCase: "html",
31
+ SourceMapGenerator: extraOptions.sourcemap ? SourceMapGenerator : void 0
32
+ });
40
33
  }
41
- function rehypeApplyFrontmatterExport() {
42
- return function(tree, vfile) {
43
- const astroData = safelyGetAstroData(vfile.data);
44
- if (astroData instanceof InvalidAstroDataError)
45
- throw new Error(
46
- // Copied from Astro core `errors-data`
47
- // TODO: find way to import error data from core
48
- '[MDX] A remark or rehype plugin attempted to inject invalid frontmatter. Ensure "astro.frontmatter" is set to a valid JSON object that is not `null` or `undefined`.'
49
- );
50
- const { frontmatter } = astroData;
51
- const exportNodes = [
52
- jsToTreeNode(`export const frontmatter = ${JSON.stringify(frontmatter)};`)
53
- ];
54
- if (frontmatter.layout) {
55
- exportNodes.unshift(
56
- jsToTreeNode(
57
- /** @see 'vite-plugin-markdown' for layout props reference */
58
- `import { jsx as layoutJsx } from 'astro/jsx-runtime';
59
-
60
- export default async function ({ children }) {
61
- const Layout = (await import(${JSON.stringify(frontmatter.layout)})).default;
62
- const { layout, ...content } = frontmatter;
63
- content.file = file;
64
- content.url = url;
65
- return layoutJsx(Layout, {
66
- file,
67
- url,
68
- content,
69
- frontmatter: content,
70
- headings: getHeadings(),
71
- 'server:root': true,
72
- children,
73
- });
74
- };`
75
- )
76
- );
77
- }
78
- tree.children = exportNodes.concat(tree.children);
79
- };
80
- }
81
- async function getRemarkPlugins(mdxOptions) {
34
+ function getRemarkPlugins(mdxOptions) {
82
35
  let remarkPlugins = [remarkCollectImages, remarkImageToComponent];
83
36
  if (!isPerformanceBenchmark) {
84
37
  if (mdxOptions.gfm) {
@@ -91,7 +44,7 @@ async function getRemarkPlugins(mdxOptions) {
91
44
  remarkPlugins = [...remarkPlugins, ...mdxOptions.remarkPlugins];
92
45
  if (!isPerformanceBenchmark) {
93
46
  if (mdxOptions.syntaxHighlight === "shiki") {
94
- remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]);
47
+ remarkPlugins.push([remarkShiki, mdxOptions.shikiConfig]);
95
48
  }
96
49
  if (mdxOptions.syntaxHighlight === "prism") {
97
50
  remarkPlugins.push(remarkPrism);
@@ -121,29 +74,9 @@ function getRehypePlugins(mdxOptions) {
121
74
  }
122
75
  return rehypePlugins;
123
76
  }
124
- function getImportMetaEnvVariableName(node) {
125
- try {
126
- if (node.object.type !== "MemberExpression" || node.property.type !== "Identifier")
127
- return new Error();
128
- const nestedExpression = node.object;
129
- if (nestedExpression.property.type !== "Identifier" || nestedExpression.property.name !== "env")
130
- return new Error();
131
- const envExpression = nestedExpression.object;
132
- if (envExpression.type !== "MetaProperty" || envExpression.property.type !== "Identifier" || envExpression.property.name !== "meta")
133
- return new Error();
134
- if (envExpression.meta.name !== "import")
135
- return new Error();
136
- return node.property.name;
137
- } catch (e) {
138
- if (e instanceof Error) {
139
- return e;
140
- }
141
- return new Error("Unknown parsing error");
142
- }
77
+ function getRecmaPlugins(mdxOptions, importMetaEnv) {
78
+ return [...mdxOptions.recmaPlugins ?? [], [recmaInjectImportMetaEnv, { importMetaEnv }]];
143
79
  }
144
80
  export {
145
- getRehypePlugins,
146
- getRemarkPlugins,
147
- recmaInjectImportMetaEnvPlugin,
148
- rehypeApplyFrontmatterExport
81
+ createMdxProcessor
149
82
  };
@@ -0,0 +1,3 @@
1
+ export declare function recmaInjectImportMetaEnv({ importMetaEnv, }: {
2
+ importMetaEnv: Record<string, any>;
3
+ }): (tree: any) => void;
@@ -0,0 +1,46 @@
1
+ import { visit as estreeVisit } from "estree-util-visit";
2
+ function recmaInjectImportMetaEnv({
3
+ importMetaEnv
4
+ }) {
5
+ return (tree) => {
6
+ estreeVisit(tree, (node) => {
7
+ if (node.type === "MemberExpression") {
8
+ const envVarName = getImportMetaEnvVariableName(node);
9
+ if (typeof envVarName === "string") {
10
+ for (const key in node) {
11
+ delete node[key];
12
+ }
13
+ const envVarLiteral = {
14
+ type: "Literal",
15
+ value: importMetaEnv[envVarName],
16
+ raw: JSON.stringify(importMetaEnv[envVarName])
17
+ };
18
+ Object.assign(node, envVarLiteral);
19
+ }
20
+ }
21
+ });
22
+ };
23
+ }
24
+ function getImportMetaEnvVariableName(node) {
25
+ try {
26
+ if (node.object.type !== "MemberExpression" || node.property.type !== "Identifier")
27
+ return new Error();
28
+ const nestedExpression = node.object;
29
+ if (nestedExpression.property.type !== "Identifier" || nestedExpression.property.name !== "env")
30
+ return new Error();
31
+ const envExpression = nestedExpression.object;
32
+ if (envExpression.type !== "MetaProperty" || envExpression.property.type !== "Identifier" || envExpression.property.name !== "meta")
33
+ return new Error();
34
+ if (envExpression.meta.name !== "import")
35
+ return new Error();
36
+ return node.property.name;
37
+ } catch (e) {
38
+ if (e instanceof Error) {
39
+ return e;
40
+ }
41
+ return new Error("Unknown parsing error");
42
+ }
43
+ }
44
+ export {
45
+ recmaInjectImportMetaEnv
46
+ };
@@ -0,0 +1,2 @@
1
+ import type { VFile } from 'vfile';
2
+ export declare function rehypeApplyFrontmatterExport(): (tree: any, vfile: VFile) => void;
@@ -0,0 +1,46 @@
1
+ import { InvalidAstroDataError } from "@astrojs/markdown-remark";
2
+ import { safelyGetAstroData } from "@astrojs/markdown-remark/dist/internal.js";
3
+ import { jsToTreeNode } from "./utils.js";
4
+ function rehypeApplyFrontmatterExport() {
5
+ return function(tree, vfile) {
6
+ const astroData = safelyGetAstroData(vfile.data);
7
+ if (astroData instanceof InvalidAstroDataError)
8
+ throw new Error(
9
+ // Copied from Astro core `errors-data`
10
+ // TODO: find way to import error data from core
11
+ '[MDX] A remark or rehype plugin attempted to inject invalid frontmatter. Ensure "astro.frontmatter" is set to a valid JSON object that is not `null` or `undefined`.'
12
+ );
13
+ const { frontmatter } = astroData;
14
+ const exportNodes = [
15
+ jsToTreeNode(`export const frontmatter = ${JSON.stringify(frontmatter)};`)
16
+ ];
17
+ if (frontmatter.layout) {
18
+ exportNodes.unshift(
19
+ jsToTreeNode(
20
+ /** @see 'vite-plugin-markdown' for layout props reference */
21
+ `import { jsx as layoutJsx } from 'astro/jsx-runtime';
22
+
23
+ export default async function ({ children }) {
24
+ const Layout = (await import(${JSON.stringify(frontmatter.layout)})).default;
25
+ const { layout, ...content } = frontmatter;
26
+ content.file = file;
27
+ content.url = url;
28
+ return layoutJsx(Layout, {
29
+ file,
30
+ url,
31
+ content,
32
+ frontmatter: content,
33
+ headings: getHeadings(),
34
+ 'server:root': true,
35
+ children,
36
+ });
37
+ };`
38
+ )
39
+ );
40
+ }
41
+ tree.children = exportNodes.concat(tree.children);
42
+ };
43
+ }
44
+ export {
45
+ rehypeApplyFrontmatterExport
46
+ };
@@ -1,2 +1,5 @@
1
1
  import type { MarkdownVFile } from '@astrojs/markdown-remark';
2
+ export declare const ASTRO_IMAGE_ELEMENT = "astro-image";
3
+ export declare const ASTRO_IMAGE_IMPORT = "__AstroImage__";
4
+ export declare const USES_ASTRO_IMAGE_FLAG = "__usesAstroImage";
2
5
  export declare function remarkImageToComponent(): (tree: any, file: MarkdownVFile) => void;
@@ -1,5 +1,8 @@
1
1
  import { visit } from "unist-util-visit";
2
2
  import { jsToTreeNode } from "./utils.js";
3
+ const ASTRO_IMAGE_ELEMENT = "astro-image";
4
+ const ASTRO_IMAGE_IMPORT = "__AstroImage__";
5
+ const USES_ASTRO_IMAGE_FLAG = "__usesAstroImage";
3
6
  function remarkImageToComponent() {
4
7
  return function(tree, file) {
5
8
  if (!file.data.imagePaths)
@@ -36,7 +39,7 @@ function remarkImageToComponent() {
36
39
  importedImages.set(node.url, importName);
37
40
  }
38
41
  const componentElement = {
39
- name: "__AstroImage__",
42
+ name: ASTRO_IMAGE_ELEMENT,
40
43
  type: "mdxJsxFlowElement",
41
44
  attributes: [
42
45
  {
@@ -75,9 +78,15 @@ function remarkImageToComponent() {
75
78
  }
76
79
  });
77
80
  tree.children.unshift(...importsStatements);
78
- tree.children.unshift(jsToTreeNode(`import { Image as __AstroImage__ } from "astro:assets";`));
81
+ tree.children.unshift(
82
+ jsToTreeNode(`import { Image as ${ASTRO_IMAGE_IMPORT} } from "astro:assets";`)
83
+ );
84
+ tree.children.push(jsToTreeNode(`export const ${USES_ASTRO_IMAGE_FLAG} = true`));
79
85
  };
80
86
  }
81
87
  export {
88
+ ASTRO_IMAGE_ELEMENT,
89
+ ASTRO_IMAGE_IMPORT,
90
+ USES_ASTRO_IMAGE_FLAG,
82
91
  remarkImageToComponent
83
92
  };
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.2",
4
+ "version": "1.1.0",
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.0.0",
47
- "@astrojs/prism": "3.0.0"
44
+ "@astrojs/markdown-remark": "3.2.0"
48
45
  },
49
46
  "peerDependencies": {
50
- "astro": "^3.0.10"
47
+ "astro": "^3.1.0"
51
48
  },
52
49
  "devDependencies": {
53
50
  "@types/chai": "^4.3.5",
@@ -68,8 +65,9 @@
68
65
  "remark-rehype": "^10.1.0",
69
66
  "remark-shiki-twoslash": "^3.1.3",
70
67
  "remark-toc": "^8.0.1",
68
+ "unified": "^10.1.2",
71
69
  "vite": "^4.4.9",
72
- "astro": "3.0.10",
70
+ "astro": "3.1.0",
73
71
  "astro-scripts": "0.0.14"
74
72
  },
75
73
  "engines": {
@@ -1,2 +0,0 @@
1
- /** */
2
- export default function remarkPrism(): (tree: any) => void;
@@ -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
- };
@@ -1,3 +0,0 @@
1
- import type { ShikiConfig } from 'astro';
2
- declare const remarkShiki: ({ langs, theme, wrap }: ShikiConfig) => Promise<() => (tree: any) => void>;
3
- export default remarkShiki;
@@ -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
- };