MCPcopy
hub / github.com/vercel/next.js / createFormatAwareProcessors

Function createFormatAwareProcessors

packages/next-mdx/mdx-rs-loader.js:114–162  ·  view source on GitHub ↗
(bindings, compileOptions = {})

Source from the content-addressed store, hash-verified

112}
113
114function createFormatAwareProcessors(bindings, compileOptions = {}) {
115 const mdExtensions = compileOptions.mdExtensions || md
116 const mdxExtensions = compileOptions.mdxExtensions || mdx
117
118 let cachedMarkdown
119 let cachedMdx
120
121 return {
122 extnames:
123 compileOptions.format === 'md'
124 ? mdExtensions
125 : compileOptions.format === 'mdx'
126 ? mdxExtensions
127 : mdExtensions.concat(mdxExtensions),
128 compile,
129 }
130
131 function compile({ value, path: p }) {
132 const format =
133 compileOptions.format === 'md' || compileOptions.format === 'mdx'
134 ? compileOptions.format
135 : path.extname(p) &&
136 (compileOptions.mdExtensions || md).includes(path.extname(p))
137 ? 'md'
138 : 'mdx'
139
140 const options = {
141 parse: compileOptions.parse,
142 development: compileOptions.development,
143 providerImportSource: compileOptions.providerImportSource,
144 jsx: compileOptions.jsx,
145 jsxRuntime: compileOptions.jsxRuntime,
146 jsxImportSource: compileOptions.jsxImportSource,
147 pragma: compileOptions.pragma,
148 pragmaFrag: compileOptions.pragmaFrag,
149 pragmaImportSource: compileOptions.pragmaImportSource,
150 filepath: p,
151 }
152
153 const compileMdx = (input) => bindings.mdx.compile(input, options)
154
155 const processor =
156 format === 'md'
157 ? cachedMarkdown || (cachedMarkdown = compileMdx)
158 : cachedMdx || (cachedMdx = compileMdx)
159
160 return processor(value)
161 }
162}
163
164module.exports = function (code) {
165 const callback = this.async()

Callers 1

loaderFunction · 0.85

Calls 1

concatMethod · 0.45

Tested by

no test coverage detected