@astrojs/mdx 0.15.0-beta.1 → 0.15.1

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
1
+ @astrojs/mdx:build: cache hit, replaying output 86781ef119fbfda9
2
2
  @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.15.0-beta.1 build /home/runner/work/astro/astro/packages/integrations/mdx
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.15.1 build /home/runner/work/astro/astro/packages/integrations/mdx
4
4
  @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
5
  @astrojs/mdx:build: 
package/CHANGELOG.md CHANGED
@@ -1,7 +1,155 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.15.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#5978](https://github.com/withastro/astro/pull/5978) [`7abb1e905`](https://github.com/withastro/astro/commit/7abb1e9056c4b4fd0abfced347df32a41cdfbf28) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fix MDX heading IDs generation when using a frontmatter reference
8
+
9
+ - Updated dependencies [[`7abb1e905`](https://github.com/withastro/astro/commit/7abb1e9056c4b4fd0abfced347df32a41cdfbf28)]:
10
+ - @astrojs/markdown-remark@2.0.1
11
+
12
+ ## 0.15.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#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.
17
+
18
+ - **Markdown**
19
+
20
+ - **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.
21
+
22
+ - 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.
23
+
24
+ - **Migrate `extendDefaultPlugins` to `gfm` and `smartypants`**
25
+
26
+ 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:
27
+
28
+ - `markdown.gfm` to disable GitHub-Flavored Markdown
29
+ - `markdown.smartypants` to disable SmartyPants
30
+
31
+ ```diff
32
+ // astro.config.mjs
33
+ import { defineConfig } from 'astro/config';
34
+
35
+ export default defineConfig({
36
+ markdown: {
37
+ - extendDefaultPlugins: false,
38
+ + smartypants: false,
39
+ + gfm: false,
40
+ }
41
+ });
42
+ ```
43
+
44
+ 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`.
45
+
46
+ - **MDX**
47
+
48
+ - Support _all_ Markdown configuration options (except `drafts`) from your MDX integration config. This includes `syntaxHighlighting` and `shikiConfig` options to further customize the MDX renderer.
49
+
50
+ - 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.
51
+
52
+ - **Migrate MDX's `extendPlugins` to `extendMarkdownConfig`**
53
+
54
+ You may have used the `extendPlugins` option to manage plugin defaults in MDX. This has been replaced by 3 flags:
55
+
56
+ - `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
57
+ - `gfm` (`true` by default) and `smartypants` (`true` by default) to toggle GitHub-Flavored Markdown and SmartyPants in MDX. This replaces the `extendPlugins: 'defaults'` option.
58
+
59
+ - [#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.
60
+
61
+ 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:
62
+
63
+ ```ts
64
+ export function remarkInjectSocialImagePlugin() {
65
+ return function (tree, file) {
66
+ const { frontmatter } = file.data.astro;
67
+ frontmatter.socialImageSrc = new URL(frontmatter.imageSrc, 'https://my-blog.com/').pathname;
68
+ };
69
+ }
70
+ ```
71
+
72
+ When using Content Collections, you can access this modified frontmatter using the `remarkPluginFrontmatter` property returned when rendering an entry.
73
+
74
+ **Migration instructions**
75
+
76
+ Plugin authors should now **check for user frontmatter when applying defaults.**
77
+
78
+ 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:
79
+
80
+ ```diff
81
+ export function remarkInjectTitlePlugin() {
82
+ return function (tree, file) {
83
+ const { frontmatter } = file.data.astro;
84
+ + if (!frontmatter.title) {
85
+ frontmatter.title = 'Default title';
86
+ + }
87
+ }
88
+ }
89
+ ```
90
+
91
+ This differs from previous behavior, where a Markdown file's frontmatter would _always_ override frontmatter injected via remark or reype.
92
+
93
+ - [#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.
94
+
95
+ - [#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
96
+
97
+ - [#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!
98
+
99
+ ```diff
100
+ import { defineConfig } from 'astro/config';
101
+
102
+ export default defineConfig({
103
+ - experimental: { contentCollections: true }
104
+ })
105
+ ```
106
+
107
+ ### Patch Changes
108
+
109
+ - [#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
110
+
111
+ - [#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
112
+
113
+ - 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)]:
114
+ - @astrojs/markdown-remark@2.0.0
115
+ - @astrojs/prism@2.0.0
116
+
117
+ ## 1.0.0-beta.2
118
+
119
+ <details>
120
+ <summary>See changes in 1.0.0-beta.2</summary>
121
+
122
+ ### Major Changes
123
+
124
+ - [#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!
125
+
126
+ ```diff
127
+ import { defineConfig } from 'astro/config';
128
+
129
+ export default defineConfig({
130
+ - experimental: { contentCollections: true }
131
+ })
132
+ ```
133
+
134
+ ### Minor Changes
135
+
136
+ - [#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
137
+
138
+ ### Patch Changes
139
+
140
+ - [#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
141
+
142
+ - 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)]:
143
+ - @astrojs/prism@2.0.0-beta.0
144
+ - @astrojs/markdown-remark@2.0.0-beta.2
145
+
146
+ </details>
147
+
3
148
  ## 0.15.0-beta.1
4
149
 
150
+ <details>
151
+ <summary>See changes in 0.15.0-beta.1</summary>
152
+
5
153
  ### Minor Changes
6
154
 
7
155
  - [#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 +189,13 @@
41
189
  - Updated dependencies [[`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b)]:
42
190
  - @astrojs/markdown-remark@2.0.0-beta.1
43
191
 
192
+ </details>
193
+
44
194
  ## 0.15.0-beta.0
45
195
 
196
+ <details>
197
+ <summary>See changes in 0.15.0-beta.0</summary>
198
+
46
199
  ### Minor Changes
47
200
 
48
201
  - [#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 +299,8 @@
146
299
  - Updated dependencies [[`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d)]:
147
300
  - @astrojs/markdown-remark@2.0.0-beta.0
148
301
 
302
+ </details>
303
+
149
304
  ## 0.14.0
150
305
 
151
306
  ### Minor Changes
package/README.md CHANGED
@@ -89,7 +89,7 @@ You can configure how your MDX is rendered with the following options:
89
89
  All [`markdown` configuration options](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) except `drafts` can be configured separately in the MDX integration. This includes remark and rehype plugins, syntax highlighting, and more. Options will default to those in your Markdown config ([see the `extendMarkdownConfig` option](#extendmarkdownconfig) to modify this).
90
90
 
91
91
  :::note
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 overriden for MDX files specifically.
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
95
  ```ts
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.1",
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.1",
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.2",
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(
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: The Frontmatter Title
3
+ keywords: [Keyword 1, Keyword 2, Keyword 3]
4
+ tags:
5
+ - Tag 1
6
+ - Tag 2
7
+ - Tag 3
8
+ items:
9
+ - value: Item 1
10
+ - value: Item 2
11
+ - value: Item 3
12
+ nested_items:
13
+ nested:
14
+ - value: Nested Item 1
15
+ - value: Nested Item 2
16
+ - value: Nested Item 3
17
+ ---
18
+
19
+ # {frontmatter.title}
20
+
21
+ This ID should be the frontmatter title.
22
+
23
+ ## frontmatter.title
24
+
25
+ The ID should not be the frontmatter title.
26
+
27
+ ### {frontmatter.keywords[1]}
28
+
29
+ The ID should be the frontmatter keyword #2.
30
+
31
+ ### {frontmatter.tags[0]}
32
+
33
+ The ID should be the frontmatter tag #1.
34
+
35
+ #### {frontmatter.items[1].value}
36
+
37
+ The ID should be the frontmatter item #2.
38
+
39
+ ##### {frontmatter.nested_items.nested[2].value}
40
+
41
+ The ID should be the frontmatter nested item #3.
42
+
43
+ ###### {frontmatter.unknown}
44
+
45
+ This ID should not reference the frontmatter.
@@ -149,3 +149,46 @@ describe('MDX heading IDs can be injected before user plugins', () => {
149
149
  expect(h1?.id).to.equal('heading-test');
150
150
  });
151
151
  });
152
+
153
+ describe('MDX headings with frontmatter', () => {
154
+ let fixture;
155
+
156
+ before(async () => {
157
+ fixture = await loadFixture({
158
+ root: new URL('./fixtures/mdx-get-headings/', import.meta.url),
159
+ integrations: [mdx()],
160
+ });
161
+
162
+ await fixture.build();
163
+ });
164
+
165
+ it('adds anchor IDs to headings', async () => {
166
+ const html = await fixture.readFile('/test-with-frontmatter/index.html');
167
+ const { document } = parseHTML(html);
168
+
169
+ const h3Ids = document.querySelectorAll('h3').map((el) => el?.id);
170
+
171
+ expect(document.querySelector('h1').id).to.equal('the-frontmatter-title');
172
+ expect(document.querySelector('h2').id).to.equal('frontmattertitle');
173
+ expect(h3Ids).to.contain('keyword-2');
174
+ expect(h3Ids).to.contain('tag-1');
175
+ expect(document.querySelector('h4').id).to.equal('item-2');
176
+ expect(document.querySelector('h5').id).to.equal('nested-item-3');
177
+ expect(document.querySelector('h6').id).to.equal('frontmatterunknown');
178
+ });
179
+
180
+ it('generates correct getHeadings() export', async () => {
181
+ const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
182
+ expect(JSON.stringify(headingsByPage['./test-with-frontmatter.mdx'])).to.equal(
183
+ JSON.stringify([
184
+ { depth: 1, slug: 'the-frontmatter-title', text: 'The Frontmatter Title' },
185
+ { depth: 2, slug: 'frontmattertitle', text: 'frontmatter.title' },
186
+ { depth: 3, slug: 'keyword-2', text: 'Keyword 2' },
187
+ { depth: 3, slug: 'tag-1', text: 'Tag 1' },
188
+ { depth: 4, slug: 'item-2', text: 'Item 2' },
189
+ { depth: 5, slug: 'nested-item-3', text: 'Nested Item 3' },
190
+ { depth: 6, slug: 'frontmatterunknown', text: 'frontmatter.unknown' },
191
+ ])
192
+ );
193
+ });
194
+ });