@vxrn/mdx 1.1.538 → 1.1.540
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/dist/index.js +250 -20068
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +424 -0
- package/dist/index.native.js +296 -43680
- package/dist/index.native.js.map +3 -3
- package/package.json +3 -2
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __commonJS = (cb, mod) => function() {
|
|
7
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
12
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
24
|
+
mod
|
|
25
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/mdx-bundler/dist/dirname-messed-up.cjs
|
|
28
|
+
var require_dirname_messed_up = __commonJS({
|
|
29
|
+
"../../node_modules/mdx-bundler/dist/dirname-messed-up.cjs"(exports2, module2) {
|
|
30
|
+
"use strict";
|
|
31
|
+
module2.exports = !__dirname.includes("mdx-bundler");
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// ../../node_modules/mdx-bundler/dist/index.js
|
|
36
|
+
var require_dist = __commonJS({
|
|
37
|
+
"../../node_modules/mdx-bundler/dist/index.js"(exports2) {
|
|
38
|
+
"use strict";
|
|
39
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
40
|
+
Object.defineProperty(exports2, "__esModule", {
|
|
41
|
+
value: !0
|
|
42
|
+
});
|
|
43
|
+
exports2.bundleMDX = bundleMDX2;
|
|
44
|
+
var _fs = _interopRequireDefault(require("fs")), _path = _interopRequireDefault(require("path")), _string_decoder = require("string_decoder"), _grayMatter = _interopRequireDefault(require("gray-matter")), esbuild = _interopRequireWildcard(require("esbuild-wasm")), _nodeResolve = require("@esbuild-plugins/node-resolve"), _esbuildPluginGlobalExternals = require("@fal-works/esbuild-plugin-global-externals"), _uuid = require("uuid"), _dirnameMessedUp = _interopRequireDefault(require_dirname_messed_up());
|
|
45
|
+
function _getRequireWildcardCache(e) {
|
|
46
|
+
if (typeof WeakMap != "function") return null;
|
|
47
|
+
var r = /* @__PURE__ */ new WeakMap(), t = /* @__PURE__ */ new WeakMap();
|
|
48
|
+
return (_getRequireWildcardCache = function(e2) {
|
|
49
|
+
return e2 ? t : r;
|
|
50
|
+
})(e);
|
|
51
|
+
}
|
|
52
|
+
function _interopRequireWildcard(e, r) {
|
|
53
|
+
if (!r && e && e.__esModule) return e;
|
|
54
|
+
if (e === null || typeof e != "object" && typeof e != "function") return { default: e };
|
|
55
|
+
var t = _getRequireWildcardCache(r);
|
|
56
|
+
if (t && t.has(e)) return t.get(e);
|
|
57
|
+
var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
58
|
+
for (var u in e) if (u !== "default" && {}.hasOwnProperty.call(e, u)) {
|
|
59
|
+
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
60
|
+
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
61
|
+
}
|
|
62
|
+
return n.default = e, t && t.set(e, n), n;
|
|
63
|
+
}
|
|
64
|
+
var {
|
|
65
|
+
readFile,
|
|
66
|
+
unlink
|
|
67
|
+
} = _fs.default.promises;
|
|
68
|
+
async function bundleMDX2({
|
|
69
|
+
file,
|
|
70
|
+
source,
|
|
71
|
+
files = {},
|
|
72
|
+
mdxOptions = (options) => options,
|
|
73
|
+
esbuildOptions = (options) => options,
|
|
74
|
+
globals = {},
|
|
75
|
+
cwd = _path.default.join(process.cwd(), "__mdx_bundler_fake_dir__"),
|
|
76
|
+
grayMatterOptions = (options) => options,
|
|
77
|
+
bundleDirectory,
|
|
78
|
+
bundlePath
|
|
79
|
+
}) {
|
|
80
|
+
_dirnameMessedUp.default;
|
|
81
|
+
let [{
|
|
82
|
+
default: mdxESBuild
|
|
83
|
+
}, {
|
|
84
|
+
default: remarkFrontmatter
|
|
85
|
+
}, {
|
|
86
|
+
default: remarkMdxFrontmatter
|
|
87
|
+
}] = await Promise.all([import("@mdx-js/esbuild"), import("remark-frontmatter"), import("remark-mdx-frontmatter")]), code, entryPath, matter2, absoluteFiles = {}, isWriting = typeof bundleDirectory == "string";
|
|
88
|
+
if (typeof bundleDirectory != typeof bundlePath)
|
|
89
|
+
throw new Error("When using `bundleDirectory` or `bundlePath` the other must be set.");
|
|
90
|
+
function isVFile(vfile) {
|
|
91
|
+
return typeof vfile == "object" && vfile !== null && "value" in vfile;
|
|
92
|
+
}
|
|
93
|
+
if (typeof source == "string")
|
|
94
|
+
matter2 = (0, _grayMatter.default)(source, grayMatterOptions({})), entryPath = _path.default.join(cwd, `./_mdx_bundler_entry_point-${(0, _uuid.v4)()}.mdx`), absoluteFiles[entryPath] = source;
|
|
95
|
+
else if (isVFile(source)) {
|
|
96
|
+
let value = String(source.value);
|
|
97
|
+
matter2 = (0, _grayMatter.default)(value, grayMatterOptions({})), entryPath = source.path ? _path.default.isAbsolute(source.path) ? source.path : _path.default.join(source.cwd, source.path) : _path.default.join(cwd, `./_mdx_bundler_entry_point-${(0, _uuid.v4)()}.mdx`), absoluteFiles[entryPath] = value;
|
|
98
|
+
} else if (typeof file == "string")
|
|
99
|
+
matter2 = _grayMatter.default.read(file, grayMatterOptions({})), entryPath = file;
|
|
100
|
+
else
|
|
101
|
+
throw new Error("`source` or `file` must be defined");
|
|
102
|
+
for (let [filepath, fileCode] of Object.entries(files))
|
|
103
|
+
absoluteFiles[_path.default.join(cwd, filepath)] = fileCode;
|
|
104
|
+
let inMemoryPlugin = {
|
|
105
|
+
name: "inMemory",
|
|
106
|
+
setup(build) {
|
|
107
|
+
build.onResolve({
|
|
108
|
+
filter: /.*/
|
|
109
|
+
}, ({
|
|
110
|
+
path: filePath,
|
|
111
|
+
importer
|
|
112
|
+
}) => {
|
|
113
|
+
if (filePath === entryPath)
|
|
114
|
+
return {
|
|
115
|
+
path: filePath,
|
|
116
|
+
pluginData: {
|
|
117
|
+
inMemory: !0,
|
|
118
|
+
contents: absoluteFiles[filePath]
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
let modulePath = _path.default.resolve(_path.default.dirname(importer), filePath);
|
|
122
|
+
if (modulePath in absoluteFiles)
|
|
123
|
+
return {
|
|
124
|
+
path: modulePath,
|
|
125
|
+
pluginData: {
|
|
126
|
+
inMemory: !0,
|
|
127
|
+
contents: absoluteFiles[modulePath]
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
for (let ext of [".js", ".ts", ".jsx", ".tsx", ".json", ".mdx"]) {
|
|
131
|
+
let fullModulePath = `${modulePath}${ext}`;
|
|
132
|
+
if (fullModulePath in absoluteFiles)
|
|
133
|
+
return {
|
|
134
|
+
path: fullModulePath,
|
|
135
|
+
pluginData: {
|
|
136
|
+
inMemory: !0,
|
|
137
|
+
contents: absoluteFiles[fullModulePath]
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return {};
|
|
142
|
+
}), build.onLoad({
|
|
143
|
+
filter: /.*/
|
|
144
|
+
}, async ({
|
|
145
|
+
path: filePath,
|
|
146
|
+
pluginData
|
|
147
|
+
}) => {
|
|
148
|
+
if (pluginData === void 0 || !pluginData.inMemory)
|
|
149
|
+
return null;
|
|
150
|
+
let fileType = (_path.default.extname(filePath) || ".jsx").slice(1), contents = absoluteFiles[filePath];
|
|
151
|
+
if (fileType === "mdx") return null;
|
|
152
|
+
let loader;
|
|
153
|
+
return build.initialOptions.loader && build.initialOptions.loader[`.${fileType}`] ? loader = build.initialOptions.loader[`.${fileType}`] : loader = /** @type import('esbuild').Loader */
|
|
154
|
+
fileType, {
|
|
155
|
+
contents,
|
|
156
|
+
loader
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}, buildOptions = esbuildOptions({
|
|
161
|
+
entryPoints: [entryPath],
|
|
162
|
+
write: isWriting,
|
|
163
|
+
outdir: isWriting ? bundleDirectory : void 0,
|
|
164
|
+
publicPath: isWriting ? bundlePath : void 0,
|
|
165
|
+
absWorkingDir: cwd,
|
|
166
|
+
define: {
|
|
167
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? "production")
|
|
168
|
+
},
|
|
169
|
+
plugins: [
|
|
170
|
+
(0, _esbuildPluginGlobalExternals.globalExternals)({
|
|
171
|
+
...globals,
|
|
172
|
+
react: {
|
|
173
|
+
varName: "React",
|
|
174
|
+
type: "cjs"
|
|
175
|
+
},
|
|
176
|
+
"react-dom": {
|
|
177
|
+
varName: "ReactDOM",
|
|
178
|
+
type: "cjs"
|
|
179
|
+
},
|
|
180
|
+
"react/jsx-runtime": {
|
|
181
|
+
varName: "_jsx_runtime",
|
|
182
|
+
type: "cjs"
|
|
183
|
+
}
|
|
184
|
+
}),
|
|
185
|
+
// eslint-disable-next-line new-cap
|
|
186
|
+
(0, _nodeResolve.NodeResolvePlugin)({
|
|
187
|
+
extensions: [".js", ".ts", ".jsx", ".tsx"],
|
|
188
|
+
resolveOptions: {
|
|
189
|
+
basedir: cwd
|
|
190
|
+
}
|
|
191
|
+
}),
|
|
192
|
+
inMemoryPlugin,
|
|
193
|
+
mdxESBuild(mdxOptions({
|
|
194
|
+
remarkPlugins: [remarkFrontmatter, [remarkMdxFrontmatter, {
|
|
195
|
+
name: "frontmatter"
|
|
196
|
+
}]]
|
|
197
|
+
}, matter2.data))
|
|
198
|
+
],
|
|
199
|
+
bundle: !0,
|
|
200
|
+
format: "iife",
|
|
201
|
+
globalName: "Component",
|
|
202
|
+
minify: !0
|
|
203
|
+
}, matter2.data), bundled = await esbuild.build(buildOptions);
|
|
204
|
+
if (bundled.outputFiles)
|
|
205
|
+
code = new _string_decoder.StringDecoder("utf8").write(Buffer.from(bundled.outputFiles[0].contents));
|
|
206
|
+
else if (buildOptions.outdir && buildOptions.write) {
|
|
207
|
+
let entryFile = (
|
|
208
|
+
/** @type {{entryPoints: string[]}} */
|
|
209
|
+
buildOptions.entryPoints[0]
|
|
210
|
+
), fileName = _path.default.basename(entryFile).replace(/\.[^/.]+$/, ".js");
|
|
211
|
+
code = (await readFile(_path.default.join(buildOptions.outdir, fileName))).toString(), await unlink(_path.default.join(buildOptions.outdir, fileName));
|
|
212
|
+
} else
|
|
213
|
+
throw new Error("You must either specify `write: false` or `write: true` and `outdir: '/path'` in your esbuild options");
|
|
214
|
+
return {
|
|
215
|
+
code: `${code};return Component;`,
|
|
216
|
+
frontmatter: matter2.data,
|
|
217
|
+
errors: bundled.errors,
|
|
218
|
+
matter: matter2
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// src/index.ts
|
|
225
|
+
var index_exports = {};
|
|
226
|
+
__export(index_exports, {
|
|
227
|
+
createCodeHighlighter: () => createCodeHighlighter,
|
|
228
|
+
getAllFrontmatter: () => getAllFrontmatter,
|
|
229
|
+
getAllVersionsFromPath: () => getAllVersionsFromPath,
|
|
230
|
+
getMDX: () => getMDX,
|
|
231
|
+
getMDXBySlug: () => getMDXBySlug
|
|
232
|
+
});
|
|
233
|
+
module.exports = __toCommonJS(index_exports);
|
|
234
|
+
|
|
235
|
+
// src/getAllFrontmatter.tsx
|
|
236
|
+
var import_fast_glob = __toESM(require("fast-glob")), import_gray_matter = __toESM(require("gray-matter")), import_node_fs = __toESM(require("node:fs")), import_node_path = __toESM(require("node:path")), import_reading_time = __toESM(require("reading-time"));
|
|
237
|
+
|
|
238
|
+
// src/getHeadings.ts
|
|
239
|
+
var getTitle = (source) => source.replace(/^\#+\s+/, "").replace(/\<.*\>/, " "), getHeadings = (source) => source.split(`
|
|
240
|
+
`).filter((x) => x.startsWith("#")).map((x) => ({
|
|
241
|
+
title: getTitle(x),
|
|
242
|
+
priority: x.trim().split(" ")[0].length,
|
|
243
|
+
id: `#${getTitle(x).replace(/\s+/g, "-").toLowerCase()}`
|
|
244
|
+
}));
|
|
245
|
+
|
|
246
|
+
// src/getAllFrontmatter.tsx
|
|
247
|
+
var getAllFrontmatter = (fromPath) => import_fast_glob.default.sync(`${fromPath}/**/*.mdx`).map((filePath) => {
|
|
248
|
+
let source = import_node_fs.default.readFileSync(import_node_path.default.join(filePath), "utf8"), { data, content } = (0, import_gray_matter.default)(source), slug = filePath.replace(`${fromPath.replaceAll("\\", "/")}/`, "").replace(".mdx", "");
|
|
249
|
+
return {
|
|
250
|
+
...data,
|
|
251
|
+
slug,
|
|
252
|
+
headings: getHeadings(source),
|
|
253
|
+
readingTime: (0, import_reading_time.default)(content)
|
|
254
|
+
};
|
|
255
|
+
}).sort((a, b) => Number(new Date(b.publishedAt || "")) - Number(new Date(a.publishedAt || "")));
|
|
256
|
+
|
|
257
|
+
// src/getMDX.ts
|
|
258
|
+
var import_mdx_bundler = __toESM(require_dist()), import_reading_time2 = __toESM(require("reading-time")), import_rehype_autolink_headings = __toESM(require("rehype-autolink-headings")), import_rehype_slug = __toESM(require("rehype-slug"));
|
|
259
|
+
|
|
260
|
+
// src/rehypeHighlightCode.tsx
|
|
261
|
+
var import_hast_util_to_string = require("hast-util-to-string"), import_parse_numeric_range = __toESM(require("parse-numeric-range")), import_refractor = require("refractor"), import_tsx = __toESM(require("refractor/lang/tsx.js")), import_unist_util_visit = __toESM(require("unist-util-visit"));
|
|
262
|
+
|
|
263
|
+
// src/rehypeLine.tsx
|
|
264
|
+
var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse = __toESM(require("rehype-parse")), import_unified = require("unified"), lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
265
|
+
let lineNumber = lineNum;
|
|
266
|
+
return ast.reduce(
|
|
267
|
+
(result, node) => {
|
|
268
|
+
if (node.type === "text") {
|
|
269
|
+
if (node.value.indexOf(`
|
|
270
|
+
`) === -1)
|
|
271
|
+
return node.lineNumber = lineNumber, result.nodes.push(node), result;
|
|
272
|
+
let lines = node.value.split(`
|
|
273
|
+
`);
|
|
274
|
+
for (let i = 0; i < lines.length; i++)
|
|
275
|
+
i !== 0 && ++lineNumber, !(i === lines.length - 1 && lines[i].length === 0) && result.nodes.push({
|
|
276
|
+
type: "text",
|
|
277
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
278
|
+
`,
|
|
279
|
+
lineNumber
|
|
280
|
+
});
|
|
281
|
+
return result.lineNumber = lineNumber, result;
|
|
282
|
+
}
|
|
283
|
+
if (node.children) {
|
|
284
|
+
node.lineNumber = lineNumber;
|
|
285
|
+
let processed = lineNumberify2(node.children, lineNumber);
|
|
286
|
+
return node.children = processed.nodes, result.lineNumber = processed.lineNumber, result.nodes.push(node), result;
|
|
287
|
+
}
|
|
288
|
+
return result.nodes.push(node), result;
|
|
289
|
+
},
|
|
290
|
+
{ nodes: [], lineNumber }
|
|
291
|
+
);
|
|
292
|
+
}, wrapLines = function(ast, linesToHighlight) {
|
|
293
|
+
let highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0, allLines = Array.from(new Set(ast.map((x) => x.lineNumber))), i = 0;
|
|
294
|
+
return allLines.reduce((nodes, marker) => {
|
|
295
|
+
let line = marker, children = [];
|
|
296
|
+
for (; i < ast.length; i++) {
|
|
297
|
+
if (ast[i].lineNumber < line) {
|
|
298
|
+
nodes.push(ast[i]);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (ast[i].lineNumber === line) {
|
|
302
|
+
children.push(ast[i]);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (ast[i].lineNumber > line)
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
return nodes.push({
|
|
309
|
+
type: "element",
|
|
310
|
+
tagName: "div",
|
|
311
|
+
properties: {
|
|
312
|
+
dataLine: line,
|
|
313
|
+
className: "highlight-line",
|
|
314
|
+
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
315
|
+
},
|
|
316
|
+
children,
|
|
317
|
+
lineNumber: line
|
|
318
|
+
}), nodes;
|
|
319
|
+
}, []);
|
|
320
|
+
}, MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g, applyMultilineFix = (ast) => {
|
|
321
|
+
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
322
|
+
return html = html.replace(
|
|
323
|
+
MULTILINE_TOKEN_SPAN,
|
|
324
|
+
(match, token) => match.replace(/\n/g, `</span>
|
|
325
|
+
<span class="token ${token}">`)
|
|
326
|
+
), (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(html).children;
|
|
327
|
+
};
|
|
328
|
+
function rehypeHighlightLine(ast, lines) {
|
|
329
|
+
let formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
330
|
+
return wrapLines(numbered, lines);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/rehypeWord.tsx
|
|
334
|
+
var import_hast_util_to_html2 = require("hast-util-to-html"), import_rehype_parse2 = __toESM(require("rehype-parse")), import_unified2 = require("unified"), CALLOUT = /__(.*?)__/g, rehypeHighlightWord = (code) => {
|
|
335
|
+
let result = (0, import_hast_util_to_html2.toHtml)(code).replace(CALLOUT, (_, text) => `<span class="highlight-word">${text}</span>`);
|
|
336
|
+
return (0, import_unified2.unified)().use(import_rehype_parse2.default, { emitParseErrors: !0, fragment: !0 }).parse(result).children;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// src/rehypeHighlightCode.tsx
|
|
340
|
+
import_refractor.refractor.register(import_tsx.default);
|
|
341
|
+
var rehypeHighlightCode = (options = {}) => {
|
|
342
|
+
return (tree) => {
|
|
343
|
+
(0, import_unist_util_visit.default)(tree, "element", visitor);
|
|
344
|
+
};
|
|
345
|
+
function visitor(node, index, parent) {
|
|
346
|
+
if (!parent || parent.tagName !== "pre" || node.tagName !== "code" || !node.properties.className)
|
|
347
|
+
return;
|
|
348
|
+
let [_, lang] = node.properties.className[0].split("-"), codeString = (0, import_hast_util_to_string.toString)(node), result = import_refractor.refractor.highlight(codeString, lang), linesToHighlight = (0, import_parse_numeric_range.default)(node.properties.line || "0");
|
|
349
|
+
result = rehypeHighlightLine(result, linesToHighlight), node.children = rehypeHighlightWord(result);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// src/rehypeMetaAttribute.tsx
|
|
354
|
+
var import_unist_util_visit2 = __toESM(require("unist-util-visit")), re = /\b([-\w]+)(?:=(?:"([^"]*)"|'([^']*)'|([^"'\s]+)))?/g, rehypeMetaAttribute_default = (options = {}) => {
|
|
355
|
+
return (tree) => {
|
|
356
|
+
(0, import_unist_util_visit2.default)(tree, "element", onelement);
|
|
357
|
+
};
|
|
358
|
+
function onelement(node) {
|
|
359
|
+
let match;
|
|
360
|
+
if (node.tagName === "code" && node.data && node.data.meta)
|
|
361
|
+
for (re.lastIndex = 0; match = re.exec(node.data.meta); )
|
|
362
|
+
node.properties[match[1]] = match[2] || match[3] || match[4] || "";
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// src/getMDX.ts
|
|
367
|
+
async function getMDX(source, extraPlugins) {
|
|
368
|
+
let { frontmatter, code } = await (0, import_mdx_bundler.bundleMDX)({
|
|
369
|
+
source,
|
|
370
|
+
mdxOptions(options) {
|
|
371
|
+
let plugins = [
|
|
372
|
+
...extraPlugins || [],
|
|
373
|
+
...options.rehypePlugins ?? [],
|
|
374
|
+
rehypeMetaAttribute_default,
|
|
375
|
+
rehypeHighlightCode,
|
|
376
|
+
import_rehype_autolink_headings.default,
|
|
377
|
+
import_rehype_slug.default
|
|
378
|
+
];
|
|
379
|
+
return options.rehypePlugins = plugins, options;
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
return {
|
|
383
|
+
frontmatter: {
|
|
384
|
+
...frontmatter,
|
|
385
|
+
headings: getHeadings(source),
|
|
386
|
+
readingTime: (0, import_reading_time2.default)(code)
|
|
387
|
+
},
|
|
388
|
+
code
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/getMDXBySlug.tsx
|
|
393
|
+
var import_node_fs2 = __toESM(require("node:fs")), import_node_path2 = __toESM(require("node:path")), import_compare_versions = __toESM(require("compare-versions"));
|
|
394
|
+
var getMDXBySlug = async (basePath, slug, extraPlugins) => {
|
|
395
|
+
let mdxPath = slug;
|
|
396
|
+
if (!slug.includes(".") && basePath.includes("components")) {
|
|
397
|
+
let versions = getAllVersionsFromPath(import_node_path2.default.join(basePath, slug));
|
|
398
|
+
mdxPath += `/${versions[0]}`;
|
|
399
|
+
}
|
|
400
|
+
let filePath = import_node_path2.default.join(basePath, `${mdxPath}.mdx`), source = import_node_fs2.default.readFileSync(filePath, "utf8");
|
|
401
|
+
return await getMDX(source, extraPlugins);
|
|
402
|
+
};
|
|
403
|
+
function getAllVersionsFromPath(fromPath) {
|
|
404
|
+
return import_node_fs2.default.existsSync(fromPath) ? import_node_fs2.default.readdirSync(fromPath).map((fileName) => fileName.replace(".mdx", "")).sort(import_compare_versions.default).reverse() : [];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// src/highlightCode.tsx
|
|
408
|
+
var import_hast_util_to_html3 = require("hast-util-to-html"), import_parse_numeric_range2 = __toESM(require("parse-numeric-range")), import_refractor2 = require("refractor"), import_css = __toESM(require("refractor/lang/css.js")), import_tsx2 = __toESM(require("refractor/lang/tsx.js"));
|
|
409
|
+
var highlighter;
|
|
410
|
+
function createCodeHighlighter() {
|
|
411
|
+
return highlighter || (import_refractor2.refractor.register(import_tsx2.default), import_refractor2.refractor.register(import_css.default), highlighter = function(source, language, line = "0") {
|
|
412
|
+
let result = import_refractor2.refractor.highlight(source, language);
|
|
413
|
+
return result = rehypeHighlightLine(result, (0, import_parse_numeric_range2.default)(line)), result = rehypeHighlightWord(result), result = (0, import_hast_util_to_html3.toHtml)(result), result;
|
|
414
|
+
}, highlighter);
|
|
415
|
+
}
|
|
416
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
417
|
+
0 && (module.exports = {
|
|
418
|
+
createCodeHighlighter,
|
|
419
|
+
getAllFrontmatter,
|
|
420
|
+
getAllVersionsFromPath,
|
|
421
|
+
getMDX,
|
|
422
|
+
getMDXBySlug
|
|
423
|
+
});
|
|
424
|
+
//# sourceMappingURL=index.js.map
|