@astrojs/mdx 0.5.0 → 0.8.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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +30 -0
- package/README.md +57 -76
- package/dist/astro-data-utils.d.ts +9 -0
- package/dist/astro-data-utils.js +47 -0
- package/dist/index.d.ts +0 -7
- package/dist/index.js +49 -44
- package/dist/utils.d.ts +2 -3
- package/dist/utils.js +4 -4
- package/package.json +4 -5
- package/src/astro-data-utils.ts +59 -0
- package/src/index.ts +63 -59
- package/src/utils.ts +2 -2
- package/test/fixtures/mdx-escape/src/components/Em.astro +7 -0
- package/test/fixtures/mdx-escape/src/components/P.astro +1 -0
- package/test/fixtures/mdx-escape/src/components/Title.astro +1 -0
- package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +5 -0
- package/test/fixtures/mdx-escape/src/pages/index.mdx +13 -0
- package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +13 -3
- package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +3 -0
- package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +7 -0
- package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +12 -0
- package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +17 -0
- package/test/fixtures/mdx-frontmatter-injection/package.json +12 -0
- package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +20 -0
- package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +6 -0
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +3 -0
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +19 -0
- package/test/fixtures/mdx-frontmatter-injection/src/pages/with-overrides.mdx +7 -0
- package/test/fixtures/mdx-plus-react/astro.config.mjs +6 -0
- package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +17 -0
- package/test/fixtures/mdx-plus-react/package.json +8 -0
- package/test/fixtures/mdx-plus-react/src/components/Component.jsx +5 -0
- package/test/fixtures/mdx-plus-react/src/pages/index.astro +11 -0
- package/test/fixtures/mdx-rehype-plugins/src/pages/reading-time.json.js +2 -2
- package/test/fixtures/mdx-remark-plugins/src/pages/headings-glob.json.js +6 -0
- package/test/mdx-escape.test.js +32 -0
- package/test/mdx-frontmatter-injection.test.js +44 -0
- package/test/mdx-frontmatter.test.js +20 -37
- package/test/mdx-plus-react.test.js +25 -0
- package/test/mdx-rehype-plugins.test.js +6 -17
- package/test/fixtures/mdx-custom-frontmatter-name/src/pages/glob.json.js +0 -9
- package/test/fixtures/mdx-custom-frontmatter-name/src/pages/index.mdx +0 -6
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import mdx from '@astrojs/mdx';
|
|
2
|
-
import { jsToTreeNode } from '../dist/utils.js';
|
|
3
2
|
|
|
4
|
-
import { expect } from 'chai';
|
|
5
|
-
import { parseHTML } from 'linkedom';
|
|
6
3
|
import getReadingTime from 'reading-time';
|
|
7
4
|
import { toString } from 'mdast-util-to-string';
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
import { parseHTML } from 'linkedom';
|
|
7
|
+
import { jsToTreeNode } from '../dist/utils.js';
|
|
8
8
|
|
|
9
9
|
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
return function (tree) {
|
|
11
|
+
function rehypeReadingTime() {
|
|
12
|
+
return function (tree, { data }) {
|
|
13
13
|
const readingTime = getReadingTime(toString(tree));
|
|
14
14
|
tree.children.unshift(
|
|
15
15
|
jsToTreeNode(`export const readingTime = ${JSON.stringify(readingTime)}`)
|
|
@@ -34,19 +34,8 @@ describe('MDX rehype plugins', () => {
|
|
|
34
34
|
await fixture.build();
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it('removes default getHeadings', async () => {
|
|
38
|
-
const html = await fixture.readFile('/space-ipsum/index.html');
|
|
39
|
-
const { document } = parseHTML(html);
|
|
40
|
-
|
|
41
|
-
const headings = [...document.querySelectorAll('h1, h2')];
|
|
42
|
-
expect(headings.length).to.be.greaterThan(0);
|
|
43
|
-
for (const heading of headings) {
|
|
44
|
-
expect(heading.id).to.be.empty;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
37
|
it('supports custom rehype plugins - reading time', async () => {
|
|
49
|
-
const readingTime = JSON.parse(await fixture.readFile('/reading-time.json'));
|
|
38
|
+
const { readingTime } = JSON.parse(await fixture.readFile('/reading-time.json'));
|
|
50
39
|
|
|
51
40
|
expect(readingTime).to.not.be.null;
|
|
52
41
|
expect(readingTime.text).to.match(/^\d+ min read/);
|