@astrojs/mdx 0.11.6 → 0.12.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 +10 -0
- package/README.md +21 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/package.json +3 -2
- package/src/index.ts +12 -0
- package/test/fixtures/mdx-astro-markdown-remarkRehype/src/pages/index.mdx +5 -0
- package/test/mdx-astro-markdown-remarkRehype.test.js +85 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
1
|
+
[33m@astrojs/mdx:build: [0mcache hit, replaying output [2mdac9ca86e0959274[0m
|
|
2
|
+
[33m@astrojs/mdx:build: [0m
|
|
3
|
+
[33m@astrojs/mdx:build: [0m> @astrojs/mdx@0.12.0 build /home/runner/work/astro/astro/packages/integrations/mdx
|
|
4
|
+
[33m@astrojs/mdx:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
|
+
[33m@astrojs/mdx:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @astrojs/mdx
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#5427](https://github.com/withastro/astro/pull/5427) [`2a1c085b1`](https://github.com/withastro/astro/commit/2a1c085b199f24e34424ec8c19041c03602c53c5) Thanks [@backflip](https://github.com/backflip)! - Uses remark-rehype options from astro.config.mjs
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#5448](https://github.com/withastro/astro/pull/5448) [`ef2ffc7ae`](https://github.com/withastro/astro/commit/ef2ffc7ae9ff554860238ecd2fb3bf6d82b5801b) Thanks [@delucis](https://github.com/delucis)! - Fix broken link in README
|
|
12
|
+
|
|
3
13
|
## 0.11.6
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -191,7 +191,7 @@ export default {
|
|
|
191
191
|
};
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
-
…every MDX file will have `customProperty` in its frontmatter! See [our Markdown documentation](https://docs.astro.build/en/guides/markdown-content/#injecting-frontmatter) for more usage instructions and a [reading time plugin example](https://docs.astro.build/en/guides/markdown-content/#example-calculate-reading-time).
|
|
194
|
+
…every MDX file will have `customProperty` in its frontmatter! See [our Markdown documentation](https://docs.astro.build/en/guides/markdown-content/#example-injecting-frontmatter) for more usage instructions and a [reading time plugin example](https://docs.astro.build/en/guides/markdown-content/#example-calculate-reading-time).
|
|
195
195
|
|
|
196
196
|
### Layouts
|
|
197
197
|
Layouts can be applied [in the same way as standard Astro Markdown](https://docs.astro.build/en/guides/markdown-content/#frontmatter-layout). You can add a `layout` to [your frontmatter](#frontmatter) like so:
|
|
@@ -518,6 +518,26 @@ These are plugins that modify the output [estree](https://github.com/estree/estr
|
|
|
518
518
|
|
|
519
519
|
We suggest [using AST Explorer](https://astexplorer.net/) to play with estree outputs, and trying [`estree-util-visit`](https://unifiedjs.com/explore/package/estree-util-visit/) for searching across JavaScript nodes.
|
|
520
520
|
|
|
521
|
+
### remarkRehype
|
|
522
|
+
|
|
523
|
+
Markdown content is transformed into HTML through remark-rehype which has [a number of options](https://github.com/remarkjs/remark-rehype#options).
|
|
524
|
+
|
|
525
|
+
You can use remark-rehype options in your MDX integration config file like so:
|
|
526
|
+
|
|
527
|
+
```js
|
|
528
|
+
// astro.config.mjs
|
|
529
|
+
export default {
|
|
530
|
+
integrations: [mdx({
|
|
531
|
+
remarkRehype: {
|
|
532
|
+
footnoteLabel: 'Catatan kaki',
|
|
533
|
+
footnoteBackLabel: 'Kembali ke konten',
|
|
534
|
+
},
|
|
535
|
+
})],
|
|
536
|
+
};
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
This inherits the configuration of `markdown.remarkRehype`. This behavior can be changed by configuring `extendPlugins`.
|
|
540
|
+
|
|
521
541
|
## Examples
|
|
522
542
|
|
|
523
543
|
- The [Astro MDX example](https://github.com/withastro/astro/tree/latest/examples/with-mdx) shows how to use MDX files in your Astro project.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PluggableList } from '@mdx-js/mdx/lib/core.js';
|
|
2
2
|
import type { AstroIntegration } from 'astro';
|
|
3
|
+
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
3
4
|
export declare type MdxOptions = {
|
|
4
5
|
remarkPlugins?: PluggableList;
|
|
5
6
|
rehypePlugins?: PluggableList;
|
|
@@ -12,5 +13,6 @@ export declare type MdxOptions = {
|
|
|
12
13
|
* - false - do not inherit any plugins
|
|
13
14
|
*/
|
|
14
15
|
extendPlugins?: 'markdown' | 'astroDefaults' | false;
|
|
16
|
+
remarkRehype?: RemarkRehypeOptions;
|
|
15
17
|
};
|
|
16
18
|
export default function mdx(mdxOptions?: MdxOptions): AstroIntegration;
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,13 @@ function mdx(mdxOptions = {}) {
|
|
|
34
34
|
);
|
|
35
35
|
console.info(`See "extendPlugins" option to configure this behavior.`);
|
|
36
36
|
}
|
|
37
|
+
let remarkRehypeOptions = mdxOptions.remarkRehype;
|
|
38
|
+
if (mdxOptions.extendPlugins === "markdown") {
|
|
39
|
+
remarkRehypeOptions = {
|
|
40
|
+
...config.markdown.remarkRehype,
|
|
41
|
+
...remarkRehypeOptions
|
|
42
|
+
};
|
|
43
|
+
}
|
|
37
44
|
const mdxPluginOpts = {
|
|
38
45
|
remarkPlugins: await getRemarkPlugins(mdxOptions, config),
|
|
39
46
|
rehypePlugins: getRehypePlugins(mdxOptions, config),
|
|
@@ -41,7 +48,8 @@ function mdx(mdxOptions = {}) {
|
|
|
41
48
|
jsx: true,
|
|
42
49
|
jsxImportSource: "astro",
|
|
43
50
|
format: "mdx",
|
|
44
|
-
mdExtensions: []
|
|
51
|
+
mdExtensions: [],
|
|
52
|
+
remarkRehypeOptions
|
|
45
53
|
};
|
|
46
54
|
let importMetaEnv = {
|
|
47
55
|
SITE: config.site
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/mdx",
|
|
3
3
|
"description": "Use MDX within Astro",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@types/github-slugger": "^1.3.0",
|
|
47
47
|
"@types/mocha": "^9.1.1",
|
|
48
48
|
"@types/yargs-parser": "^21.0.0",
|
|
49
|
-
"astro": "1.6.
|
|
49
|
+
"astro": "1.6.11",
|
|
50
50
|
"astro-scripts": "0.0.9",
|
|
51
51
|
"chai": "^4.3.6",
|
|
52
52
|
"cheerio": "^1.0.0-rc.11",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"mocha": "^9.2.2",
|
|
57
57
|
"reading-time": "^1.5.0",
|
|
58
58
|
"rehype-pretty-code": "^0.4.0",
|
|
59
|
+
"remark-rehype": "^10.1.0",
|
|
59
60
|
"remark-shiki-twoslash": "^3.1.0",
|
|
60
61
|
"remark-toc": "^8.0.1",
|
|
61
62
|
"vite": "^3.0.0"
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { AstroIntegration } from 'astro';
|
|
|
5
5
|
import { parse as parseESM } from 'es-module-lexer';
|
|
6
6
|
import { blue, bold } from 'kleur/colors';
|
|
7
7
|
import fs from 'node:fs/promises';
|
|
8
|
+
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
8
9
|
import { VFile } from 'vfile';
|
|
9
10
|
import type { Plugin as VitePlugin } from 'vite';
|
|
10
11
|
import {
|
|
@@ -33,6 +34,7 @@ export type MdxOptions = {
|
|
|
33
34
|
* - false - do not inherit any plugins
|
|
34
35
|
*/
|
|
35
36
|
extendPlugins?: 'markdown' | 'astroDefaults' | false;
|
|
37
|
+
remarkRehype?: RemarkRehypeOptions;
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
|
|
@@ -62,6 +64,15 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
|
|
|
62
64
|
console.info(`See "extendPlugins" option to configure this behavior.`);
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
let remarkRehypeOptions = mdxOptions.remarkRehype;
|
|
68
|
+
|
|
69
|
+
if (mdxOptions.extendPlugins === 'markdown') {
|
|
70
|
+
remarkRehypeOptions = {
|
|
71
|
+
...config.markdown.remarkRehype,
|
|
72
|
+
...remarkRehypeOptions,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
65
76
|
const mdxPluginOpts: MdxRollupPluginOptions = {
|
|
66
77
|
remarkPlugins: await getRemarkPlugins(mdxOptions, config),
|
|
67
78
|
rehypePlugins: getRehypePlugins(mdxOptions, config),
|
|
@@ -71,6 +82,7 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
|
|
|
71
82
|
// Note: disable `.md` (and other alternative extensions for markdown files like `.markdown`) support
|
|
72
83
|
format: 'mdx',
|
|
73
84
|
mdExtensions: [],
|
|
85
|
+
remarkRehypeOptions,
|
|
74
86
|
};
|
|
75
87
|
|
|
76
88
|
let importMetaEnv: Record<string, any> = {
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
});
|