@astrojs/mdx 0.19.0 → 0.19.2

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.
Files changed (140) hide show
  1. package/dist/remark-shiki.js +17 -0
  2. package/package.json +10 -6
  3. package/.turbo/turbo-build.log +0 -5
  4. package/CHANGELOG.md +0 -716
  5. package/src/index.ts +0 -226
  6. package/src/plugins.ts +0 -185
  7. package/src/rehype-collect-headings.ts +0 -11
  8. package/src/rehype-meta-string.ts +0 -17
  9. package/src/remark-images-to-component.ts +0 -98
  10. package/src/remark-prism.ts +0 -18
  11. package/src/remark-shiki.ts +0 -95
  12. package/src/utils.ts +0 -108
  13. package/test/css-head-mdx.test.js +0 -98
  14. package/test/fixtures/css-head-mdx/node_modules/.bin/astro +0 -17
  15. package/test/fixtures/css-head-mdx/package.json +0 -10
  16. package/test/fixtures/css-head-mdx/src/components/BaseHead.astro +0 -11
  17. package/test/fixtures/css-head-mdx/src/components/BasicBlock.astro +0 -14
  18. package/test/fixtures/css-head-mdx/src/components/GenericComponent.astro +0 -1
  19. package/test/fixtures/css-head-mdx/src/components/HelloWorld.astro +0 -11
  20. package/test/fixtures/css-head-mdx/src/components/MDXWrapper.astro +0 -9
  21. package/test/fixtures/css-head-mdx/src/components/P.astro +0 -3
  22. package/test/fixtures/css-head-mdx/src/components/SmallCaps.astro +0 -3
  23. package/test/fixtures/css-head-mdx/src/components/UsingMdx.astro +0 -8
  24. package/test/fixtures/css-head-mdx/src/components/WithHoistedScripts.astro +0 -6
  25. package/test/fixtures/css-head-mdx/src/content/blog/_styles.css +0 -3
  26. package/test/fixtures/css-head-mdx/src/content/blog/using-mdx.mdx +0 -6
  27. package/test/fixtures/css-head-mdx/src/content/posts/test.mdx +0 -5
  28. package/test/fixtures/css-head-mdx/src/content/posts/using-component.mdx +0 -13
  29. package/test/fixtures/css-head-mdx/src/layouts/ContentLayout.astro +0 -18
  30. package/test/fixtures/css-head-mdx/src/layouts/DocumentLayout.astro +0 -15
  31. package/test/fixtures/css-head-mdx/src/layouts/One.astro +0 -15
  32. package/test/fixtures/css-head-mdx/src/layouts/Three.astro +0 -6
  33. package/test/fixtures/css-head-mdx/src/layouts/Two.astro +0 -6
  34. package/test/fixtures/css-head-mdx/src/pages/DirectContentUsage.astro +0 -17
  35. package/test/fixtures/css-head-mdx/src/pages/componentwithtext.mdx +0 -12
  36. package/test/fixtures/css-head-mdx/src/pages/indexOne.astro +0 -10
  37. package/test/fixtures/css-head-mdx/src/pages/indexThree.astro +0 -10
  38. package/test/fixtures/css-head-mdx/src/pages/indexTwo.astro +0 -10
  39. package/test/fixtures/css-head-mdx/src/pages/noLayoutWithComponent.mdx +0 -22
  40. package/test/fixtures/css-head-mdx/src/pages/posts/[post].astro +0 -18
  41. package/test/fixtures/css-head-mdx/src/pages/remote.astro +0 -17
  42. package/test/fixtures/css-head-mdx/src/pages/testOne.mdx +0 -15
  43. package/test/fixtures/css-head-mdx/src/pages/testThree.mdx +0 -15
  44. package/test/fixtures/css-head-mdx/src/pages/testTwo.mdx +0 -15
  45. package/test/fixtures/css-head-mdx/src/styles/global.css +0 -3
  46. package/test/fixtures/css-head-mdx/src/test.mdx +0 -14
  47. package/test/fixtures/mdx-astro-markdown-remarkRehype/src/pages/index.mdx +0 -5
  48. package/test/fixtures/mdx-component/src/components/Test.mdx +0 -3
  49. package/test/fixtures/mdx-component/src/components/WithFragment.mdx +0 -3
  50. package/test/fixtures/mdx-component/src/pages/glob.astro +0 -20
  51. package/test/fixtures/mdx-component/src/pages/index.astro +0 -5
  52. package/test/fixtures/mdx-component/src/pages/w-fragment.astro +0 -5
  53. package/test/fixtures/mdx-escape/src/components/Em.astro +0 -7
  54. package/test/fixtures/mdx-escape/src/components/P.astro +0 -1
  55. package/test/fixtures/mdx-escape/src/components/Title.astro +0 -1
  56. package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +0 -5
  57. package/test/fixtures/mdx-escape/src/pages/index.mdx +0 -13
  58. package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +0 -38
  59. package/test/fixtures/mdx-frontmatter/src/pages/glob.json.js +0 -9
  60. package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +0 -10
  61. package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +0 -7
  62. package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +0 -12
  63. package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +0 -17
  64. package/test/fixtures/mdx-frontmatter-injection/package.json +0 -12
  65. package/test/fixtures/mdx-frontmatter-injection/src/layouts/Base.astro +0 -17
  66. package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +0 -27
  67. package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +0 -6
  68. package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +0 -8
  69. package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +0 -24
  70. package/test/fixtures/mdx-get-headings/src/pages/pages.json.js +0 -11
  71. package/test/fixtures/mdx-get-headings/src/pages/test-with-frontmatter.mdx +0 -45
  72. package/test/fixtures/mdx-get-headings/src/pages/test-with-jsx-expressions.mdx +0 -8
  73. package/test/fixtures/mdx-get-headings/src/pages/test.mdx +0 -9
  74. package/test/fixtures/mdx-get-static-paths/src/content/1.mdx +0 -5
  75. package/test/fixtures/mdx-get-static-paths/src/pages/[slug].astro +0 -34
  76. package/test/fixtures/mdx-images/astro.config.ts +0 -8
  77. package/test/fixtures/mdx-images/node_modules/.bin/astro +0 -17
  78. package/test/fixtures/mdx-images/package.json +0 -9
  79. package/test/fixtures/mdx-images/src/assets/houston in space.webp +0 -0
  80. package/test/fixtures/mdx-images/src/assets/houston.webp +0 -0
  81. package/test/fixtures/mdx-images/src/pages/index.mdx +0 -11
  82. package/test/fixtures/mdx-infinite-loop/astro.config.ts +0 -6
  83. package/test/fixtures/mdx-infinite-loop/node_modules/.bin/astro +0 -17
  84. package/test/fixtures/mdx-infinite-loop/package.json +0 -10
  85. package/test/fixtures/mdx-infinite-loop/src/components/Test.js +0 -3
  86. package/test/fixtures/mdx-infinite-loop/src/pages/doc.mdx +0 -6
  87. package/test/fixtures/mdx-infinite-loop/src/pages/index.astro +0 -5
  88. package/test/fixtures/mdx-math/src/pages/mathjax.mdx +0 -5
  89. package/test/fixtures/mdx-namespace/astro.config.mjs +0 -6
  90. package/test/fixtures/mdx-namespace/node_modules/.bin/astro +0 -17
  91. package/test/fixtures/mdx-namespace/package.json +0 -10
  92. package/test/fixtures/mdx-namespace/src/components/Component.jsx +0 -6
  93. package/test/fixtures/mdx-namespace/src/pages/object.mdx +0 -3
  94. package/test/fixtures/mdx-namespace/src/pages/star.mdx +0 -3
  95. package/test/fixtures/mdx-page/astro.config.ts +0 -5
  96. package/test/fixtures/mdx-page/node_modules/.bin/astro +0 -17
  97. package/test/fixtures/mdx-page/package.json +0 -9
  98. package/test/fixtures/mdx-page/src/pages/index.mdx +0 -3
  99. package/test/fixtures/mdx-page/src/styles.css +0 -3
  100. package/test/fixtures/mdx-plugins/src/pages/with-plugins.mdx +0 -25
  101. package/test/fixtures/mdx-plus-react/astro.config.mjs +0 -6
  102. package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +0 -17
  103. package/test/fixtures/mdx-plus-react/package.json +0 -10
  104. package/test/fixtures/mdx-plus-react/src/components/Component.jsx +0 -5
  105. package/test/fixtures/mdx-plus-react/src/pages/index.astro +0 -11
  106. package/test/fixtures/mdx-script-style-raw/src/pages/index.mdx +0 -13
  107. package/test/fixtures/mdx-slots/src/components/Slotted.astro +0 -4
  108. package/test/fixtures/mdx-slots/src/components/Test.mdx +0 -15
  109. package/test/fixtures/mdx-slots/src/pages/glob.astro +0 -11
  110. package/test/fixtures/mdx-slots/src/pages/index.astro +0 -5
  111. package/test/fixtures/mdx-syntax-hightlighting/src/pages/index.mdx +0 -9
  112. package/test/fixtures/mdx-url-export/src/pages/pages.json.js +0 -9
  113. package/test/fixtures/mdx-url-export/src/pages/test-1.mdx +0 -1
  114. package/test/fixtures/mdx-url-export/src/pages/test-2.mdx +0 -1
  115. package/test/fixtures/mdx-url-export/src/pages/with-url-override.mdx +0 -3
  116. package/test/fixtures/mdx-vite-env-vars/astro.config.mjs +0 -9
  117. package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +0 -17
  118. package/test/fixtures/mdx-vite-env-vars/package.json +0 -7
  119. package/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js +0 -7
  120. package/test/fixtures/mdx-vite-env-vars/src/pages/vite-env-vars.mdx +0 -38
  121. package/test/mdx-astro-markdown-remarkRehype.test.js +0 -85
  122. package/test/mdx-component.test.js +0 -191
  123. package/test/mdx-escape.test.js +0 -32
  124. package/test/mdx-frontmatter-injection.test.js +0 -53
  125. package/test/mdx-frontmatter.test.js +0 -77
  126. package/test/mdx-get-headings.test.js +0 -194
  127. package/test/mdx-get-static-paths.test.js +0 -32
  128. package/test/mdx-images.test.js +0 -40
  129. package/test/mdx-infinite-loop.test.js +0 -30
  130. package/test/mdx-math.test.js +0 -64
  131. package/test/mdx-namespace.test.js +0 -83
  132. package/test/mdx-page.test.js +0 -64
  133. package/test/mdx-plugins.test.js +0 -285
  134. package/test/mdx-plus-react.test.js +0 -25
  135. package/test/mdx-script-style-raw.test.js +0 -70
  136. package/test/mdx-slots.js +0 -124
  137. package/test/mdx-syntax-highlighting.test.js +0 -145
  138. package/test/mdx-url-export.test.js +0 -28
  139. package/test/mdx-vite-env-vars.test.js +0 -54
  140. package/tsconfig.json +0 -10
@@ -1,17 +0,0 @@
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/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
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
@@ -1,10 +0,0 @@
1
- {
2
- "name": "@test/mdx-plus-react",
3
- "dependencies": {
4
- "@astrojs/mdx": "workspace:*",
5
- "@astrojs/react": "workspace:*",
6
- "astro": "workspace:*",
7
- "react": "^18.2.0",
8
- "react-dom": "^18.2.0"
9
- }
10
- }
@@ -1,5 +0,0 @@
1
- const Component = () => {
2
- return <p>Hello world</p>;
3
- };
4
-
5
- export default Component;
@@ -1,11 +0,0 @@
1
- ---
2
- import Component from "../components/Component.jsx";
3
- ---
4
- <html>
5
- <head>
6
- <title>Testing</title>
7
- </head>
8
- <body>
9
- <Component />
10
- </body>
11
- </html>
@@ -1,13 +0,0 @@
1
- # Script style raw
2
-
3
- <script id="test-script">
4
- {`console.log('raw script')`}
5
- </script>
6
-
7
- <style id="test-style">
8
- {`
9
- h1[id="script-style-raw"] {
10
- color: red;
11
- }
12
- `}
13
- </style>
@@ -1,4 +0,0 @@
1
- <div class="slotted">
2
- <div data-default-slot><slot /></div>
3
- <div data-named-slot><slot name="named" /></div>
4
- </div>
@@ -1,15 +0,0 @@
1
- import Slotted from './Slotted.astro'
2
-
3
- # Hello slotted component!
4
-
5
- <Slotted>
6
-
7
- Default content.
8
-
9
- <Fragment slot="named">
10
-
11
- Content for named slot.
12
-
13
- </Fragment>
14
-
15
- </Slotted>
@@ -1,11 +0,0 @@
1
- ---
2
- const components = await Astro.glob('../components/*.mdx');
3
- ---
4
-
5
- <div data-default-export>
6
- {components.map(Component => <Component.default />)}
7
- </div>
8
-
9
- <div data-content-export>
10
- {components.map(({ Content }) => <Content />)}
11
- </div>
@@ -1,5 +0,0 @@
1
- ---
2
- import Test from '../components/Test.mdx';
3
- ---
4
-
5
- <Test />
@@ -1,9 +0,0 @@
1
- # Syntax highlighting
2
-
3
- ```astro {2}
4
- ---
5
- const handlesAstroSyntax = true
6
- ---
7
-
8
- <h1>{handlesAstroSyntax}</h1>
9
- ```
@@ -1,9 +0,0 @@
1
- export async function get() {
2
- const mdxPages = await import.meta.glob('./*.mdx', { eager: true });
3
-
4
- return {
5
- body: JSON.stringify({
6
- urls: Object.values(mdxPages ?? {}).map(v => v?.url),
7
- })
8
- }
9
- }
@@ -1 +0,0 @@
1
- # I'm a page with a url of "/test-1!"
@@ -1 +0,0 @@
1
- # I'm a page with a url of "/test-2!"
@@ -1,3 +0,0 @@
1
- export const url = '/AH!'
2
-
3
- # I'm a test with a url override!
@@ -1,9 +0,0 @@
1
- import mdx from '@astrojs/mdx';
2
-
3
- export default {
4
- site: 'https://mdx-is-neat.com/',
5
- markdown: {
6
- syntaxHighlight: false,
7
- },
8
- integrations: [mdx()],
9
- }
@@ -1,17 +0,0 @@
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/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
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
@@ -1,7 +0,0 @@
1
- {
2
- "name": "@test/mdx-env-variables",
3
- "dependencies": {
4
- "astro": "workspace:*",
5
- "@astrojs/mdx": "workspace:*"
6
- }
7
- }
@@ -1,7 +0,0 @@
1
- import { frontmatter } from './vite-env-vars.mdx';
2
-
3
- export function get() {
4
- return {
5
- body: JSON.stringify(frontmatter),
6
- }
7
- }
@@ -1,38 +0,0 @@
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>
@@ -1,85 +0,0 @@
1
- import mdx from '@astrojs/mdx';
2
-
3
- import { expect } from 'chai';
4
- import { parseHTML } from 'linkedom';
5
- import { loadFixture } from '../../../astro/test/test-utils.js';
6
-
7
- describe('MDX with Astro Markdown remark-rehype config', () => {
8
- it('Renders footnotes with values from the default configuration', async () => {
9
- const fixture = await loadFixture({
10
- root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
11
- integrations: [mdx()],
12
- markdown: {
13
- remarkRehype: {
14
- footnoteLabel: 'Catatan kaki',
15
- footnoteBackLabel: 'Kembali ke konten',
16
- },
17
- },
18
- });
19
-
20
- await fixture.build();
21
- const html = await fixture.readFile('/index.html');
22
- const { document } = parseHTML(html);
23
-
24
- expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki');
25
- expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal(
26
- 'Kembali ke konten'
27
- );
28
- });
29
-
30
- it('Renders footnotes with values from custom configuration extending the default', async () => {
31
- const fixture = await loadFixture({
32
- root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
33
- integrations: [
34
- mdx({
35
- remarkRehype: {
36
- footnoteLabel: 'Catatan kaki',
37
- footnoteBackLabel: 'Kembali ke konten',
38
- },
39
- }),
40
- ],
41
- markdown: {
42
- remarkRehype: {
43
- footnoteBackLabel: 'Replace me',
44
- },
45
- },
46
- });
47
-
48
- await fixture.build();
49
- const html = await fixture.readFile('/index.html');
50
- const { document } = parseHTML(html);
51
-
52
- expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki');
53
- expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal(
54
- 'Kembali ke konten'
55
- );
56
- });
57
-
58
- it('Renders footnotes with values from custom configuration without extending the default', async () => {
59
- const fixture = await loadFixture({
60
- root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
61
- integrations: [
62
- mdx({
63
- extendPlugins: 'astroDefaults',
64
- remarkRehype: {
65
- footnoteLabel: 'Catatan kaki',
66
- },
67
- }),
68
- ],
69
- markdown: {
70
- remarkRehype: {
71
- footnoteBackLabel: 'Kembali ke konten',
72
- },
73
- },
74
- });
75
-
76
- await fixture.build();
77
- const html = await fixture.readFile('/index.html');
78
- const { document } = parseHTML(html);
79
-
80
- expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki');
81
- expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal(
82
- 'Back to content'
83
- );
84
- });
85
- });
@@ -1,191 +0,0 @@
1
- import mdx from '@astrojs/mdx';
2
-
3
- import { expect } from 'chai';
4
- import { parseHTML } from 'linkedom';
5
- import { loadFixture } from '../../../astro/test/test-utils.js';
6
-
7
- describe('MDX Component', () => {
8
- let fixture;
9
-
10
- before(async () => {
11
- fixture = await loadFixture({
12
- root: new URL('./fixtures/mdx-component/', import.meta.url),
13
- integrations: [mdx()],
14
- });
15
- });
16
-
17
- describe('build', () => {
18
- before(async () => {
19
- await fixture.build();
20
- });
21
-
22
- it('supports top-level imports', async () => {
23
- const html = await fixture.readFile('/index.html');
24
- const { document } = parseHTML(html);
25
-
26
- const h1 = document.querySelector('h1');
27
- const foo = document.querySelector('#foo');
28
-
29
- expect(h1.textContent).to.equal('Hello component!');
30
- expect(foo.textContent).to.equal('bar');
31
- });
32
-
33
- it('supports glob imports - <Component.default />', async () => {
34
- const html = await fixture.readFile('/glob/index.html');
35
- const { document } = parseHTML(html);
36
-
37
- const h1 = document.querySelector('[data-default-export] h1');
38
- const foo = document.querySelector('[data-default-export] #foo');
39
-
40
- expect(h1.textContent).to.equal('Hello component!');
41
- expect(foo.textContent).to.equal('bar');
42
- });
43
-
44
- it('supports glob imports - <Content />', async () => {
45
- const html = await fixture.readFile('/glob/index.html');
46
- const { document } = parseHTML(html);
47
-
48
- const h1 = document.querySelector('[data-content-export] h1');
49
- const foo = document.querySelector('[data-content-export] #foo');
50
-
51
- expect(h1.textContent).to.equal('Hello component!');
52
- expect(foo.textContent).to.equal('bar');
53
- });
54
-
55
- describe('with <Fragment>', () => {
56
- it('supports top-level imports', async () => {
57
- const html = await fixture.readFile('/w-fragment/index.html');
58
- const { document } = parseHTML(html);
59
-
60
- const h1 = document.querySelector('h1');
61
- const p = document.querySelector('p');
62
-
63
- expect(h1.textContent).to.equal('MDX containing <Fragment />');
64
- expect(p.textContent).to.equal('bar');
65
- });
66
-
67
- it('supports glob imports - <Component.default />', async () => {
68
- const html = await fixture.readFile('/glob/index.html');
69
- const { document } = parseHTML(html);
70
-
71
- const h = document.querySelector('[data-default-export] [data-file="WithFragment.mdx"] h1');
72
- const p = document.querySelector('[data-default-export] [data-file="WithFragment.mdx"] p');
73
-
74
- expect(h.textContent).to.equal('MDX containing <Fragment />');
75
- expect(p.textContent).to.equal('bar');
76
- });
77
-
78
- it('supports glob imports - <Content />', async () => {
79
- const html = await fixture.readFile('/glob/index.html');
80
- const { document } = parseHTML(html);
81
-
82
- const h = document.querySelector('[data-content-export] [data-file="WithFragment.mdx"] h1');
83
- const p = document.querySelector('[data-content-export] [data-file="WithFragment.mdx"] p');
84
-
85
- expect(h.textContent).to.equal('MDX containing <Fragment />');
86
- expect(p.textContent).to.equal('bar');
87
- });
88
- });
89
- });
90
-
91
- describe('dev', () => {
92
- let devServer;
93
-
94
- before(async () => {
95
- devServer = await fixture.startDevServer();
96
- });
97
-
98
- after(async () => {
99
- await devServer.stop();
100
- });
101
-
102
- it('supports top-level imports', async () => {
103
- const res = await fixture.fetch('/');
104
-
105
- expect(res.status).to.equal(200);
106
-
107
- const html = await res.text();
108
- const { document } = parseHTML(html);
109
-
110
- const h1 = document.querySelector('h1');
111
- const foo = document.querySelector('#foo');
112
-
113
- expect(h1.textContent).to.equal('Hello component!');
114
- expect(foo.textContent).to.equal('bar');
115
- });
116
-
117
- it('supports glob imports - <Component.default />', async () => {
118
- const res = await fixture.fetch('/glob');
119
-
120
- expect(res.status).to.equal(200);
121
-
122
- const html = await res.text();
123
- const { document } = parseHTML(html);
124
-
125
- const h1 = document.querySelector('[data-default-export] h1');
126
- const foo = document.querySelector('[data-default-export] #foo');
127
-
128
- expect(h1.textContent).to.equal('Hello component!');
129
- expect(foo.textContent).to.equal('bar');
130
- });
131
-
132
- it('supports glob imports - <Content />', async () => {
133
- const res = await fixture.fetch('/glob');
134
-
135
- expect(res.status).to.equal(200);
136
-
137
- const html = await res.text();
138
- const { document } = parseHTML(html);
139
-
140
- const h1 = document.querySelector('[data-content-export] h1');
141
- const foo = document.querySelector('[data-content-export] #foo');
142
-
143
- expect(h1.textContent).to.equal('Hello component!');
144
- expect(foo.textContent).to.equal('bar');
145
- });
146
-
147
- describe('with <Fragment>', () => {
148
- it('supports top-level imports', async () => {
149
- const res = await fixture.fetch('/w-fragment');
150
- expect(res.status).to.equal(200);
151
-
152
- const html = await res.text();
153
- const { document } = parseHTML(html);
154
-
155
- const h1 = document.querySelector('h1');
156
- const p = document.querySelector('p');
157
-
158
- expect(h1.textContent).to.equal('MDX containing <Fragment />');
159
- expect(p.textContent).to.equal('bar');
160
- });
161
-
162
- it('supports glob imports - <Component.default />', async () => {
163
- const res = await fixture.fetch('/glob');
164
- expect(res.status).to.equal(200);
165
-
166
- const html = await res.text();
167
- const { document } = parseHTML(html);
168
-
169
- const h = document.querySelector('[data-default-export] [data-file="WithFragment.mdx"] h1');
170
- const p = document.querySelector('[data-default-export] [data-file="WithFragment.mdx"] p');
171
-
172
- expect(h.textContent).to.equal('MDX containing <Fragment />');
173
- expect(p.textContent).to.equal('bar');
174
- });
175
-
176
- it('supports glob imports - <Content />', async () => {
177
- const res = await fixture.fetch('/glob');
178
- expect(res.status).to.equal(200);
179
-
180
- const html = await res.text();
181
- const { document } = parseHTML(html);
182
-
183
- const h = document.querySelector('[data-content-export] [data-file="WithFragment.mdx"] h1');
184
- const p = document.querySelector('[data-content-export] [data-file="WithFragment.mdx"] p');
185
-
186
- expect(h.textContent).to.equal('MDX containing <Fragment />');
187
- expect(p.textContent).to.equal('bar');
188
- });
189
- });
190
- });
191
- });
@@ -1,32 +0,0 @@
1
- import mdx from '@astrojs/mdx';
2
-
3
- import { expect } from 'chai';
4
- import { parseHTML } from 'linkedom';
5
- import { loadFixture } from '../../../astro/test/test-utils.js';
6
-
7
- const FIXTURE_ROOT = new URL('./fixtures/mdx-escape/', import.meta.url);
8
-
9
- describe('MDX frontmatter', () => {
10
- let fixture;
11
- before(async () => {
12
- fixture = await loadFixture({
13
- root: FIXTURE_ROOT,
14
- integrations: [mdx()],
15
- });
16
- await fixture.build();
17
- });
18
-
19
- it('does not have unescaped HTML at top-level', async () => {
20
- const html = await fixture.readFile('/index.html');
21
- const { document } = parseHTML(html);
22
-
23
- expect(document.body.textContent).to.not.include('<em');
24
- });
25
-
26
- it('does not have unescaped HTML inside html tags', async () => {
27
- const html = await fixture.readFile('/html-tag/index.html');
28
- const { document } = parseHTML(html);
29
-
30
- expect(document.body.textContent).to.not.include('<em');
31
- });
32
- });
@@ -1,53 +0,0 @@
1
- import { expect } from 'chai';
2
- import { parseHTML } from 'linkedom';
3
- import { loadFixture } from '../../../astro/test/test-utils.js';
4
-
5
- const FIXTURE_ROOT = new URL('./fixtures/mdx-frontmatter-injection/', import.meta.url);
6
-
7
- describe('MDX frontmatter injection', () => {
8
- let fixture;
9
-
10
- before(async () => {
11
- fixture = await loadFixture({
12
- root: FIXTURE_ROOT,
13
- });
14
- await fixture.build();
15
- });
16
-
17
- it('remark supports custom vfile data - get title', async () => {
18
- const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
19
- const titles = frontmatterByPage.map((frontmatter = {}) => frontmatter.title);
20
- expect(titles).to.contain('Page 1');
21
- expect(titles).to.contain('Page 2');
22
- });
23
-
24
- it('rehype supports custom vfile data - reading time', async () => {
25
- const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
26
- const readingTimes = frontmatterByPage.map(
27
- (frontmatter = {}) => frontmatter.injectedReadingTime
28
- );
29
- expect(readingTimes.length).to.be.greaterThan(0);
30
- for (let readingTime of readingTimes) {
31
- expect(readingTime).to.not.be.null;
32
- expect(readingTime.text).match(/^\d+ min read/);
33
- }
34
- });
35
-
36
- it('allow user frontmatter mutation', async () => {
37
- const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
38
- const descriptions = frontmatterByPage.map((frontmatter = {}) => frontmatter.description);
39
- expect(descriptions).to.contain('Processed by remarkDescription plugin: Page 1 description');
40
- expect(descriptions).to.contain('Processed by remarkDescription plugin: Page 2 description');
41
- });
42
-
43
- it('passes injected frontmatter to layouts', async () => {
44
- const html1 = await fixture.readFile('/page-1/index.html');
45
- const html2 = await fixture.readFile('/page-2/index.html');
46
-
47
- const title1 = parseHTML(html1).document.querySelector('title');
48
- const title2 = parseHTML(html2).document.querySelector('title');
49
-
50
- expect(title1.innerHTML).to.equal('Page 1');
51
- expect(title2.innerHTML).to.equal('Page 2');
52
- });
53
- });
@@ -1,77 +0,0 @@
1
- import mdx from '@astrojs/mdx';
2
-
3
- import { expect } from 'chai';
4
- import { parseHTML } from 'linkedom';
5
- import { loadFixture } from '../../../astro/test/test-utils.js';
6
-
7
- const FIXTURE_ROOT = new URL('./fixtures/mdx-frontmatter/', import.meta.url);
8
-
9
- describe('MDX frontmatter', () => {
10
- let fixture;
11
- before(async () => {
12
- fixture = await loadFixture({
13
- root: FIXTURE_ROOT,
14
- integrations: [mdx()],
15
- });
16
- await fixture.build();
17
- });
18
- it('builds when "frontmatter.property" is in JSX expression', async () => {
19
- expect(true).to.equal(true);
20
- });
21
-
22
- it('extracts frontmatter to "frontmatter" export', async () => {
23
- const { titles } = JSON.parse(await fixture.readFile('/glob.json'));
24
- expect(titles).to.include('Using YAML frontmatter');
25
- });
26
-
27
- it('renders layout from "layout" frontmatter property', async () => {
28
- const html = await fixture.readFile('/index.html');
29
- const { document } = parseHTML(html);
30
-
31
- const layoutParagraph = document.querySelector('[data-layout-rendered]');
32
-
33
- expect(layoutParagraph).to.not.be.null;
34
- });
35
-
36
- it('passes frontmatter to layout via "content" and "frontmatter" props', async () => {
37
- const html = await fixture.readFile('/index.html');
38
- const { document } = parseHTML(html);
39
-
40
- const contentTitle = document.querySelector('[data-content-title]');
41
- const frontmatterTitle = document.querySelector('[data-frontmatter-title]');
42
-
43
- expect(contentTitle.textContent).to.equal('Using YAML frontmatter');
44
- expect(frontmatterTitle.textContent).to.equal('Using YAML frontmatter');
45
- });
46
-
47
- it('passes headings to layout via "headings" prop', async () => {
48
- const html = await fixture.readFile('/with-headings/index.html');
49
- const { document } = parseHTML(html);
50
-
51
- const headingSlugs = [...document.querySelectorAll('[data-headings] > li')].map(
52
- (el) => el.textContent
53
- );
54
-
55
- expect(headingSlugs.length).to.be.greaterThan(0);
56
- expect(headingSlugs).to.contain('section-1');
57
- expect(headingSlugs).to.contain('section-2');
58
- });
59
-
60
- it('passes "file" and "url" to layout', async () => {
61
- const html = await fixture.readFile('/with-headings/index.html');
62
- const { document } = parseHTML(html);
63
-
64
- const frontmatterFile = document.querySelector('[data-frontmatter-file]')?.textContent;
65
- const frontmatterUrl = document.querySelector('[data-frontmatter-url]')?.textContent;
66
- const file = document.querySelector('[data-file]')?.textContent;
67
- const url = document.querySelector('[data-url]')?.textContent;
68
-
69
- expect(frontmatterFile?.endsWith('with-headings.mdx')).to.equal(
70
- true,
71
- '"file" prop does not end with correct path or is undefined'
72
- );
73
- expect(frontmatterUrl).to.equal('/with-headings');
74
- expect(file).to.equal(frontmatterFile);
75
- expect(url).to.equal(frontmatterUrl);
76
- });
77
- });