@next/mdx 14.3.0-canary.9 → 15.0.0-rc.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/index.js CHANGED
@@ -3,12 +3,15 @@ module.exports =
3
3
  (nextConfig = {}) => {
4
4
  const extension = pluginOptions.extension || /\.mdx$/
5
5
 
6
- const loader = nextConfig?.experimental?.mdxRs
6
+ const mdxRsOptions = nextConfig?.experimental?.mdxRs
7
+ const loader = mdxRsOptions
7
8
  ? {
8
9
  loader: require.resolve('./mdx-rs-loader'),
9
10
  options: {
10
11
  providerImportSource: 'next-mdx-import-source-file',
11
12
  ...pluginOptions.options,
13
+ // mdxRsOptions is a union of boolean and object type of MdxTransformOptions
14
+ ...(mdxRsOptions === true ? {} : mdxRsOptions),
12
15
  },
13
16
  }
14
17
  : {
package/mdx-rs-loader.js CHANGED
@@ -20,6 +20,38 @@ const own = {}.hasOwnProperty
20
20
  const marker = {}
21
21
  const cache = new WeakMap()
22
22
 
23
+ /*
24
+ * From next.config.js's mdxRs option, construct an actual option object that mdxRs compiler accepts.
25
+ */
26
+ function coereceMdxTransformOptions(options = {}) {
27
+ const { mdxType, ...restOptions } = options
28
+
29
+ let parse = undefined
30
+ switch (mdxType) {
31
+ case 'gfm':
32
+ parse = {
33
+ constructs: {
34
+ gfmAutolinkLiteral: true,
35
+ gfmFootnoteDefinition: true,
36
+ gfmLabelStartFootnote: true,
37
+ gfmStrikethrough: true,
38
+ gfmTable: true,
39
+ gfmTaskListItem: true,
40
+ },
41
+ }
42
+ break
43
+ case 'commonMark':
44
+ default:
45
+ parse = { gfmStrikethroughSingleTilde: true, mathTextSingleDollar: true }
46
+ break
47
+ }
48
+
49
+ return {
50
+ ...restOptions,
51
+ parse,
52
+ }
53
+ }
54
+
23
55
  /**
24
56
  * A webpack loader for mdx-rs. This is largely based on existing @mdx-js/loader,
25
57
  * replaces internal compilation logic to use mdx-rs instead.
@@ -41,7 +73,10 @@ function loader(value, bindings, callback) {
41
73
  let process = map.get(hash)
42
74
 
43
75
  if (!process) {
44
- process = createFormatAwareProcessors(bindings, config).compile
76
+ process = createFormatAwareProcessors(
77
+ bindings,
78
+ coereceMdxTransformOptions(config)
79
+ ).compile
45
80
  map.set(hash, process)
46
81
  }
47
82
 
@@ -88,8 +123,8 @@ function createFormatAwareProcessors(bindings, compileOptions = {}) {
88
123
  compileOptions.format === 'md'
89
124
  ? mdExtensions
90
125
  : compileOptions.format === 'mdx'
91
- ? mdxExtensions
92
- : mdExtensions.concat(mdxExtensions),
126
+ ? mdxExtensions
127
+ : mdExtensions.concat(mdxExtensions),
93
128
  compile,
94
129
  }
95
130
 
@@ -98,9 +133,9 @@ function createFormatAwareProcessors(bindings, compileOptions = {}) {
98
133
  compileOptions.format === 'md' || compileOptions.format === 'mdx'
99
134
  ? compileOptions.format
100
135
  : path.extname(p) &&
101
- (compileOptions.mdExtensions || md).includes(path.extname(p))
102
- ? 'md'
103
- : 'mdx'
136
+ (compileOptions.mdExtensions || md).includes(path.extname(p))
137
+ ? 'md'
138
+ : 'mdx'
104
139
 
105
140
  const options = {
106
141
  parse: compileOptions.parse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/mdx",
3
- "version": "14.3.0-canary.9",
3
+ "version": "15.0.0-rc.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {