@astrojs/mdx 0.15.0-beta.1 → 0.15.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 60f6ddcdbc2ddb72
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.15.0-beta.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 40b26ab265cd4f96
2
+ @astrojs/mdx:build: 
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.15.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,7 +1,148 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#5684](https://github.com/withastro/astro/pull/5684) [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Refine Markdown and MDX configuration options for ease-of-use. & [#5769](https://github.com/withastro/astro/pull/5769) [`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Introduce a `smartypants` flag to opt-out of Astro's default SmartyPants plugin.
8
+
9
+ - **Markdown**
10
+
11
+ - **Replace the `extendDefaultPlugins` option** with a `gfm` boolean and a `smartypants` boolean. These are enabled by default, and can be disabled to remove GitHub-Flavored Markdown and SmartyPants.
12
+
13
+ - Ensure GitHub-Flavored Markdown and SmartyPants are applied whether or not custom `remarkPlugins` or `rehypePlugins` are configured. If you want to apply custom plugins _and_ remove Astro's default plugins, manually set `gfm: false` and `smartypants: false` in your config.
14
+
15
+ - **Migrate `extendDefaultPlugins` to `gfm` and `smartypants`**
16
+
17
+ You may have disabled Astro's built-in plugins (GitHub-Flavored Markdown and Smartypants) with the `extendDefaultPlugins` option. This has now been split into 2 flags to disable each plugin individually:
18
+
19
+ - `markdown.gfm` to disable GitHub-Flavored Markdown
20
+ - `markdown.smartypants` to disable SmartyPants
21
+
22
+ ```diff
23
+ // astro.config.mjs
24
+ import { defineConfig } from 'astro/config';
25
+
26
+ export default defineConfig({
27
+ markdown: {
28
+ - extendDefaultPlugins: false,
29
+ + smartypants: false,
30
+ + gfm: false,
31
+ }
32
+ });
33
+ ```
34
+
35
+ Additionally, applying remark and rehype plugins **no longer disables** `gfm` and `smartypants`. You will need to opt-out manually by setting `gfm` and `smartypants` to `false`.
36
+
37
+ - **MDX**
38
+
39
+ - Support _all_ Markdown configuration options (except `drafts`) from your MDX integration config. This includes `syntaxHighlighting` and `shikiConfig` options to further customize the MDX renderer.
40
+
41
+ - Simplify `extendPlugins` to an `extendMarkdownConfig` option. MDX options will default to their equivalent in your Markdown config. By setting `extendMarkdownConfig` to false, you can "eject" to set your own syntax highlighting, plugins, and more.
42
+
43
+ - **Migrate MDX's `extendPlugins` to `extendMarkdownConfig`**
44
+
45
+ You may have used the `extendPlugins` option to manage plugin defaults in MDX. This has been replaced by 3 flags:
46
+
47
+ - `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
48
+ - `gfm` (`true` by default) and `smartypants` (`true` by default) to toggle GitHub-Flavored Markdown and SmartyPants in MDX. This replaces the `extendPlugins: 'defaults'` option.
49
+
50
+
51
+
52
+ - [#5687](https://github.com/withastro/astro/pull/5687) [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Give remark and rehype plugins access to user frontmatter via frontmatter injection. This means `data.astro.frontmatter` is now the _complete_ Markdown or MDX document's frontmatter, rather than an empty object.
53
+
54
+ This allows plugin authors to modify existing frontmatter, or compute new properties based on other properties. For example, say you want to compute a full image URL based on an `imageSrc` slug in your document frontmatter:
55
+
56
+ ```ts
57
+ export function remarkInjectSocialImagePlugin() {
58
+ return function (tree, file) {
59
+ const { frontmatter } = file.data.astro;
60
+ frontmatter.socialImageSrc = new URL(frontmatter.imageSrc, 'https://my-blog.com/').pathname;
61
+ };
62
+ }
63
+ ```
64
+
65
+ When using Content Collections, you can access this modified frontmatter using the `remarkPluginFrontmatter` property returned when rendering an entry.
66
+
67
+ **Migration instructions**
68
+
69
+ Plugin authors should now **check for user frontmatter when applying defaults.**
70
+
71
+ For example, say a remark plugin wants to apply a default `title` if none is present. Add a conditional to check if the property is present, and update if none exists:
72
+
73
+ ```diff
74
+ export function remarkInjectTitlePlugin() {
75
+ return function (tree, file) {
76
+ const { frontmatter } = file.data.astro;
77
+ + if (!frontmatter.title) {
78
+ frontmatter.title = 'Default title';
79
+ + }
80
+ }
81
+ }
82
+ ```
83
+
84
+ This differs from previous behavior, where a Markdown file's frontmatter would _always_ override frontmatter injected via remark or reype.
85
+
86
+ - [#5891](https://github.com/withastro/astro/pull/5891) [`05caf445d`](https://github.com/withastro/astro/commit/05caf445d4d2728f1010aeb2179a9e756c2fd17d) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Remove deprecated Markdown APIs from Astro v0.X. This includes `getHeaders()`, the `.astro` property for layouts, and the `rawContent()` and `compiledContent()` error messages for MDX.
87
+
88
+ - [#5782](https://github.com/withastro/astro/pull/5782) [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Remove support for Node 14. Minimum supported Node version is now >=16.12.0
89
+
90
+ - [#5825](https://github.com/withastro/astro/pull/5825) [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Baseline the experimental `contentCollections` flag. You're free to remove this from your astro config!
91
+
92
+ ```diff
93
+ import { defineConfig } from 'astro/config';
94
+
95
+ export default defineConfig({
96
+ - experimental: { contentCollections: true }
97
+ })
98
+ ```
99
+
100
+ ### Patch Changes
101
+
102
+ - [#5837](https://github.com/withastro/astro/pull/5837) [`12f65a4d5`](https://github.com/withastro/astro/commit/12f65a4d55e3fd2993c2f67b18794dd536280c69) Thanks [@giuseppelt](https://github.com/giuseppelt)! - fix shiki css class replace logic
103
+
104
+ - [#5741](https://github.com/withastro/astro/pull/5741) [`000d3e694`](https://github.com/withastro/astro/commit/000d3e6940839c2aebba1984e6fb3b133cec6749) Thanks [@delucis](https://github.com/delucis)! - Fix broken links in README
105
+
106
+ - Updated dependencies [[`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b), [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a), [`12f65a4d5`](https://github.com/withastro/astro/commit/12f65a4d55e3fd2993c2f67b18794dd536280c69), [`16107b6a1`](https://github.com/withastro/astro/commit/16107b6a10514ef1b563e585ec9add4b14f42b94), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d), [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f), [`7572f7402`](https://github.com/withastro/astro/commit/7572f7402238da37de748be58d678fedaf863b53)]:
107
+ - @astrojs/markdown-remark@2.0.0
108
+ - @astrojs/prism@2.0.0
109
+
110
+ ## 1.0.0-beta.2
111
+
112
+ <details>
113
+ <summary>See changes in 1.0.0-beta.2</summary>
114
+
115
+ ### Major Changes
116
+
117
+ - [#5825](https://github.com/withastro/astro/pull/5825) [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Baseline the experimental `contentCollections` flag. You're free to remove this from your astro config!
118
+
119
+ ```diff
120
+ import { defineConfig } from 'astro/config';
121
+
122
+ export default defineConfig({
123
+ - experimental: { contentCollections: true }
124
+ })
125
+ ```
126
+
127
+ ### Minor Changes
128
+
129
+ - [#5782](https://github.com/withastro/astro/pull/5782) [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Remove support for Node 14. Minimum supported Node version is now >=16.12.0
130
+
131
+ ### Patch Changes
132
+
133
+ - [#5837](https://github.com/withastro/astro/pull/5837) [`12f65a4d5`](https://github.com/withastro/astro/commit/12f65a4d55e3fd2993c2f67b18794dd536280c69) Thanks [@giuseppelt](https://github.com/giuseppelt)! - fix shiki css class replace logic
134
+
135
+ - Updated dependencies [[`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a), [`12f65a4d5`](https://github.com/withastro/astro/commit/12f65a4d55e3fd2993c2f67b18794dd536280c69), [`16107b6a1`](https://github.com/withastro/astro/commit/16107b6a10514ef1b563e585ec9add4b14f42b94), [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f), [`7572f7402`](https://github.com/withastro/astro/commit/7572f7402238da37de748be58d678fedaf863b53)]:
136
+ - @astrojs/prism@2.0.0-beta.0
137
+ - @astrojs/markdown-remark@2.0.0-beta.2
138
+
139
+ </details>
140
+
3
141
  ## 0.15.0-beta.1
4
142
 
143
+ <details>
144
+ <summary>See changes in 0.15.0-beta.1</summary>
145
+
5
146
  ### Minor Changes
6
147
 
7
148
  - [#5769](https://github.com/withastro/astro/pull/5769) [`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Introduce a `smartypants` flag to opt-out of Astro's default SmartyPants plugin.
@@ -41,8 +182,13 @@
41
182
  - Updated dependencies [[`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b)]:
42
183
  - @astrojs/markdown-remark@2.0.0-beta.1
43
184
 
185
+ </details>
186
+
44
187
  ## 0.15.0-beta.0
45
188
 
189
+ <details>
190
+ <summary>See changes in 0.15.0-beta.0</summary>
191
+
46
192
  ### Minor Changes
47
193
 
48
194
  - [#5687](https://github.com/withastro/astro/pull/5687) [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Give remark and rehype plugins access to user frontmatter via frontmatter injection. This means `data.astro.frontmatter` is now the _complete_ Markdown or MDX document's frontmatter, rather than an empty object.
@@ -146,6 +292,8 @@
146
292
  - Updated dependencies [[`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d)]:
147
293
  - @astrojs/markdown-remark@2.0.0-beta.0
148
294
 
295
+ </details>
296
+
149
297
  ## 0.14.0
150
298
 
151
299
  ### Minor Changes
package/dist/index.js CHANGED
@@ -7,8 +7,6 @@ import fs from "node:fs/promises";
7
7
  import { VFile } from "vfile";
8
8
  import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from "./plugins.js";
9
9
  import { getFileInfo, parseFrontmatter } from "./utils.js";
10
- const RAW_CONTENT_ERROR = "MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins";
11
- const COMPILED_CONTENT_ERROR = "MDX does not support compiledContent()! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins";
12
10
  function mdx(partialMdxOptions = {}) {
13
11
  return {
14
12
  name: "@astrojs/mdx",
@@ -87,18 +85,6 @@ export const url = ${JSON.stringify(fileUrl)};`;
87
85
  code += `
88
86
  export const file = ${JSON.stringify(fileId)};`;
89
87
  }
90
- if (!moduleExports.includes("rawContent")) {
91
- code += `
92
- export function rawContent() { throw new Error(${JSON.stringify(
93
- RAW_CONTENT_ERROR
94
- )}) };`;
95
- }
96
- if (!moduleExports.includes("compiledContent")) {
97
- code += `
98
- export function compiledContent() { throw new Error(${JSON.stringify(
99
- COMPILED_CONTENT_ERROR
100
- )}) };`;
101
- }
102
88
  if (!moduleExports.includes("Content")) {
103
89
  code = code.replace("export default MDXContent;", "");
104
90
  code += `
package/dist/plugins.js CHANGED
@@ -59,22 +59,6 @@ function rehypeApplyFrontmatterExport() {
59
59
  const { layout, ...content } = frontmatter;
60
60
  content.file = file;
61
61
  content.url = url;
62
- content.astro = {};
63
- Object.defineProperty(content.astro, 'headings', {
64
- get() {
65
- throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."')
66
- }
67
- });
68
- Object.defineProperty(content.astro, 'html', {
69
- get() {
70
- throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."')
71
- }
72
- });
73
- Object.defineProperty(content.astro, 'source', {
74
- get() {
75
- throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."')
76
- }
77
- });
78
62
  return layoutJsx(Layout, {
79
63
  file,
80
64
  url,
@@ -127,9 +111,7 @@ async function getRemarkPlugins(mdxOptions, config) {
127
111
  remarkPlugins.push(remarkSmartypants);
128
112
  }
129
113
  remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)];
130
- if (config.experimental.contentCollections) {
131
- remarkPlugins.push(toRemarkContentRelImageError(config));
132
- }
114
+ remarkPlugins.push(toRemarkContentRelImageError(config));
133
115
  return remarkPlugins;
134
116
  }
135
117
  function getRehypePlugins(mdxOptions) {
@@ -42,7 +42,7 @@ const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false })
42
42
  lang = "plaintext";
43
43
  }
44
44
  let html = highlighter.codeToHtml(node.value, { lang });
45
- html = html.replace('<pre class="shiki"', `<pre class="astro-code"`);
45
+ html = html.replace(/<pre class="(.*?)shiki(.*?)"/, `<pre class="$1astro-code$2"`);
46
46
  if (node.lang === "diff") {
47
47
  html = html.replace(
48
48
  /<span class="line"><span style="(.*?)">([\+|\-])/g,
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.0-beta.1",
4
+ "version": "0.15.0",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -23,8 +23,8 @@
23
23
  "./package.json": "./package.json"
24
24
  },
25
25
  "dependencies": {
26
- "@astrojs/markdown-remark": "^2.0.0-beta.1",
27
- "@astrojs/prism": "^1.0.2",
26
+ "@astrojs/markdown-remark": "^2.0.0",
27
+ "@astrojs/prism": "^2.0.0",
28
28
  "@mdx-js/mdx": "^2.1.2",
29
29
  "@mdx-js/rollup": "^2.1.1",
30
30
  "acorn": "^8.8.0",
@@ -48,8 +48,8 @@
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.0-beta.1",
52
- "astro-scripts": "0.0.9",
51
+ "astro": "2.0.0",
52
+ "astro-scripts": "0.0.10",
53
53
  "chai": "^4.3.6",
54
54
  "cheerio": "^1.0.0-rc.11",
55
55
  "linkedom": "^0.14.12",
@@ -64,7 +64,7 @@
64
64
  "vite": "^4.0.3"
65
65
  },
66
66
  "engines": {
67
- "node": "^14.18.0 || >=16.12.0"
67
+ "node": ">=16.12.0"
68
68
  },
69
69
  "scripts": {
70
70
  "build": "astro-scripts build \"src/**/*.ts\" && tsc",
package/src/index.ts CHANGED
@@ -12,12 +12,6 @@ import type { Plugin as VitePlugin } from 'vite';
12
12
  import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js';
13
13
  import { getFileInfo, parseFrontmatter } from './utils.js';
14
14
 
15
- const RAW_CONTENT_ERROR =
16
- 'MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins';
17
-
18
- const COMPILED_CONTENT_ERROR =
19
- 'MDX does not support compiledContent()! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins';
20
-
21
15
  export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | 'rehypePlugins'> & {
22
16
  extendMarkdownConfig: boolean;
23
17
  recmaPlugins: PluggableList;
@@ -123,16 +117,6 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
123
117
  if (!moduleExports.includes('file')) {
124
118
  code += `\nexport const file = ${JSON.stringify(fileId)};`;
125
119
  }
126
- if (!moduleExports.includes('rawContent')) {
127
- code += `\nexport function rawContent() { throw new Error(${JSON.stringify(
128
- RAW_CONTENT_ERROR
129
- )}) };`;
130
- }
131
- if (!moduleExports.includes('compiledContent')) {
132
- code += `\nexport function compiledContent() { throw new Error(${JSON.stringify(
133
- COMPILED_CONTENT_ERROR
134
- )}) };`;
135
- }
136
120
  if (!moduleExports.includes('Content')) {
137
121
  // Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment`
138
122
  code = code.replace('export default MDXContent;', '');
package/src/plugins.ts CHANGED
@@ -79,22 +79,6 @@ export function rehypeApplyFrontmatterExport() {
79
79
  const { layout, ...content } = frontmatter;
80
80
  content.file = file;
81
81
  content.url = url;
82
- content.astro = {};
83
- Object.defineProperty(content.astro, 'headings', {
84
- get() {
85
- throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."')
86
- }
87
- });
88
- Object.defineProperty(content.astro, 'html', {
89
- get() {
90
- throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."')
91
- }
92
- });
93
- Object.defineProperty(content.astro, 'source', {
94
- get() {
95
- throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."')
96
- }
97
- });
98
82
  return layoutJsx(Layout, {
99
83
  file,
100
84
  url,
@@ -161,9 +145,8 @@ export async function getRemarkPlugins(
161
145
  remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)];
162
146
 
163
147
  // Apply last in case user plugins resolve relative image paths
164
- if (config.experimental.contentCollections) {
165
- remarkPlugins.push(toRemarkContentRelImageError(config));
166
- }
148
+ remarkPlugins.push(toRemarkContentRelImageError(config));
149
+
167
150
  return remarkPlugins;
168
151
  }
169
152
 
@@ -66,7 +66,7 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
66
66
  // &lt;span class=&quot;line&quot;
67
67
 
68
68
  // Replace "shiki" class naming with "astro".
69
- html = html.replace('<pre class="shiki"', `<pre class="astro-code"`);
69
+ html = html.replace(/<pre class="(.*?)shiki(.*?)"/, `<pre class="$1astro-code$2"`);
70
70
  // Add "user-select: none;" for "+"/"-" diff symbols
71
71
  if (node.lang === 'diff') {
72
72
  html = html.replace(