@astrojs/mdx 0.0.0-imgcache-20220929145446
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +209 -0
- package/LICENSE +61 -0
- package/README.md +527 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +131 -0
- package/dist/plugins.d.ts +11 -0
- package/dist/plugins.js +214 -0
- package/dist/rehype-collect-headings.d.ts +6 -0
- package/dist/rehype-collect-headings.js +47 -0
- package/dist/remark-prism.d.ts +2 -0
- package/dist/remark-prism.js +17 -0
- package/dist/remark-shiki.d.ts +3 -0
- package/dist/remark-shiki.js +69 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +74 -0
- package/package.json +71 -0
- package/src/index.ts +167 -0
- package/src/plugins.ts +273 -0
- package/src/rehype-collect-headings.ts +50 -0
- package/src/remark-prism.ts +18 -0
- package/src/remark-shiki.ts +95 -0
- package/src/utils.ts +97 -0
- package/test/fixtures/mdx-component/src/components/Test.mdx +3 -0
- package/test/fixtures/mdx-component/src/pages/glob.astro +11 -0
- package/test/fixtures/mdx-component/src/pages/index.astro +5 -0
- package/test/fixtures/mdx-escape/src/components/Em.astro +7 -0
- package/test/fixtures/mdx-escape/src/components/P.astro +1 -0
- package/test/fixtures/mdx-escape/src/components/Title.astro +1 -0
- package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +5 -0
- package/test/fixtures/mdx-escape/src/pages/index.mdx +13 -0
- package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +38 -0
- package/test/fixtures/mdx-frontmatter/src/pages/glob.json.js +9 -0
- package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +10 -0
- package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +7 -0
- package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +12 -0
- package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +17 -0
- package/test/fixtures/mdx-frontmatter-injection/package.json +12 -0
- package/test/fixtures/mdx-frontmatter-injection/src/layouts/Base.astro +17 -0
- package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +20 -0
- package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +6 -0
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +7 -0
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +23 -0
- package/test/fixtures/mdx-frontmatter-injection/src/pages/with-overrides.mdx +7 -0
- package/test/fixtures/mdx-get-headings/src/pages/pages.json.js +11 -0
- package/test/fixtures/mdx-get-headings/src/pages/test-with-jsx-expressions.mdx +8 -0
- package/test/fixtures/mdx-get-headings/src/pages/test.mdx +9 -0
- package/test/fixtures/mdx-get-static-paths/src/content/1.mdx +5 -0
- package/test/fixtures/mdx-get-static-paths/src/pages/[slug].astro +34 -0
- package/test/fixtures/mdx-namespace/astro.config.mjs +6 -0
- package/test/fixtures/mdx-namespace/node_modules/.bin/astro +17 -0
- package/test/fixtures/mdx-namespace/package.json +10 -0
- package/test/fixtures/mdx-namespace/src/components/Component.jsx +6 -0
- package/test/fixtures/mdx-namespace/src/pages/object.mdx +3 -0
- package/test/fixtures/mdx-namespace/src/pages/star.mdx +3 -0
- package/test/fixtures/mdx-page/astro.config.ts +5 -0
- package/test/fixtures/mdx-page/node_modules/.bin/astro +17 -0
- package/test/fixtures/mdx-page/package.json +9 -0
- package/test/fixtures/mdx-page/src/pages/index.mdx +3 -0
- package/test/fixtures/mdx-page/src/styles.css +3 -0
- package/test/fixtures/mdx-plugins/src/pages/with-plugins.mdx +19 -0
- package/test/fixtures/mdx-plus-react/astro.config.mjs +6 -0
- package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +17 -0
- package/test/fixtures/mdx-plus-react/package.json +10 -0
- package/test/fixtures/mdx-plus-react/src/components/Component.jsx +5 -0
- package/test/fixtures/mdx-plus-react/src/pages/index.astro +11 -0
- package/test/fixtures/mdx-syntax-hightlighting/src/pages/index.mdx +9 -0
- package/test/fixtures/mdx-url-export/src/pages/pages.json.js +9 -0
- package/test/fixtures/mdx-url-export/src/pages/test-1.mdx +1 -0
- package/test/fixtures/mdx-url-export/src/pages/test-2.mdx +1 -0
- package/test/fixtures/mdx-url-export/src/pages/with-url-override.mdx +3 -0
- package/test/fixtures/mdx-vite-env-vars/astro.config.mjs +9 -0
- package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +17 -0
- package/test/fixtures/mdx-vite-env-vars/package.json +7 -0
- package/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js +7 -0
- package/test/fixtures/mdx-vite-env-vars/src/pages/vite-env-vars.mdx +38 -0
- package/test/mdx-component.test.js +112 -0
- package/test/mdx-escape.test.js +32 -0
- package/test/mdx-frontmatter-injection.test.js +56 -0
- package/test/mdx-frontmatter.test.js +77 -0
- package/test/mdx-get-headings.test.js +60 -0
- package/test/mdx-get-static-paths.test.js +32 -0
- package/test/mdx-namespace.test.js +83 -0
- package/test/mdx-page.test.js +64 -0
- package/test/mdx-plugins.test.js +211 -0
- package/test/mdx-plus-react.test.js +25 -0
- package/test/mdx-syntax-highlighting.test.js +91 -0
- package/test/mdx-url-export.test.js +28 -0
- package/test/mdx-vite-env-vars.test.js +54 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p><slot /></p>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<h1><slot/></h1>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import P from '../components/P.astro';
|
|
2
|
+
import Em from '../components/Em.astro';
|
|
3
|
+
import Title from '../components/Title.astro';
|
|
4
|
+
|
|
5
|
+
export const components = { p: P, em: Em, h1: Title };
|
|
6
|
+
|
|
7
|
+
# Hello _there_
|
|
8
|
+
|
|
9
|
+
# _there_
|
|
10
|
+
|
|
11
|
+
Hello _there_
|
|
12
|
+
|
|
13
|
+
_there_
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
const {
|
|
3
|
+
content = { title: "content didn't work" },
|
|
4
|
+
file = "file didn't work",
|
|
5
|
+
url = "url didn't work",
|
|
6
|
+
frontmatter = {
|
|
7
|
+
title: "frontmatter didn't work",
|
|
8
|
+
file: "file didn't work",
|
|
9
|
+
url: "url didn't work",
|
|
10
|
+
},
|
|
11
|
+
headings = [],
|
|
12
|
+
} = Astro.props;
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<!DOCTYPE html>
|
|
16
|
+
<html lang="en">
|
|
17
|
+
|
|
18
|
+
<head>
|
|
19
|
+
<meta charset="UTF-8">
|
|
20
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
21
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
22
|
+
</head>
|
|
23
|
+
|
|
24
|
+
<body>
|
|
25
|
+
<p data-content-title>{content.title}</p>
|
|
26
|
+
<p data-frontmatter-title>{frontmatter.title}</p>
|
|
27
|
+
<p data-frontmatter-file>{frontmatter.file}</p>
|
|
28
|
+
<p data-frontmatter-url>{frontmatter.url}</p>
|
|
29
|
+
<p data-file>{frontmatter.file}</p>
|
|
30
|
+
<p data-url>{frontmatter.url}</p>
|
|
31
|
+
<p data-layout-rendered>Layout rendered!</p>
|
|
32
|
+
<ul data-headings>
|
|
33
|
+
{headings.map(heading => <li>{heading.slug}</li>)}
|
|
34
|
+
</ul>
|
|
35
|
+
<slot />
|
|
36
|
+
</body>
|
|
37
|
+
|
|
38
|
+
</html>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Using YAML frontmatter'
|
|
3
|
+
layout: '../layouts/Base.astro'
|
|
4
|
+
illThrowIfIDontExist: "Oh no, that's scary!"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
{frontmatter.illThrowIfIDontExist}
|
|
8
|
+
|
|
9
|
+
> Note: newline intentionally missing from the end of this file.
|
|
10
|
+
> Useful since that can be the source of bugs in our compile step.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from 'astro/config';
|
|
2
|
+
import mdx from '@astrojs/mdx';
|
|
3
|
+
import { rehypeReadingTime, remarkTitle } from './src/markdown-plugins.mjs';
|
|
4
|
+
|
|
5
|
+
// https://astro.build/config
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
site: 'https://astro.build/',
|
|
8
|
+
integrations: [mdx({
|
|
9
|
+
remarkPlugins: [remarkTitle],
|
|
10
|
+
rehypePlugins: [rehypeReadingTime],
|
|
11
|
+
})],
|
|
12
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@test/mdx-frontmatter-injection",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"astro": "workspace:*",
|
|
7
|
+
"@astrojs/mdx": "workspace:*",
|
|
8
|
+
"mdast-util-to-string": "^3.1.0",
|
|
9
|
+
"reading-time": "^1.5.0",
|
|
10
|
+
"unist-util-visit": "^4.1.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
const defaults = { title: 'Frontmatter not passed to layout!' }
|
|
3
|
+
const { frontmatter = defaults, content = defaults } = Astro.props;
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!DOCTYPE html>
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="UTF-8">
|
|
10
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
12
|
+
<title>{frontmatter.title}</title>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<slot />
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import getReadingTime from 'reading-time';
|
|
2
|
+
import { toString } from 'mdast-util-to-string';
|
|
3
|
+
import { visit } from 'unist-util-visit';
|
|
4
|
+
|
|
5
|
+
export function rehypeReadingTime() {
|
|
6
|
+
return function (tree, { data }) {
|
|
7
|
+
const readingTime = getReadingTime(toString(tree));
|
|
8
|
+
data.astro.frontmatter.injectedReadingTime = readingTime;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function remarkTitle() {
|
|
13
|
+
return function (tree, { data }) {
|
|
14
|
+
visit(tree, ['heading'], (node) => {
|
|
15
|
+
if (node.depth === 1) {
|
|
16
|
+
data.astro.frontmatter.title = toString(node.children);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: '../layouts/Base.astro'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Page 2
|
|
6
|
+
|
|
7
|
+
## Table of contents
|
|
8
|
+
|
|
9
|
+
## Section 1
|
|
10
|
+
|
|
11
|
+
Some text!
|
|
12
|
+
|
|
13
|
+
### Subsection 1
|
|
14
|
+
|
|
15
|
+
Some subsection test!
|
|
16
|
+
|
|
17
|
+
### Subsection 2
|
|
18
|
+
|
|
19
|
+
Oh cool, more text!
|
|
20
|
+
|
|
21
|
+
## Section 2
|
|
22
|
+
|
|
23
|
+
More content
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export async function get() {
|
|
2
|
+
const mdxPages = await import.meta.glob('./*.mdx', { eager: true });
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
body: JSON.stringify({
|
|
6
|
+
headingsByPage: Object.fromEntries(
|
|
7
|
+
Object.entries(mdxPages ?? {}).map(([k, v]) => [k, v?.getHeadings()])
|
|
8
|
+
),
|
|
9
|
+
}),
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
export const getStaticPaths = async () => {
|
|
3
|
+
const content = await Astro.glob('../content/*.mdx');
|
|
4
|
+
|
|
5
|
+
return content
|
|
6
|
+
.filter((page) => !page.frontmatter.draft) // skip drafts
|
|
7
|
+
.map(({ default: MdxContent, frontmatter, url, file }) => {
|
|
8
|
+
return {
|
|
9
|
+
params: { slug: frontmatter.slug || "index" },
|
|
10
|
+
props: {
|
|
11
|
+
MdxContent,
|
|
12
|
+
file,
|
|
13
|
+
frontmatter,
|
|
14
|
+
url
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { MdxContent, frontmatter, url, file } = Astro.props;
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
<html>
|
|
24
|
+
<head>
|
|
25
|
+
<title>Page</title>
|
|
26
|
+
</head>
|
|
27
|
+
<body>
|
|
28
|
+
<MdxContent />
|
|
29
|
+
|
|
30
|
+
<div id="one">{frontmatter.one}</div>
|
|
31
|
+
<div id="url">{url}</div>
|
|
32
|
+
<div id="file">{file}</div>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# TOC test
|
|
2
|
+
|
|
3
|
+
## Table of contents
|
|
4
|
+
|
|
5
|
+
## Section 1
|
|
6
|
+
|
|
7
|
+
Some text!
|
|
8
|
+
|
|
9
|
+
### Subsection 1
|
|
10
|
+
|
|
11
|
+
Some subsection test!
|
|
12
|
+
|
|
13
|
+
### Subsection 2
|
|
14
|
+
|
|
15
|
+
Oh cool, more text!
|
|
16
|
+
|
|
17
|
+
## Section 2
|
|
18
|
+
|
|
19
|
+
And section 2, with a hyperlink to check GFM is preserved: https://handle-me-gfm.com
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# I'm a page with a url of "/test-1!"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# I'm a page with a url of "/test-2!"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Let's talk about my import.meta.env.SITE
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
export const modeWorks =
|
|
6
|
+
import.meta.env.MODE === 'production' ? 'MODE works' : 'MODE does not work!';
|
|
7
|
+
|
|
8
|
+
# About my import.meta.env.SITE
|
|
9
|
+
|
|
10
|
+
My `import.meta.env.SITE` is so cool, I can put env variables in code!
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
const site = import.meta.env.SITE;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## But I can use import.meta.env properly too
|
|
17
|
+
|
|
18
|
+
<div data-env-site>
|
|
19
|
+
|
|
20
|
+
I can compute my site, for example: {new URL('/blog/cool-post', import.meta.env.SITE)}
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<div data-env-variable-exports>
|
|
25
|
+
|
|
26
|
+
I can also use `import.meta.env` in variable exports: {modeWorks}
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
I can also use vars as HTML attributes:
|
|
31
|
+
|
|
32
|
+
<div
|
|
33
|
+
data-env-dump
|
|
34
|
+
data-env-prod={import.meta.env.PROD}
|
|
35
|
+
data-env-dev={import.meta.env.DEV}
|
|
36
|
+
data-env-base-url={import.meta.env.BASE_URL}
|
|
37
|
+
data-env-mode={import.meta.env.MODE}
|
|
38
|
+
></div>
|