@astrojs/mdx 0.15.1 → 0.16.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.
@@ -1,5 +1,5 @@
1
- @astrojs/mdx:build: cache hit, replaying output 86781ef119fbfda9
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.15.1 build /home/runner/work/astro/astro/packages/integrations/mdx
4
- @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
- @astrojs/mdx:build: 
1
+ @astrojs/mdx:build: cache hit, replaying output 2e9264d0ca51149a
2
+ @astrojs/mdx:build: 
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.16.0 build /home/runner/work/astro/astro/packages/integrations/mdx
4
+ @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
+ @astrojs/mdx:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#6050](https://github.com/withastro/astro/pull/6050) [`2ab32b59e`](https://github.com/withastro/astro/commit/2ab32b59ef0a28d34757f2c2adb9cf2baa86855e) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix: load syntax highlighters after MDX remark plugins. This keeps MDX consistent with Astro's markdown behavior.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#6062](https://github.com/withastro/astro/pull/6062) [`c6cf847bd`](https://github.com/withastro/astro/commit/c6cf847bd0b6bef3c51a5710fba5ca43b11e46f9) Thanks [@delucis](https://github.com/delucis)! - Update MDX README
12
+
13
+ ## 0.15.2
14
+
15
+ ### Patch Changes
16
+
17
+ - [#5478](https://github.com/withastro/astro/pull/5478) [`1c7eef308`](https://github.com/withastro/astro/commit/1c7eef308e808aa5ed4662b53e67ec8d1b814d1f) Thanks [@nemo0](https://github.com/nemo0)! - Update READMEs for consistency
18
+
3
19
  ## 0.15.1
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -42,9 +42,9 @@ npm install @astrojs/mdx
42
42
 
43
43
  Then, apply this integration to your `astro.config.*` file using the `integrations` property:
44
44
 
45
- **`astro.config.mjs`**
45
+ __`astro.config.mjs`__
46
46
 
47
- ```js
47
+ ```js ins={2} "mdx()"
48
48
  import { defineConfig } from 'astro/config';
49
49
  import mdx from '@astrojs/mdx';
50
50
 
@@ -92,8 +92,9 @@ All [`markdown` configuration options](https://docs.astro.build/en/reference/con
92
92
  There is no separate MDX configuration for [including pages marked as draft in the build](https://docs.astro.build/en/reference/configuration-reference/#markdowndrafts). This Markdown setting will be respected by both Markdown and MDX files and cannot be overridden for MDX files specifically.
93
93
  :::
94
94
 
95
- ```ts
96
- // astro.config.mjs
95
+ __`astro.config.mjs`__
96
+
97
+ ```js
97
98
  import { defineConfig } from 'astro/config';
98
99
  import mdx from '@astrojs/mdx';
99
100
  import remarkToc from 'remark-toc';
@@ -128,8 +129,9 @@ MDX will extend [your project's existing Markdown configuration](https://docs.as
128
129
 
129
130
  For example, say you need to disable GitHub-Flavored Markdown and apply a different set of remark plugins for MDX files. You can apply these options like so, with `extendMarkdownConfig` enabled by default:
130
131
 
131
- ```ts
132
- // astro.config.mjs
132
+ __`astro.config.mjs`__
133
+
134
+ ```js
133
135
  import { defineConfig } from 'astro/config';
134
136
  import mdx from '@astrojs/mdx';
135
137
 
@@ -155,8 +157,9 @@ export default defineConfig({
155
157
 
156
158
  You may also need to disable `markdown` config extension in MDX. For this, set `extendMarkdownConfig` to `false`:
157
159
 
158
- ```ts
159
- // astro.config.mjs
160
+ __`astro.config.mjs`__
161
+
162
+ ```js
160
163
  import { defineConfig } from 'astro/config';
161
164
  import mdx from '@astrojs/mdx';
162
165
 
package/dist/plugins.js CHANGED
@@ -98,12 +98,6 @@ function toRemarkContentRelImageError({ srcDir }) {
98
98
  }
99
99
  async function getRemarkPlugins(mdxOptions, config) {
100
100
  let remarkPlugins = [];
101
- if (mdxOptions.syntaxHighlight === "shiki") {
102
- remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]);
103
- }
104
- if (mdxOptions.syntaxHighlight === "prism") {
105
- remarkPlugins.push(remarkPrism);
106
- }
107
101
  if (mdxOptions.gfm) {
108
102
  remarkPlugins.push(remarkGfm);
109
103
  }
@@ -111,6 +105,12 @@ async function getRemarkPlugins(mdxOptions, config) {
111
105
  remarkPlugins.push(remarkSmartypants);
112
106
  }
113
107
  remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)];
108
+ if (mdxOptions.syntaxHighlight === "shiki") {
109
+ remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]);
110
+ }
111
+ if (mdxOptions.syntaxHighlight === "prism") {
112
+ remarkPlugins.push(remarkPrism);
113
+ }
114
114
  remarkPlugins.push(toRemarkContentRelImageError(config));
115
115
  return remarkPlugins;
116
116
  }
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.15.1",
4
+ "version": "0.16.0",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -48,7 +48,7 @@
48
48
  "@types/mdast": "^3.0.10",
49
49
  "@types/mocha": "^9.1.1",
50
50
  "@types/yargs-parser": "^21.0.0",
51
- "astro": "2.0.2",
51
+ "astro": "2.0.5",
52
52
  "astro-scripts": "0.0.10",
53
53
  "chai": "^4.3.6",
54
54
  "cheerio": "^1.0.0-rc.11",
package/src/plugins.ts CHANGED
@@ -129,12 +129,7 @@ export async function getRemarkPlugins(
129
129
  config: AstroConfig
130
130
  ): Promise<MdxRollupPluginOptions['remarkPlugins']> {
131
131
  let remarkPlugins: PluggableList = [];
132
- if (mdxOptions.syntaxHighlight === 'shiki') {
133
- remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]);
134
- }
135
- if (mdxOptions.syntaxHighlight === 'prism') {
136
- remarkPlugins.push(remarkPrism);
137
- }
132
+
138
133
  if (mdxOptions.gfm) {
139
134
  remarkPlugins.push(remarkGfm);
140
135
  }
@@ -144,6 +139,14 @@ export async function getRemarkPlugins(
144
139
 
145
140
  remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)];
146
141
 
142
+ // Apply syntax highlighters after user plugins to match `markdown/remark` behavior
143
+ if (mdxOptions.syntaxHighlight === 'shiki') {
144
+ remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]);
145
+ }
146
+ if (mdxOptions.syntaxHighlight === 'prism') {
147
+ remarkPlugins.push(remarkPrism);
148
+ }
149
+
147
150
  // Apply last in case user plugins resolve relative image paths
148
151
  remarkPlugins.push(toRemarkContentRelImageError(config));
149
152
 
@@ -0,0 +1,33 @@
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('Head injection w/ MDX', () => {
8
+ let fixture;
9
+
10
+ before(async () => {
11
+ fixture = await loadFixture({
12
+ root: new URL('./fixtures/css-head-mdx/', import.meta.url),
13
+ integrations: [mdx()],
14
+ });
15
+ });
16
+
17
+ describe('build', () => {
18
+ before(async () => {
19
+ await fixture.build();
20
+ });
21
+
22
+ it('only injects contents into head', async () => {
23
+ const html = await fixture.readFile('/indexThree/index.html');
24
+ const { document } = parseHTML(html);
25
+
26
+ const links = document.querySelectorAll('link[rel=stylesheet]');
27
+ expect(links).to.have.a.lengthOf(1);
28
+
29
+ const scripts = document.querySelectorAll('script[type=module]');
30
+ expect(scripts).to.have.a.lengthOf(1);
31
+ });
32
+ });
33
+ });
@@ -0,0 +1,11 @@
1
+ ---
2
+ ---
3
+
4
+ <h3>Hello world!!</h3>
5
+ <slot />
6
+
7
+ <style>h3 { color: red }</style>
8
+
9
+ <script>
10
+ console.log('hellooooo')
11
+ </script>
@@ -0,0 +1,15 @@
1
+ ---
2
+ ---
3
+
4
+ <html lang="en">
5
+ <head>
6
+ <meta charset="utf-8" />
7
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
8
+ <meta name="viewport" content="width=device-width" />
9
+ <meta name="generator" content={Astro.generator} />
10
+ <title>Astro</title>
11
+ </head>
12
+ <body>
13
+ <slot />
14
+ </body>
15
+ </html>
@@ -0,0 +1,6 @@
1
+ ---
2
+ import Two from './Two.astro'
3
+ ---
4
+ <Two>
5
+ <slot />
6
+ </Two>
@@ -0,0 +1,6 @@
1
+ ---
2
+ import One from './One.astro'
3
+ ---
4
+ <One>
5
+ <slot />
6
+ </One>
@@ -0,0 +1,10 @@
1
+ ---
2
+ import One from '../layouts/One.astro'
3
+
4
+ import { Content } from '../test.mdx'
5
+ ---
6
+
7
+ <One>
8
+ <h1>Astro</h1>
9
+ <Content />
10
+ </One>
@@ -0,0 +1,10 @@
1
+ ---
2
+ import Three from '../layouts/Three.astro'
3
+
4
+ import { Content } from '../test.mdx'
5
+ ---
6
+
7
+ <Three>
8
+ <h1>Astro</h1>
9
+ <Content />
10
+ </Three>
@@ -0,0 +1,10 @@
1
+ ---
2
+ import Two from '../layouts/Two.astro'
3
+
4
+ import { Content } from '../test.mdx'
5
+ ---
6
+
7
+ <Two>
8
+ <h1>Astro</h1>
9
+ <Content />
10
+ </Two>
@@ -0,0 +1,15 @@
1
+ ---
2
+ layout: '../layouts/One.astro'
3
+ title: "hello world"
4
+ publishDate: "2023-01-01"
5
+ ---
6
+
7
+ import HelloWorld from '../components/HelloWorld.astro';
8
+
9
+ # Test
10
+
11
+ 123
12
+
13
+ <HelloWorld />
14
+
15
+ 456
@@ -0,0 +1,15 @@
1
+ ---
2
+ layout: '../layouts/Three.astro'
3
+ title: "hello world"
4
+ publishDate: "2023-01-01"
5
+ ---
6
+
7
+ import HelloWorld from '../components/HelloWorld.astro';
8
+
9
+ # Test
10
+
11
+ 123
12
+
13
+ <HelloWorld />
14
+
15
+ 456
@@ -0,0 +1,15 @@
1
+ ---
2
+ layout: '../layouts/Two.astro'
3
+ title: "hello world"
4
+ publishDate: "2023-01-01"
5
+ ---
6
+
7
+ import HelloWorld from '../components/HelloWorld.astro';
8
+
9
+ # Test
10
+
11
+ 123
12
+
13
+ <HelloWorld />
14
+
15
+ 456
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: "hello world"
3
+ publishDate: "2023-01-01"
4
+ ---
5
+
6
+ import HelloWorld from './components/HelloWorld.astro';
7
+
8
+ # Test
9
+
10
+ 123
11
+
12
+ <HelloWorld />
13
+
14
+ 456