@astrojs/mdx 1.0.0-beta.2 → 1.0.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/README.md +83 -19
- package/dist/index.d.ts +4 -2
- package/dist/index.js +83 -35
- package/dist/plugins.d.ts +4 -5
- package/dist/plugins.js +36 -80
- package/dist/rehype-collect-headings.d.ts +1 -1
- package/dist/rehype-meta-string.js +2 -3
- package/dist/rehype-optimize-static.d.ts +11 -0
- package/dist/rehype-optimize-static.js +62 -0
- package/dist/remark-images-to-component.d.ts +2 -0
- package/dist/remark-images-to-component.js +83 -0
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +23 -15
- package/package.json +39 -30
- package/template/content-module-types.d.ts +9 -0
- package/.turbo/turbo-build.log +0 -5
- package/CHANGELOG.md +0 -469
- package/src/index.ts +0 -201
- package/src/plugins.ts +0 -246
- package/src/rehype-collect-headings.ts +0 -11
- package/src/rehype-meta-string.ts +0 -17
- package/src/remark-prism.ts +0 -18
- package/src/remark-shiki.ts +0 -95
- package/src/utils.ts +0 -102
- package/test/fixtures/mdx-astro-markdown-remarkRehype/src/pages/index.mdx +0 -5
- package/test/fixtures/mdx-component/src/components/Test.mdx +0 -3
- package/test/fixtures/mdx-component/src/components/WithFragment.mdx +0 -3
- package/test/fixtures/mdx-component/src/pages/glob.astro +0 -20
- package/test/fixtures/mdx-component/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-component/src/pages/w-fragment.astro +0 -5
- package/test/fixtures/mdx-escape/src/components/Em.astro +0 -7
- package/test/fixtures/mdx-escape/src/components/P.astro +0 -1
- package/test/fixtures/mdx-escape/src/components/Title.astro +0 -1
- package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +0 -5
- package/test/fixtures/mdx-escape/src/pages/index.mdx +0 -13
- package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +0 -38
- package/test/fixtures/mdx-frontmatter/src/pages/glob.json.js +0 -9
- package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +0 -10
- package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +0 -7
- package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +0 -12
- package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-frontmatter-injection/package.json +0 -12
- package/test/fixtures/mdx-frontmatter-injection/src/layouts/Base.astro +0 -17
- package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +0 -27
- package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +0 -6
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +0 -8
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +0 -24
- package/test/fixtures/mdx-get-headings/src/pages/pages.json.js +0 -11
- package/test/fixtures/mdx-get-headings/src/pages/test-with-jsx-expressions.mdx +0 -8
- package/test/fixtures/mdx-get-headings/src/pages/test.mdx +0 -9
- package/test/fixtures/mdx-get-static-paths/src/content/1.mdx +0 -5
- package/test/fixtures/mdx-get-static-paths/src/pages/[slug].astro +0 -34
- package/test/fixtures/mdx-infinite-loop/astro.config.ts +0 -6
- package/test/fixtures/mdx-infinite-loop/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-infinite-loop/package.json +0 -10
- package/test/fixtures/mdx-infinite-loop/src/components/Test.js +0 -3
- package/test/fixtures/mdx-infinite-loop/src/pages/doc.mdx +0 -6
- package/test/fixtures/mdx-infinite-loop/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-namespace/astro.config.mjs +0 -6
- package/test/fixtures/mdx-namespace/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-namespace/package.json +0 -10
- package/test/fixtures/mdx-namespace/src/components/Component.jsx +0 -6
- package/test/fixtures/mdx-namespace/src/pages/object.mdx +0 -3
- package/test/fixtures/mdx-namespace/src/pages/star.mdx +0 -3
- package/test/fixtures/mdx-page/astro.config.ts +0 -5
- package/test/fixtures/mdx-page/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-page/package.json +0 -9
- package/test/fixtures/mdx-page/src/pages/index.mdx +0 -3
- package/test/fixtures/mdx-page/src/styles.css +0 -3
- package/test/fixtures/mdx-plugins/src/pages/with-plugins.mdx +0 -25
- package/test/fixtures/mdx-plus-react/astro.config.mjs +0 -6
- package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-plus-react/package.json +0 -10
- package/test/fixtures/mdx-plus-react/src/components/Component.jsx +0 -5
- package/test/fixtures/mdx-plus-react/src/pages/index.astro +0 -11
- package/test/fixtures/mdx-slots/src/components/Slotted.astro +0 -4
- package/test/fixtures/mdx-slots/src/components/Test.mdx +0 -15
- package/test/fixtures/mdx-slots/src/pages/glob.astro +0 -11
- package/test/fixtures/mdx-slots/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-syntax-hightlighting/src/pages/index.mdx +0 -9
- package/test/fixtures/mdx-url-export/src/pages/pages.json.js +0 -9
- package/test/fixtures/mdx-url-export/src/pages/test-1.mdx +0 -1
- package/test/fixtures/mdx-url-export/src/pages/test-2.mdx +0 -1
- package/test/fixtures/mdx-url-export/src/pages/with-url-override.mdx +0 -3
- package/test/fixtures/mdx-vite-env-vars/astro.config.mjs +0 -9
- package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-vite-env-vars/package.json +0 -7
- package/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js +0 -7
- package/test/fixtures/mdx-vite-env-vars/src/pages/vite-env-vars.mdx +0 -38
- package/test/mdx-astro-markdown-remarkRehype.test.js +0 -85
- package/test/mdx-component.test.js +0 -191
- package/test/mdx-escape.test.js +0 -32
- package/test/mdx-frontmatter-injection.test.js +0 -53
- package/test/mdx-frontmatter.test.js +0 -77
- package/test/mdx-get-headings.test.js +0 -151
- package/test/mdx-get-static-paths.test.js +0 -32
- package/test/mdx-infinite-loop.test.js +0 -30
- package/test/mdx-namespace.test.js +0 -83
- package/test/mdx-page.test.js +0 -64
- package/test/mdx-plugins.test.js +0 -250
- package/test/mdx-plus-react.test.js +0 -25
- package/test/mdx-slots.js +0 -124
- package/test/mdx-syntax-highlighting.test.js +0 -145
- package/test/mdx-url-export.test.js +0 -28
- package/test/mdx-vite-env-vars.test.js +0 -54
- package/tsconfig.json +0 -10
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import { parseHTML } from 'linkedom';
|
|
3
|
-
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
4
|
-
|
|
5
|
-
describe('MDX Namespace', () => {
|
|
6
|
-
let fixture;
|
|
7
|
-
|
|
8
|
-
before(async () => {
|
|
9
|
-
fixture = await loadFixture({
|
|
10
|
-
root: new URL('./fixtures/mdx-namespace/', import.meta.url),
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('build', () => {
|
|
15
|
-
before(async () => {
|
|
16
|
-
await fixture.build();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('works for object', async () => {
|
|
20
|
-
const html = await fixture.readFile('/object/index.html');
|
|
21
|
-
const { document } = parseHTML(html);
|
|
22
|
-
|
|
23
|
-
const island = document.querySelector('astro-island');
|
|
24
|
-
const component = document.querySelector('#component');
|
|
25
|
-
|
|
26
|
-
expect(island).not.undefined;
|
|
27
|
-
expect(component.textContent).equal('Hello world');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('works for star', async () => {
|
|
31
|
-
const html = await fixture.readFile('/star/index.html');
|
|
32
|
-
const { document } = parseHTML(html);
|
|
33
|
-
|
|
34
|
-
const island = document.querySelector('astro-island');
|
|
35
|
-
const component = document.querySelector('#component');
|
|
36
|
-
|
|
37
|
-
expect(island).not.undefined;
|
|
38
|
-
expect(component.textContent).equal('Hello world');
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('dev', () => {
|
|
43
|
-
let devServer;
|
|
44
|
-
|
|
45
|
-
before(async () => {
|
|
46
|
-
devServer = await fixture.startDevServer();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
after(async () => {
|
|
50
|
-
await devServer.stop();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('works for object', async () => {
|
|
54
|
-
const res = await fixture.fetch('/object');
|
|
55
|
-
|
|
56
|
-
expect(res.status).to.equal(200);
|
|
57
|
-
|
|
58
|
-
const html = await res.text();
|
|
59
|
-
const { document } = parseHTML(html);
|
|
60
|
-
|
|
61
|
-
const island = document.querySelector('astro-island');
|
|
62
|
-
const component = document.querySelector('#component');
|
|
63
|
-
|
|
64
|
-
expect(island).not.undefined;
|
|
65
|
-
expect(component.textContent).equal('Hello world');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('works for star', async () => {
|
|
69
|
-
const res = await fixture.fetch('/star');
|
|
70
|
-
|
|
71
|
-
expect(res.status).to.equal(200);
|
|
72
|
-
|
|
73
|
-
const html = await res.text();
|
|
74
|
-
const { document } = parseHTML(html);
|
|
75
|
-
|
|
76
|
-
const island = document.querySelector('astro-island');
|
|
77
|
-
const component = document.querySelector('#component');
|
|
78
|
-
|
|
79
|
-
expect(island).not.undefined;
|
|
80
|
-
expect(component.textContent).equal('Hello world');
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
package/test/mdx-page.test.js
DELETED
|
@@ -1,64 +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 Page', () => {
|
|
8
|
-
let fixture;
|
|
9
|
-
|
|
10
|
-
before(async () => {
|
|
11
|
-
fixture = await loadFixture({
|
|
12
|
-
root: new URL('./fixtures/mdx-page/', import.meta.url),
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('build', () => {
|
|
17
|
-
before(async () => {
|
|
18
|
-
await fixture.build();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('works', async () => {
|
|
22
|
-
const html = await fixture.readFile('/index.html');
|
|
23
|
-
const { document } = parseHTML(html);
|
|
24
|
-
|
|
25
|
-
const h1 = document.querySelector('h1');
|
|
26
|
-
|
|
27
|
-
expect(h1.textContent).to.equal('Hello page!');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('injects style imports when layout is not applied', async () => {
|
|
31
|
-
const html = await fixture.readFile('/index.html');
|
|
32
|
-
const { document } = parseHTML(html);
|
|
33
|
-
|
|
34
|
-
const stylesheet = document.querySelector('link[rel="stylesheet"]');
|
|
35
|
-
|
|
36
|
-
expect(stylesheet).to.not.be.null;
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('dev', () => {
|
|
41
|
-
let devServer;
|
|
42
|
-
|
|
43
|
-
before(async () => {
|
|
44
|
-
devServer = await fixture.startDevServer();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
after(async () => {
|
|
48
|
-
await devServer.stop();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('works', async () => {
|
|
52
|
-
const res = await fixture.fetch('/');
|
|
53
|
-
|
|
54
|
-
expect(res.status).to.equal(200);
|
|
55
|
-
|
|
56
|
-
const html = await res.text();
|
|
57
|
-
const { document } = parseHTML(html);
|
|
58
|
-
|
|
59
|
-
const h1 = document.querySelector('h1');
|
|
60
|
-
|
|
61
|
-
expect(h1.textContent).to.equal('Hello page!');
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
package/test/mdx-plugins.test.js
DELETED
|
@@ -1,250 +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('extends markdown config by default', async () => {
|
|
67
|
-
const fixture = await buildFixture({
|
|
68
|
-
markdown: {
|
|
69
|
-
remarkPlugins: [remarkExamplePlugin],
|
|
70
|
-
rehypePlugins: [rehypeExamplePlugin],
|
|
71
|
-
},
|
|
72
|
-
integrations: [mdx()],
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const html = await fixture.readFile(FILE);
|
|
76
|
-
const { document } = parseHTML(html);
|
|
77
|
-
|
|
78
|
-
expect(selectRemarkExample(document)).to.not.be.null;
|
|
79
|
-
expect(selectRehypeExample(document)).to.not.be.null;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('ignores string-based plugins in markdown config', async () => {
|
|
83
|
-
const fixture = await buildFixture({
|
|
84
|
-
markdown: {
|
|
85
|
-
remarkPlugins: [['remark-toc']],
|
|
86
|
-
},
|
|
87
|
-
integrations: [mdx()],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const html = await fixture.readFile(FILE);
|
|
91
|
-
const { document } = parseHTML(html);
|
|
92
|
-
|
|
93
|
-
expect(selectTocLink(document)).to.be.null;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
for (const extendMarkdownConfig of [true, false]) {
|
|
97
|
-
describe(`extendMarkdownConfig = ${extendMarkdownConfig}`, () => {
|
|
98
|
-
let fixture;
|
|
99
|
-
before(async () => {
|
|
100
|
-
fixture = await buildFixture({
|
|
101
|
-
markdown: {
|
|
102
|
-
remarkPlugins: [remarkToc],
|
|
103
|
-
gfm: false,
|
|
104
|
-
smartypants: false,
|
|
105
|
-
},
|
|
106
|
-
integrations: [
|
|
107
|
-
mdx({
|
|
108
|
-
extendMarkdownConfig,
|
|
109
|
-
remarkPlugins: [remarkExamplePlugin],
|
|
110
|
-
rehypePlugins: [rehypeExamplePlugin],
|
|
111
|
-
}),
|
|
112
|
-
],
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('Handles MDX plugins', async () => {
|
|
117
|
-
const html = await fixture.readFile(FILE);
|
|
118
|
-
const { document } = parseHTML(html);
|
|
119
|
-
|
|
120
|
-
expect(selectRemarkExample(document, 'MDX remark plugins not applied.')).to.not.be.null;
|
|
121
|
-
expect(selectRehypeExample(document, 'MDX rehype plugins not applied.')).to.not.be.null;
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('Handles Markdown plugins', async () => {
|
|
125
|
-
const html = await fixture.readFile(FILE);
|
|
126
|
-
const { document } = parseHTML(html);
|
|
127
|
-
|
|
128
|
-
expect(
|
|
129
|
-
selectTocLink(
|
|
130
|
-
document,
|
|
131
|
-
'`remarkToc` plugin applied unexpectedly. Should override Markdown config.'
|
|
132
|
-
)
|
|
133
|
-
).to.be.null;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('Handles gfm', async () => {
|
|
137
|
-
const html = await fixture.readFile(FILE);
|
|
138
|
-
const { document } = parseHTML(html);
|
|
139
|
-
|
|
140
|
-
if (extendMarkdownConfig === true) {
|
|
141
|
-
expect(selectGfmLink(document), 'Does not respect `markdown.gfm` option.').to.be.null;
|
|
142
|
-
} else {
|
|
143
|
-
expect(selectGfmLink(document), 'Respects `markdown.gfm` unexpectedly.').to.not.be.null;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('Handles smartypants', async () => {
|
|
148
|
-
const html = await fixture.readFile(FILE);
|
|
149
|
-
const { document } = parseHTML(html);
|
|
150
|
-
|
|
151
|
-
const quote = selectSmartypantsQuote(document);
|
|
152
|
-
|
|
153
|
-
if (extendMarkdownConfig === true) {
|
|
154
|
-
expect(quote.textContent, 'Does not respect `markdown.smartypants` option.').to.contain(
|
|
155
|
-
'"Smartypants" is -- awesome'
|
|
156
|
-
);
|
|
157
|
-
} else {
|
|
158
|
-
expect(quote.textContent, 'Respects `markdown.smartypants` unexpectedly.').to.contain(
|
|
159
|
-
'“Smartypants” is — awesome'
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
it('supports custom recma plugins', async () => {
|
|
167
|
-
const fixture = await buildFixture({
|
|
168
|
-
integrations: [
|
|
169
|
-
mdx({
|
|
170
|
-
recmaPlugins: [recmaExamplePlugin],
|
|
171
|
-
}),
|
|
172
|
-
],
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const html = await fixture.readFile(FILE);
|
|
176
|
-
const { document } = parseHTML(html);
|
|
177
|
-
|
|
178
|
-
expect(selectRecmaExample(document)).to.not.be.null;
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
async function buildFixture(config) {
|
|
183
|
-
const fixture = await loadFixture({
|
|
184
|
-
root: FIXTURE_ROOT,
|
|
185
|
-
...config,
|
|
186
|
-
});
|
|
187
|
-
await fixture.build();
|
|
188
|
-
return fixture;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function remarkExamplePlugin() {
|
|
192
|
-
return (tree) => {
|
|
193
|
-
tree.children.push({
|
|
194
|
-
type: 'html',
|
|
195
|
-
value: '<div data-remark-plugin-works="true"></div>',
|
|
196
|
-
});
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function rehypeExamplePlugin() {
|
|
201
|
-
return (tree) => {
|
|
202
|
-
tree.children.push({
|
|
203
|
-
type: 'element',
|
|
204
|
-
tagName: 'div',
|
|
205
|
-
properties: { 'data-rehype-plugin-works': 'true' },
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function recmaExamplePlugin() {
|
|
211
|
-
return (tree) => {
|
|
212
|
-
estreeVisit(tree, (node) => {
|
|
213
|
-
if (
|
|
214
|
-
node.type === 'VariableDeclarator' &&
|
|
215
|
-
node.id.name === 'recmaPluginWorking' &&
|
|
216
|
-
node.init?.type === 'Literal'
|
|
217
|
-
) {
|
|
218
|
-
node.init = {
|
|
219
|
-
...(node.init ?? {}),
|
|
220
|
-
value: true,
|
|
221
|
-
raw: 'true',
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function selectTocLink(document) {
|
|
229
|
-
return document.querySelector('ul a[href="#section-1"]');
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function selectGfmLink(document) {
|
|
233
|
-
return document.querySelector('a[href="https://handle-me-gfm.com"]');
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function selectSmartypantsQuote(document) {
|
|
237
|
-
return document.querySelector('blockquote');
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function selectRemarkExample(document) {
|
|
241
|
-
return document.querySelector('div[data-remark-plugin-works]');
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function selectRehypeExample(document) {
|
|
245
|
-
return document.querySelector('div[data-rehype-plugin-works]');
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function selectRecmaExample(document) {
|
|
249
|
-
return document.querySelector('div[data-recma-plugin-works]');
|
|
250
|
-
}
|
|
@@ -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
|
-
});
|
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
|
-
});
|