@astrojs/mdx 0.15.0-beta.0 → 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 a2df0a02dde16921
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.15.0-beta.0 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,194 @@
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
+
141
+ ## 0.15.0-beta.1
142
+
143
+ <details>
144
+ <summary>See changes in 0.15.0-beta.1</summary>
145
+
146
+ ### Minor Changes
147
+
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.
149
+
150
+ ```js
151
+ {
152
+ markdown: {
153
+ smartypants: false,
154
+ }
155
+ }
156
+ ```
157
+
158
+ #### Migration
159
+
160
+ 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:
161
+
162
+ - `markdown.gfm` to disable GitHub-Flavored Markdown
163
+ - `markdown.smartypants` to disable SmartyPants
164
+
165
+ ```diff
166
+ // astro.config.mjs
167
+ import { defineConfig } from 'astro/config';
168
+
169
+ export default defineConfig({
170
+ markdown: {
171
+ - extendDefaultPlugins: false,
172
+ + smartypants: false,
173
+ + gfm: false,
174
+ }
175
+ });
176
+ ```
177
+
178
+ ### Patch Changes
179
+
180
+ - [#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
181
+
182
+ - Updated dependencies [[`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b)]:
183
+ - @astrojs/markdown-remark@2.0.0-beta.1
184
+
185
+ </details>
186
+
3
187
  ## 0.15.0-beta.0
4
188
 
189
+ <details>
190
+ <summary>See changes in 0.15.0-beta.0</summary>
191
+
5
192
  ### Minor Changes
6
193
 
7
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.
@@ -105,6 +292,8 @@
105
292
  - Updated dependencies [[`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d)]:
106
293
  - @astrojs/markdown-remark@2.0.0-beta.0
107
294
 
295
+ </details>
296
+
108
297
  ## 0.14.0
109
298
 
110
299
  ### Minor Changes
package/README.md CHANGED
@@ -66,7 +66,7 @@ export default defineConfig({
66
66
 
67
67
  ## Usage
68
68
 
69
- With the Astro MDX integration, you can [add MDX pages to your project](/en/guides/markdown-content/#markdown-and-mdx-pages) by adding `.mdx` files within your `src/pages/` directory. You can also [import `.mdx` files](https://docs.astro.build/en/guides/markdown-content/#importing-markdown) into `.astro` files.
69
+ With the Astro MDX integration, you can [add MDX pages to your project](https://docs.astro.build/en/guides/markdown-content/#markdown-and-mdx-pages) by adding `.mdx` files within your `src/pages/` directory. You can also [import `.mdx` files](https://docs.astro.build/en/guides/markdown-content/#importing-markdown) into `.astro` files.
70
70
 
71
71
  Astro's MDX integration adds extra features to standard MDX, including Markdown-style frontmatter. This allows you to use most of Astro's built-in Markdown features like a [special frontmatter `layout` property](https://docs.astro.build/en/guides/markdown-content/#frontmatter-layout) and a [property for marking a page as a draft](https://docs.astro.build/en/guides/markdown-content/#draft-pages).
72
72
 
@@ -198,6 +198,6 @@ This package is maintained by Astro's Core team. You're welcome to submit an iss
198
198
 
199
199
  See [CHANGELOG.md](https://github.com/withastro/astro/tree/main/packages/integrations/mdx/CHANGELOG.md) for a history of changes to this integration.
200
200
 
201
- [astro-integration]: /en/guides/integrations-guide/
201
+ [astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
202
202
 
203
- [astro-ui-frameworks]: /en/core-concepts/framework-components/#using-framework-components
203
+ [astro-ui-frameworks]: https://docs.astro.build/en/core-concepts/framework-components/#using-framework-components
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 += `
@@ -144,6 +130,7 @@ function applyDefaultOptions({
144
130
  recmaPlugins: options.recmaPlugins ?? defaults.recmaPlugins,
145
131
  remarkRehype: options.remarkRehype ?? defaults.remarkRehype,
146
132
  gfm: options.gfm ?? defaults.gfm,
133
+ smartypants: options.smartypants ?? defaults.smartypants,
147
134
  remarkPlugins: options.remarkPlugins ?? defaults.remarkPlugins,
148
135
  rehypePlugins: options.rehypePlugins ?? defaults.rehypePlugins,
149
136
  shikiConfig: options.shikiConfig ?? defaults.shikiConfig
package/dist/plugins.js CHANGED
@@ -9,6 +9,7 @@ import { bold, yellow } from "kleur/colors";
9
9
  import { pathToFileURL } from "node:url";
10
10
  import rehypeRaw from "rehype-raw";
11
11
  import remarkGfm from "remark-gfm";
12
+ import remarkSmartypants from "remark-smartypants";
12
13
  import { visit } from "unist-util-visit";
13
14
  import { rehypeInjectHeadingsExport } from "./rehype-collect-headings.js";
14
15
  import rehypeMetaString from "./rehype-meta-string.js";
@@ -58,22 +59,6 @@ function rehypeApplyFrontmatterExport() {
58
59
  const { layout, ...content } = frontmatter;
59
60
  content.file = file;
60
61
  content.url = url;
61
- content.astro = {};
62
- Object.defineProperty(content.astro, 'headings', {
63
- get() {
64
- throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."')
65
- }
66
- });
67
- Object.defineProperty(content.astro, 'html', {
68
- get() {
69
- throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."')
70
- }
71
- });
72
- Object.defineProperty(content.astro, 'source', {
73
- get() {
74
- throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."')
75
- }
76
- });
77
62
  return layoutJsx(Layout, {
78
63
  file,
79
64
  url,
@@ -122,10 +107,11 @@ async function getRemarkPlugins(mdxOptions, config) {
122
107
  if (mdxOptions.gfm) {
123
108
  remarkPlugins.push(remarkGfm);
124
109
  }
125
- remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)];
126
- if (config.experimental.contentCollections) {
127
- remarkPlugins.push(toRemarkContentRelImageError(config));
110
+ if (mdxOptions.smartypants) {
111
+ remarkPlugins.push(remarkSmartypants);
128
112
  }
113
+ remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)];
114
+ remarkPlugins.push(toRemarkContentRelImageError(config));
129
115
  return remarkPlugins;
130
116
  }
131
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.0",
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.0",
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",
@@ -36,6 +36,7 @@
36
36
  "rehype-raw": "^6.1.1",
37
37
  "remark-frontmatter": "^4.0.1",
38
38
  "remark-gfm": "^3.0.1",
39
+ "remark-smartypants": "^2.0.0",
39
40
  "shiki": "^0.11.1",
40
41
  "unist-util-visit": "^4.1.0",
41
42
  "vfile": "^5.3.2"
@@ -47,8 +48,8 @@
47
48
  "@types/mdast": "^3.0.10",
48
49
  "@types/mocha": "^9.1.1",
49
50
  "@types/yargs-parser": "^21.0.0",
50
- "astro": "2.0.0-beta.0",
51
- "astro-scripts": "0.0.9",
51
+ "astro": "2.0.0",
52
+ "astro-scripts": "0.0.10",
52
53
  "chai": "^4.3.6",
53
54
  "cheerio": "^1.0.0-rc.11",
54
55
  "linkedom": "^0.14.12",
@@ -63,7 +64,7 @@
63
64
  "vite": "^4.0.3"
64
65
  },
65
66
  "engines": {
66
- "node": "^14.18.0 || >=16.12.0"
67
+ "node": ">=16.12.0"
67
68
  },
68
69
  "scripts": {
69
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;', '');
@@ -186,6 +170,7 @@ function applyDefaultOptions({
186
170
  recmaPlugins: options.recmaPlugins ?? defaults.recmaPlugins,
187
171
  remarkRehype: options.remarkRehype ?? defaults.remarkRehype,
188
172
  gfm: options.gfm ?? defaults.gfm,
173
+ smartypants: options.smartypants ?? defaults.smartypants,
189
174
  remarkPlugins: options.remarkPlugins ?? defaults.remarkPlugins,
190
175
  rehypePlugins: options.rehypePlugins ?? defaults.rehypePlugins,
191
176
  shikiConfig: options.shikiConfig ?? defaults.shikiConfig,
package/src/plugins.ts CHANGED
@@ -14,6 +14,7 @@ import type { Image } from 'mdast';
14
14
  import { pathToFileURL } from 'node:url';
15
15
  import rehypeRaw from 'rehype-raw';
16
16
  import remarkGfm from 'remark-gfm';
17
+ import remarkSmartypants from 'remark-smartypants';
17
18
  import { visit } from 'unist-util-visit';
18
19
  import type { VFile } from 'vfile';
19
20
  import { MdxOptions } from './index.js';
@@ -78,22 +79,6 @@ export function rehypeApplyFrontmatterExport() {
78
79
  const { layout, ...content } = frontmatter;
79
80
  content.file = file;
80
81
  content.url = url;
81
- content.astro = {};
82
- Object.defineProperty(content.astro, 'headings', {
83
- get() {
84
- throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."')
85
- }
86
- });
87
- Object.defineProperty(content.astro, 'html', {
88
- get() {
89
- throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."')
90
- }
91
- });
92
- Object.defineProperty(content.astro, 'source', {
93
- get() {
94
- throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."')
95
- }
96
- });
97
82
  return layoutJsx(Layout, {
98
83
  file,
99
84
  url,
@@ -153,13 +138,15 @@ export async function getRemarkPlugins(
153
138
  if (mdxOptions.gfm) {
154
139
  remarkPlugins.push(remarkGfm);
155
140
  }
141
+ if (mdxOptions.smartypants) {
142
+ remarkPlugins.push(remarkSmartypants);
143
+ }
156
144
 
157
145
  remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)];
158
146
 
159
147
  // Apply last in case user plugins resolve relative image paths
160
- if (config.experimental.contentCollections) {
161
- remarkPlugins.push(toRemarkContentRelImageError(config));
162
- }
148
+ remarkPlugins.push(toRemarkContentRelImageError(config));
149
+
163
150
  return remarkPlugins;
164
151
  }
165
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(
@@ -21,3 +21,5 @@ Oh cool, more text!
21
21
  And section 2, with a hyperlink to check GFM is preserved: https://handle-me-gfm.com
22
22
 
23
23
  <div data-recma-plugin-works={recmaPluginWorking}></div>
24
+
25
+ > "Smartypants" is -- awesome
@@ -36,6 +36,19 @@ describe('MDX plugins', () => {
36
36
  expect(selectGfmLink(document)).to.not.be.null;
37
37
  });
38
38
 
39
+ it('Applies SmartyPants by default', async () => {
40
+ const fixture = await buildFixture({
41
+ integrations: [mdx()],
42
+ });
43
+
44
+ const html = await fixture.readFile(FILE);
45
+ const { document } = parseHTML(html);
46
+
47
+ const quote = selectSmartypantsQuote(document);
48
+ expect(quote).to.not.be.null;
49
+ expect(quote.textContent).to.contain('“Smartypants” is — awesome');
50
+ });
51
+
39
52
  it('supports custom rehype plugins', async () => {
40
53
  const fixture = await buildFixture({
41
54
  integrations: [
@@ -88,6 +101,7 @@ describe('MDX plugins', () => {
88
101
  markdown: {
89
102
  remarkPlugins: [remarkToc],
90
103
  gfm: false,
104
+ smartypants: false,
91
105
  },
92
106
  integrations: [
93
107
  mdx({
@@ -129,6 +143,23 @@ describe('MDX plugins', () => {
129
143
  expect(selectGfmLink(document), 'Respects `markdown.gfm` unexpectedly.').to.not.be.null;
130
144
  }
131
145
  });
146
+
147
+ it('Handles smartypants', async () => {
148
+ const html = await fixture.readFile(FILE);
149
+ const { document } = parseHTML(html);
150
+
151
+ const quote = selectSmartypantsQuote(document);
152
+
153
+ if (extendMarkdownConfig === true) {
154
+ expect(quote.textContent, 'Does not respect `markdown.smartypants` option.').to.contain(
155
+ '"Smartypants" is -- awesome'
156
+ );
157
+ } else {
158
+ expect(quote.textContent, 'Respects `markdown.smartypants` unexpectedly.').to.contain(
159
+ '“Smartypants” is — awesome'
160
+ );
161
+ }
162
+ });
132
163
  });
133
164
  }
134
165
 
@@ -202,6 +233,10 @@ function selectGfmLink(document) {
202
233
  return document.querySelector('a[href="https://handle-me-gfm.com"]');
203
234
  }
204
235
 
236
+ function selectSmartypantsQuote(document) {
237
+ return document.querySelector('blockquote');
238
+ }
239
+
205
240
  function selectRemarkExample(document) {
206
241
  return document.querySelector('div[data-remark-plugin-works]');
207
242
  }