@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,285 +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
- import remarkToc from 'remark-toc';
7
- import { visit as estreeVisit } from 'estree-util-visit';
8
-
9
- const FIXTURE_ROOT = new URL('./fixtures/mdx-plugins/', import.meta.url);
10
- const FILE = '/with-plugins/index.html';
11
-
12
- describe('MDX plugins', () => {
13
- it('supports custom remark plugins - TOC', async () => {
14
- const fixture = await buildFixture({
15
- integrations: [
16
- mdx({
17
- remarkPlugins: [remarkToc],
18
- }),
19
- ],
20
- });
21
-
22
- const html = await fixture.readFile(FILE);
23
- const { document } = parseHTML(html);
24
-
25
- expect(selectTocLink(document)).to.not.be.null;
26
- });
27
-
28
- it('Applies GFM by default', async () => {
29
- const fixture = await buildFixture({
30
- integrations: [mdx()],
31
- });
32
-
33
- const html = await fixture.readFile(FILE);
34
- const { document } = parseHTML(html);
35
-
36
- expect(selectGfmLink(document)).to.not.be.null;
37
- });
38
-
39
- it('Applies SmartyPants by default', async () => {
40
- const fixture = await buildFixture({
41
- integrations: [mdx()],
42
- });
43
-
44
- const html = await fixture.readFile(FILE);
45
- const { document } = parseHTML(html);
46
-
47
- const quote = selectSmartypantsQuote(document);
48
- expect(quote).to.not.be.null;
49
- expect(quote.textContent).to.contain('“Smartypants” is — awesome');
50
- });
51
-
52
- it('supports custom rehype plugins', async () => {
53
- const fixture = await buildFixture({
54
- integrations: [
55
- mdx({
56
- rehypePlugins: [rehypeExamplePlugin],
57
- }),
58
- ],
59
- });
60
- const html = await fixture.readFile(FILE);
61
- const { document } = parseHTML(html);
62
-
63
- expect(selectRehypeExample(document)).to.not.be.null;
64
- });
65
-
66
- it('supports custom rehype plugins with namespaced attributes', async () => {
67
- const fixture = await buildFixture({
68
- integrations: [
69
- mdx({
70
- rehypePlugins: [rehypeSvgPlugin],
71
- }),
72
- ],
73
- });
74
- const html = await fixture.readFile(FILE);
75
- const { document } = parseHTML(html);
76
-
77
- expect(selectRehypeSvg(document)).to.not.be.null;
78
- });
79
-
80
- it('extends markdown config by default', async () => {
81
- const fixture = await buildFixture({
82
- markdown: {
83
- remarkPlugins: [remarkExamplePlugin],
84
- rehypePlugins: [rehypeExamplePlugin],
85
- },
86
- integrations: [mdx()],
87
- });
88
-
89
- const html = await fixture.readFile(FILE);
90
- const { document } = parseHTML(html);
91
-
92
- expect(selectRemarkExample(document)).to.not.be.null;
93
- expect(selectRehypeExample(document)).to.not.be.null;
94
- });
95
-
96
- it('ignores string-based plugins in markdown config', async () => {
97
- const fixture = await buildFixture({
98
- markdown: {
99
- remarkPlugins: [['remark-toc']],
100
- },
101
- integrations: [mdx()],
102
- });
103
-
104
- const html = await fixture.readFile(FILE);
105
- const { document } = parseHTML(html);
106
-
107
- expect(selectTocLink(document)).to.be.null;
108
- });
109
-
110
- for (const extendMarkdownConfig of [true, false]) {
111
- describe(`extendMarkdownConfig = ${extendMarkdownConfig}`, () => {
112
- let fixture;
113
- before(async () => {
114
- fixture = await buildFixture({
115
- markdown: {
116
- remarkPlugins: [remarkToc],
117
- gfm: false,
118
- smartypants: false,
119
- },
120
- integrations: [
121
- mdx({
122
- extendMarkdownConfig,
123
- remarkPlugins: [remarkExamplePlugin],
124
- rehypePlugins: [rehypeExamplePlugin],
125
- }),
126
- ],
127
- });
128
- });
129
-
130
- it('Handles MDX plugins', async () => {
131
- const html = await fixture.readFile(FILE);
132
- const { document } = parseHTML(html);
133
-
134
- expect(selectRemarkExample(document, 'MDX remark plugins not applied.')).to.not.be.null;
135
- expect(selectRehypeExample(document, 'MDX rehype plugins not applied.')).to.not.be.null;
136
- });
137
-
138
- it('Handles Markdown plugins', async () => {
139
- const html = await fixture.readFile(FILE);
140
- const { document } = parseHTML(html);
141
-
142
- expect(
143
- selectTocLink(
144
- document,
145
- '`remarkToc` plugin applied unexpectedly. Should override Markdown config.'
146
- )
147
- ).to.be.null;
148
- });
149
-
150
- it('Handles gfm', async () => {
151
- const html = await fixture.readFile(FILE);
152
- const { document } = parseHTML(html);
153
-
154
- if (extendMarkdownConfig === true) {
155
- expect(selectGfmLink(document), 'Does not respect `markdown.gfm` option.').to.be.null;
156
- } else {
157
- expect(selectGfmLink(document), 'Respects `markdown.gfm` unexpectedly.').to.not.be.null;
158
- }
159
- });
160
-
161
- it('Handles smartypants', async () => {
162
- const html = await fixture.readFile(FILE);
163
- const { document } = parseHTML(html);
164
-
165
- const quote = selectSmartypantsQuote(document);
166
-
167
- if (extendMarkdownConfig === true) {
168
- expect(quote.textContent, 'Does not respect `markdown.smartypants` option.').to.contain(
169
- '"Smartypants" is -- awesome'
170
- );
171
- } else {
172
- expect(quote.textContent, 'Respects `markdown.smartypants` unexpectedly.').to.contain(
173
- '“Smartypants” is — awesome'
174
- );
175
- }
176
- });
177
- });
178
- }
179
-
180
- it('supports custom recma plugins', async () => {
181
- const fixture = await buildFixture({
182
- integrations: [
183
- mdx({
184
- recmaPlugins: [recmaExamplePlugin],
185
- }),
186
- ],
187
- });
188
-
189
- const html = await fixture.readFile(FILE);
190
- const { document } = parseHTML(html);
191
-
192
- expect(selectRecmaExample(document)).to.not.be.null;
193
- });
194
- });
195
-
196
- async function buildFixture(config) {
197
- const fixture = await loadFixture({
198
- root: FIXTURE_ROOT,
199
- ...config,
200
- });
201
- await fixture.build();
202
- return fixture;
203
- }
204
-
205
- function remarkExamplePlugin() {
206
- return (tree) => {
207
- tree.children.push({
208
- type: 'html',
209
- value: '<div data-remark-plugin-works="true"></div>',
210
- });
211
- };
212
- }
213
-
214
- function rehypeExamplePlugin() {
215
- return (tree) => {
216
- tree.children.push({
217
- type: 'element',
218
- tagName: 'div',
219
- properties: { 'data-rehype-plugin-works': 'true' },
220
- });
221
- };
222
- }
223
-
224
- function rehypeSvgPlugin() {
225
- return (tree) => {
226
- tree.children.push({
227
- type: 'element',
228
- tagName: 'svg',
229
- properties: { xmlns: 'http://www.w3.org/2000/svg' },
230
- children: [
231
- {
232
- type: 'element',
233
- tagName: 'use',
234
- properties: { xLinkHref: '#icon' },
235
- },
236
- ],
237
- });
238
- };
239
- }
240
-
241
- function recmaExamplePlugin() {
242
- return (tree) => {
243
- estreeVisit(tree, (node) => {
244
- if (
245
- node.type === 'VariableDeclarator' &&
246
- node.id.name === 'recmaPluginWorking' &&
247
- node.init?.type === 'Literal'
248
- ) {
249
- node.init = {
250
- ...(node.init ?? {}),
251
- value: true,
252
- raw: 'true',
253
- };
254
- }
255
- });
256
- };
257
- }
258
-
259
- function selectTocLink(document) {
260
- return document.querySelector('ul a[href="#section-1"]');
261
- }
262
-
263
- function selectGfmLink(document) {
264
- return document.querySelector('a[href="https://handle-me-gfm.com"]');
265
- }
266
-
267
- function selectSmartypantsQuote(document) {
268
- return document.querySelector('blockquote');
269
- }
270
-
271
- function selectRemarkExample(document) {
272
- return document.querySelector('div[data-remark-plugin-works]');
273
- }
274
-
275
- function selectRehypeExample(document) {
276
- return document.querySelector('div[data-rehype-plugin-works]');
277
- }
278
-
279
- function selectRehypeSvg(document) {
280
- return document.querySelector('svg > use[xlink\\:href]');
281
- }
282
-
283
- function selectRecmaExample(document) {
284
- return document.querySelector('div[data-recma-plugin-works]');
285
- }
@@ -1,25 +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 and React', () => {
8
- let fixture;
9
-
10
- before(async () => {
11
- fixture = await loadFixture({
12
- root: new URL('./fixtures/mdx-plus-react/', import.meta.url),
13
- });
14
- await fixture.build();
15
- });
16
-
17
- it('can be used in the same project', async () => {
18
- const html = await fixture.readFile('/index.html');
19
- const { document } = parseHTML(html);
20
-
21
- const p = document.querySelector('p');
22
-
23
- expect(p.textContent).to.equal('Hello world');
24
- });
25
- });
@@ -1,70 +0,0 @@
1
- import mdx from '@astrojs/mdx';
2
- import { expect } from 'chai';
3
- import { parseHTML } from 'linkedom';
4
- import { loadFixture } from '../../../astro/test/test-utils.js';
5
-
6
- const FIXTURE_ROOT = new URL('./fixtures/mdx-script-style-raw/', import.meta.url);
7
-
8
- describe('MDX script style raw', () => {
9
- describe('dev', () => {
10
- let fixture;
11
- let devServer;
12
-
13
- before(async () => {
14
- fixture = await loadFixture({
15
- root: FIXTURE_ROOT,
16
- integrations: [mdx()],
17
- });
18
- devServer = await fixture.startDevServer();
19
- });
20
-
21
- after(async () => {
22
- await devServer.stop();
23
- });
24
-
25
- it('works with with raw script and style strings', async () => {
26
- const res = await fixture.fetch('/index.html');
27
- expect(res.status).to.equal(200);
28
-
29
- const html = await res.text();
30
- const { document } = parseHTML(html);
31
-
32
- const scriptContent = document.getElementById('test-script').innerHTML;
33
- expect(scriptContent).to.include(
34
- "console.log('raw script')",
35
- 'script should not be html-escaped'
36
- );
37
-
38
- const styleContent = document.getElementById('test-style').innerHTML;
39
- expect(styleContent).to.include(
40
- 'h1[id="script-style-raw"]',
41
- 'style should not be html-escaped'
42
- );
43
- });
44
- });
45
-
46
- describe('build', () => {
47
- it('works with with raw script and style strings', async () => {
48
- const fixture = await loadFixture({
49
- root: FIXTURE_ROOT,
50
- integrations: [mdx()],
51
- });
52
- await fixture.build();
53
-
54
- const html = await fixture.readFile('/index.html');
55
- const { document } = parseHTML(html);
56
-
57
- const scriptContent = document.getElementById('test-script').innerHTML;
58
- expect(scriptContent).to.include(
59
- "console.log('raw script')",
60
- 'script should not be html-escaped'
61
- );
62
-
63
- const styleContent = document.getElementById('test-style').innerHTML;
64
- expect(styleContent).to.include(
65
- 'h1[id="script-style-raw"]',
66
- 'style should not be html-escaped'
67
- );
68
- });
69
- });
70
- });
package/test/mdx-slots.js DELETED
@@ -1,124 +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 slots', () => {
8
- let fixture;
9
-
10
- before(async () => {
11
- fixture = await loadFixture({
12
- root: new URL('./fixtures/mdx-slots/', 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 defaultSlot = document.querySelector('[data-default-slot]');
28
- const namedSlot = document.querySelector('[data-named-slot]');
29
-
30
- expect(h1.textContent).to.equal('Hello slotted component!');
31
- expect(defaultSlot.textContent).to.equal('Default content.');
32
- expect(namedSlot.textContent).to.equal('Content for named slot.');
33
- });
34
-
35
- it('supports glob imports - <Component.default />', async () => {
36
- const html = await fixture.readFile('/glob/index.html');
37
- const { document } = parseHTML(html);
38
-
39
- const h1 = document.querySelector('[data-default-export] h1');
40
- const defaultSlot = document.querySelector('[data-default-export] [data-default-slot]');
41
- const namedSlot = document.querySelector('[data-default-export] [data-named-slot]');
42
-
43
- expect(h1.textContent).to.equal('Hello slotted component!');
44
- expect(defaultSlot.textContent).to.equal('Default content.');
45
- expect(namedSlot.textContent).to.equal('Content for named slot.');
46
- });
47
-
48
- it('supports glob imports - <Content />', async () => {
49
- const html = await fixture.readFile('/glob/index.html');
50
- const { document } = parseHTML(html);
51
-
52
- const h1 = document.querySelector('[data-content-export] h1');
53
- const defaultSlot = document.querySelector('[data-content-export] [data-default-slot]');
54
- const namedSlot = document.querySelector('[data-content-export] [data-named-slot]');
55
-
56
- expect(h1.textContent).to.equal('Hello slotted component!');
57
- expect(defaultSlot.textContent).to.equal('Default content.');
58
- expect(namedSlot.textContent).to.equal('Content for named slot.');
59
- });
60
- });
61
-
62
- describe('dev', () => {
63
- let devServer;
64
-
65
- before(async () => {
66
- devServer = await fixture.startDevServer();
67
- });
68
-
69
- after(async () => {
70
- await devServer.stop();
71
- });
72
-
73
- it('supports top-level imports', async () => {
74
- const res = await fixture.fetch('/');
75
-
76
- expect(res.status).to.equal(200);
77
-
78
- const html = await res.text();
79
- const { document } = parseHTML(html);
80
-
81
- const h1 = document.querySelector('h1');
82
- const defaultSlot = document.querySelector('[data-default-slot]');
83
- const namedSlot = document.querySelector('[data-named-slot]');
84
-
85
- expect(h1.textContent).to.equal('Hello slotted component!');
86
- expect(defaultSlot.textContent).to.equal('Default content.');
87
- expect(namedSlot.textContent).to.equal('Content for named slot.');
88
- });
89
-
90
- it('supports glob imports - <Component.default />', async () => {
91
- const res = await fixture.fetch('/glob');
92
-
93
- expect(res.status).to.equal(200);
94
-
95
- const html = await res.text();
96
- const { document } = parseHTML(html);
97
-
98
- const h1 = document.querySelector('[data-default-export] h1');
99
- const defaultSlot = document.querySelector('[data-default-export] [data-default-slot]');
100
- const namedSlot = document.querySelector('[data-default-export] [data-named-slot]');
101
-
102
- expect(h1.textContent).to.equal('Hello slotted component!');
103
- expect(defaultSlot.textContent).to.equal('Default content.');
104
- expect(namedSlot.textContent).to.equal('Content for named slot.');
105
- });
106
-
107
- it('supports glob imports - <Content />', async () => {
108
- const res = await fixture.fetch('/glob');
109
-
110
- expect(res.status).to.equal(200);
111
-
112
- const html = await res.text();
113
- const { document } = parseHTML(html);
114
-
115
- const h1 = document.querySelector('[data-content-export] h1');
116
- const defaultSlot = document.querySelector('[data-content-export] [data-default-slot]');
117
- const namedSlot = document.querySelector('[data-content-export] [data-named-slot]');
118
-
119
- expect(h1.textContent).to.equal('Hello slotted component!');
120
- expect(defaultSlot.textContent).to.equal('Default content.');
121
- expect(namedSlot.textContent).to.equal('Content for named slot.');
122
- });
123
- });
124
- });
@@ -1,145 +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
- import shikiTwoslash from 'remark-shiki-twoslash';
7
- import rehypePrettyCode from 'rehype-pretty-code';
8
-
9
- const FIXTURE_ROOT = new URL('./fixtures/mdx-syntax-hightlighting/', import.meta.url);
10
-
11
- describe('MDX syntax highlighting', () => {
12
- describe('shiki', () => {
13
- it('works', async () => {
14
- const fixture = await loadFixture({
15
- root: FIXTURE_ROOT,
16
- markdown: {
17
- syntaxHighlight: 'shiki',
18
- },
19
- integrations: [mdx()],
20
- });
21
- await fixture.build();
22
-
23
- const html = await fixture.readFile('/index.html');
24
- const { document } = parseHTML(html);
25
-
26
- const shikiCodeBlock = document.querySelector('pre.astro-code');
27
- expect(shikiCodeBlock).to.not.be.null;
28
- expect(shikiCodeBlock.getAttribute('style')).to.contain('background-color:#0d1117');
29
- });
30
-
31
- it('respects markdown.shikiConfig.theme', async () => {
32
- const fixture = await loadFixture({
33
- root: FIXTURE_ROOT,
34
- markdown: {
35
- syntaxHighlight: 'shiki',
36
- shikiConfig: {
37
- theme: 'dracula',
38
- },
39
- },
40
- integrations: [mdx()],
41
- });
42
- await fixture.build();
43
-
44
- const html = await fixture.readFile('/index.html');
45
- const { document } = parseHTML(html);
46
-
47
- const shikiCodeBlock = document.querySelector('pre.astro-code');
48
- expect(shikiCodeBlock).to.not.be.null;
49
- expect(shikiCodeBlock.getAttribute('style')).to.contain('background-color:#282A36');
50
- });
51
- });
52
-
53
- describe('prism', () => {
54
- it('works', async () => {
55
- const fixture = await loadFixture({
56
- root: FIXTURE_ROOT,
57
- markdown: {
58
- syntaxHighlight: 'prism',
59
- },
60
- integrations: [mdx()],
61
- });
62
- await fixture.build();
63
-
64
- const html = await fixture.readFile('/index.html');
65
- const { document } = parseHTML(html);
66
-
67
- const prismCodeBlock = document.querySelector('pre.language-astro');
68
- expect(prismCodeBlock).to.not.be.null;
69
- });
70
-
71
- for (const extendMarkdownConfig of [true, false]) {
72
- it(`respects syntaxHighlight when extendMarkdownConfig = ${extendMarkdownConfig}`, async () => {
73
- const fixture = await loadFixture({
74
- root: FIXTURE_ROOT,
75
- markdown: {
76
- syntaxHighlight: 'shiki',
77
- },
78
- integrations: [
79
- mdx({
80
- extendMarkdownConfig,
81
- syntaxHighlight: 'prism',
82
- }),
83
- ],
84
- });
85
- await fixture.build();
86
-
87
- const html = await fixture.readFile('/index.html');
88
- const { document } = parseHTML(html);
89
-
90
- const shikiCodeBlock = document.querySelector('pre.astro-code');
91
- expect(shikiCodeBlock, 'Markdown config syntaxHighlight used unexpectedly').to.be.null;
92
- const prismCodeBlock = document.querySelector('pre.language-astro');
93
- expect(prismCodeBlock).to.not.be.null;
94
- });
95
- }
96
- });
97
-
98
- it('supports custom highlighter - shiki-twoslash', async () => {
99
- const fixture = await loadFixture({
100
- root: FIXTURE_ROOT,
101
- markdown: {
102
- syntaxHighlight: false,
103
- },
104
- integrations: [
105
- mdx({
106
- remarkPlugins: [shikiTwoslash.default ?? shikiTwoslash],
107
- }),
108
- ],
109
- });
110
- await fixture.build();
111
-
112
- const html = await fixture.readFile('/index.html');
113
- const { document } = parseHTML(html);
114
-
115
- const twoslashCodeBlock = document.querySelector('pre.shiki');
116
- expect(twoslashCodeBlock).to.not.be.null;
117
- });
118
-
119
- it('supports custom highlighter - rehype-pretty-code', async () => {
120
- const fixture = await loadFixture({
121
- root: FIXTURE_ROOT,
122
- markdown: {
123
- syntaxHighlight: false,
124
- },
125
- integrations: [
126
- mdx({
127
- rehypePlugins: [
128
- [
129
- rehypePrettyCode,
130
- {
131
- onVisitHighlightedLine(node) {
132
- node.properties.style = 'background-color:#000000';
133
- },
134
- },
135
- ],
136
- ],
137
- }),
138
- ],
139
- });
140
- await fixture.build();
141
-
142
- const html = await fixture.readFile('/index.html');
143
- expect(html).to.include('style="background-color:#000000"');
144
- });
145
- });
@@ -1,28 +0,0 @@
1
- import mdx from '@astrojs/mdx';
2
-
3
- import { expect } from 'chai';
4
- import { loadFixture } from '../../../astro/test/test-utils.js';
5
-
6
- describe('MDX url export', () => {
7
- let fixture;
8
-
9
- before(async () => {
10
- fixture = await loadFixture({
11
- root: new URL('./fixtures/mdx-url-export/', import.meta.url),
12
- integrations: [mdx()],
13
- });
14
-
15
- await fixture.build();
16
- });
17
-
18
- it('generates correct urls in glob result', async () => {
19
- const { urls } = JSON.parse(await fixture.readFile('/pages.json'));
20
- expect(urls).to.include('/test-1');
21
- expect(urls).to.include('/test-2');
22
- });
23
-
24
- it('respects "export url" overrides in glob result', async () => {
25
- const { urls } = JSON.parse(await fixture.readFile('/pages.json'));
26
- expect(urls).to.include('/AH!');
27
- });
28
- });