@temelj/mdx 0.11.0 → 0.11.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.
- package/dist/compiler.d.mts +49 -1
- package/dist/compiler.d.mts.map +1 -1
- package/dist/compiler.mjs +205 -12
- package/dist/compiler.mjs.map +1 -1
- package/dist/mod.d.mts +2 -2
- package/dist/mod.mjs +2 -2
- package/package.json +3 -1
package/dist/compiler.d.mts
CHANGED
|
@@ -17,6 +17,31 @@ interface MdxCompileOptions {
|
|
|
17
17
|
frontmatterOnly?: boolean | undefined;
|
|
18
18
|
mdxOptions?: CompileOptions;
|
|
19
19
|
}
|
|
20
|
+
interface MdxMessagePoint {
|
|
21
|
+
line?: number | undefined;
|
|
22
|
+
column?: number | undefined;
|
|
23
|
+
offset?: number | undefined;
|
|
24
|
+
}
|
|
25
|
+
interface MdxMessagePlace {
|
|
26
|
+
start?: MdxMessagePoint | undefined;
|
|
27
|
+
end?: MdxMessagePoint | undefined;
|
|
28
|
+
}
|
|
29
|
+
interface MdxMessage {
|
|
30
|
+
message: string;
|
|
31
|
+
reason: string;
|
|
32
|
+
source?: string | undefined;
|
|
33
|
+
ruleId?: string | undefined;
|
|
34
|
+
fatal?: boolean | undefined;
|
|
35
|
+
line?: number | undefined;
|
|
36
|
+
column?: number | undefined;
|
|
37
|
+
place?: MdxMessagePlace | undefined;
|
|
38
|
+
sourceLine?: string | undefined;
|
|
39
|
+
snippet?: string | undefined;
|
|
40
|
+
cause?: {
|
|
41
|
+
name?: string | undefined;
|
|
42
|
+
message: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
20
45
|
/**
|
|
21
46
|
* The result of compiling an MDX document.
|
|
22
47
|
* Compiled content is optional, because sometimes we only need the frontmatter.
|
|
@@ -24,6 +49,29 @@ interface MdxCompileOptions {
|
|
|
24
49
|
interface MdxArtifact<TFrontmatter = Record<string, unknown>> {
|
|
25
50
|
compiled?: string | undefined;
|
|
26
51
|
frontmatter: TFrontmatter;
|
|
52
|
+
messages: MdxMessage[];
|
|
53
|
+
}
|
|
54
|
+
declare class MdxCompileError extends Error {
|
|
55
|
+
readonly reason: string;
|
|
56
|
+
readonly source?: string | undefined;
|
|
57
|
+
readonly ruleId?: string | undefined;
|
|
58
|
+
readonly line?: number | undefined;
|
|
59
|
+
readonly column?: number | undefined;
|
|
60
|
+
readonly place?: MdxMessagePlace | undefined;
|
|
61
|
+
readonly sourceLine?: string | undefined;
|
|
62
|
+
readonly snippet?: string | undefined;
|
|
63
|
+
readonly diagnostics: MdxMessage[];
|
|
64
|
+
constructor(reason: string, options?: {
|
|
65
|
+
source?: string | undefined;
|
|
66
|
+
ruleId?: string | undefined;
|
|
67
|
+
line?: number | undefined;
|
|
68
|
+
column?: number | undefined;
|
|
69
|
+
place?: MdxMessagePlace | undefined;
|
|
70
|
+
sourceLine?: string | undefined;
|
|
71
|
+
snippet?: string | undefined;
|
|
72
|
+
diagnostics?: MdxMessage[] | undefined;
|
|
73
|
+
cause?: unknown;
|
|
74
|
+
});
|
|
27
75
|
}
|
|
28
76
|
/**
|
|
29
77
|
* A reusable compiler for compiling MDX.
|
|
@@ -41,5 +89,5 @@ declare class MdxCompiler {
|
|
|
41
89
|
}?: MdxCompileOptions, frontmatterSchema?: TFrontmatterSchema): Promise<MdxArtifact<z.output<TFrontmatterSchema>>>;
|
|
42
90
|
}
|
|
43
91
|
//#endregion
|
|
44
|
-
export { MdxArtifact, MdxCompileOptions, MdxCompiler, MdxSource, remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
92
|
+
export { MdxArtifact, MdxCompileError, MdxCompileOptions, MdxCompiler, MdxMessage, MdxMessagePlace, MdxMessagePoint, MdxSource, remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
45
93
|
//# sourceMappingURL=compiler.d.mts.map
|
package/dist/compiler.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.mts","names":[],"sources":["../src/compiler.ts"],"mapp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AAU,IAAA,GACtC,OAAA,GAAU,QAAA,GACT,WAAA;EASI,gBAAA,UAAA,CACL,MAAA,EAAQ,MAAA,EAAQ,QAAA,IAAY,IAAA,EAAU,IAAA,GACtC,OAAA,GAAU,QAAA,GACT,WAAA;EASU,OAAA,4BAAmC,CAAA,CAAE,SAAA,CAAA,CAChD,MAAA,EAAQ,SAAA;IACN,eAAA;IAAyB;EAAA,IAAc,iBAAA,EACzC,iBAAA,GAAoB,kBAAA,GACnB,OAAA,CAAQ,WAAA,CAAY,CAAA,CAAE,MAAA,CAAO,kBAAA;AAAA"}
|
package/dist/compiler.mjs
CHANGED
|
@@ -4,6 +4,37 @@ import remarkGfmPlugin from "remark-gfm";
|
|
|
4
4
|
import { VFile } from "vfile";
|
|
5
5
|
import { matter } from "vfile-matter";
|
|
6
6
|
//#region src/compiler.ts
|
|
7
|
+
var MdxCompileError = class extends Error {
|
|
8
|
+
reason;
|
|
9
|
+
source;
|
|
10
|
+
ruleId;
|
|
11
|
+
line;
|
|
12
|
+
column;
|
|
13
|
+
place;
|
|
14
|
+
sourceLine;
|
|
15
|
+
snippet;
|
|
16
|
+
diagnostics;
|
|
17
|
+
constructor(reason, options = {}) {
|
|
18
|
+
super(formatDiagnosticMessage(reason, {
|
|
19
|
+
source: options.source,
|
|
20
|
+
ruleId: options.ruleId,
|
|
21
|
+
line: options.line,
|
|
22
|
+
column: options.column,
|
|
23
|
+
sourceLine: options.sourceLine,
|
|
24
|
+
snippet: options.snippet
|
|
25
|
+
}), options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
26
|
+
this.name = "MdxCompileError";
|
|
27
|
+
this.reason = reason;
|
|
28
|
+
this.source = options.source;
|
|
29
|
+
this.ruleId = options.ruleId;
|
|
30
|
+
this.line = options.line;
|
|
31
|
+
this.column = options.column;
|
|
32
|
+
this.place = options.place;
|
|
33
|
+
this.sourceLine = options.sourceLine;
|
|
34
|
+
this.snippet = options.snippet;
|
|
35
|
+
this.diagnostics = options.diagnostics ?? [];
|
|
36
|
+
}
|
|
37
|
+
};
|
|
7
38
|
/**
|
|
8
39
|
* A reusable compiler for compiling MDX.
|
|
9
40
|
*/
|
|
@@ -27,12 +58,11 @@ var MdxCompiler = class {
|
|
|
27
58
|
return this;
|
|
28
59
|
}
|
|
29
60
|
async compile(source, { frontmatterOnly = false, mdxOptions } = {}, frontmatterSchema) {
|
|
61
|
+
const sourceText = toSourceText(source);
|
|
30
62
|
const vfile = new VFile({
|
|
31
63
|
value: source,
|
|
32
64
|
cwd: "/",
|
|
33
|
-
path: "/"
|
|
34
|
-
message: {},
|
|
35
|
-
messages: {}
|
|
65
|
+
path: "/source.mdx"
|
|
36
66
|
});
|
|
37
67
|
matter(vfile, { strip: true });
|
|
38
68
|
const remarkPlugins = [
|
|
@@ -46,21 +76,184 @@ var MdxCompiler = class {
|
|
|
46
76
|
...mdxOptions?.rehypePlugins ?? []
|
|
47
77
|
];
|
|
48
78
|
let compiled;
|
|
49
|
-
if (!frontmatterOnly)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
if (!frontmatterOnly) try {
|
|
80
|
+
compiled = (await compile(vfile, {
|
|
81
|
+
outputFormat: "function-body",
|
|
82
|
+
...this.mdxOptions ?? {},
|
|
83
|
+
...mdxOptions ?? {},
|
|
84
|
+
remarkPlugins,
|
|
85
|
+
rehypePlugins
|
|
86
|
+
})).value.toString();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
throw toMdxCompileError(error, sourceText, vfile.messages);
|
|
89
|
+
}
|
|
56
90
|
const frontmatter = frontmatterSchema === void 0 ? vfile.data.matter ?? {} : frontmatterSchema.parse(vfile.data.matter ?? {});
|
|
57
91
|
return {
|
|
58
92
|
compiled,
|
|
59
|
-
frontmatter
|
|
93
|
+
frontmatter,
|
|
94
|
+
messages: normalizeMessages(vfile.messages, sourceText)
|
|
60
95
|
};
|
|
61
96
|
}
|
|
62
97
|
};
|
|
98
|
+
function toMdxCompileError(error, sourceText, diagnostics) {
|
|
99
|
+
const details = getDiagnosticDetails(sourceText, getErrorPlace(error), error);
|
|
100
|
+
return new MdxCompileError(getErrorReason(error), {
|
|
101
|
+
source: getErrorField(error, "source"),
|
|
102
|
+
ruleId: getErrorField(error, "ruleId"),
|
|
103
|
+
line: details.line,
|
|
104
|
+
column: details.column,
|
|
105
|
+
place: details.place,
|
|
106
|
+
sourceLine: details.sourceLine,
|
|
107
|
+
snippet: details.snippet,
|
|
108
|
+
diagnostics: normalizeMessages(diagnostics, sourceText),
|
|
109
|
+
cause: error
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function normalizeMessages(messages, sourceText) {
|
|
113
|
+
return messages.map((message) => {
|
|
114
|
+
const details = getDiagnosticDetails(sourceText, toMessagePlace(message), message);
|
|
115
|
+
const reason = getErrorReason(message);
|
|
116
|
+
const source = getErrorField(message, "source");
|
|
117
|
+
const ruleId = getErrorField(message, "ruleId");
|
|
118
|
+
const cause = getErrorCause(message);
|
|
119
|
+
return {
|
|
120
|
+
message: formatDiagnosticMessage(reason, {
|
|
121
|
+
source,
|
|
122
|
+
ruleId,
|
|
123
|
+
line: details.line,
|
|
124
|
+
column: details.column,
|
|
125
|
+
sourceLine: details.sourceLine,
|
|
126
|
+
snippet: details.snippet,
|
|
127
|
+
causeMessage: cause?.message
|
|
128
|
+
}),
|
|
129
|
+
reason,
|
|
130
|
+
source,
|
|
131
|
+
ruleId,
|
|
132
|
+
fatal: typeof message.fatal === "boolean" ? message.fatal : void 0,
|
|
133
|
+
line: details.line,
|
|
134
|
+
column: details.column,
|
|
135
|
+
place: details.place,
|
|
136
|
+
sourceLine: details.sourceLine,
|
|
137
|
+
snippet: details.snippet,
|
|
138
|
+
cause
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function formatDiagnosticMessage(reason, options) {
|
|
143
|
+
const lines = [[
|
|
144
|
+
reason,
|
|
145
|
+
options.source === void 0 ? void 0 : options.ruleId === void 0 ? options.source : `${options.source}:${options.ruleId}`,
|
|
146
|
+
options.line === void 0 ? void 0 : options.column === void 0 ? `at ${options.line}` : `at ${options.line}:${options.column}`
|
|
147
|
+
].filter(Boolean).join(" ")];
|
|
148
|
+
if (options.snippet !== void 0) lines.push(`Source: ${options.snippet}`);
|
|
149
|
+
if (options.sourceLine !== void 0 && options.sourceLine !== options.snippet) lines.push(`Line: ${options.sourceLine}`);
|
|
150
|
+
if (options.causeMessage !== void 0 && options.causeMessage !== "" && options.causeMessage !== reason) lines.push(`Cause: ${options.causeMessage}`);
|
|
151
|
+
return lines.join("\n");
|
|
152
|
+
}
|
|
153
|
+
function getDiagnosticDetails(sourceText, place, error) {
|
|
154
|
+
const line = place?.start?.line ?? getErrorNumberField(error, "line");
|
|
155
|
+
const column = place?.start?.column ?? getErrorNumberField(error, "column");
|
|
156
|
+
const normalizedPlace = line === void 0 && column === void 0 && place === void 0 ? void 0 : {
|
|
157
|
+
start: {
|
|
158
|
+
line,
|
|
159
|
+
column,
|
|
160
|
+
offset: place?.start?.offset
|
|
161
|
+
},
|
|
162
|
+
end: place?.end === void 0 ? void 0 : {
|
|
163
|
+
line: place.end.line,
|
|
164
|
+
column: place.end.column,
|
|
165
|
+
offset: place.end.offset
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return {
|
|
169
|
+
line,
|
|
170
|
+
column,
|
|
171
|
+
place: normalizedPlace,
|
|
172
|
+
sourceLine: getSourceLine(sourceText, line),
|
|
173
|
+
snippet: getSourceSnippet(sourceText, normalizedPlace)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function getSourceLine(sourceText, line) {
|
|
177
|
+
if (line === void 0 || line < 1) return;
|
|
178
|
+
return sourceText.split(/\r?\n/u)[line - 1];
|
|
179
|
+
}
|
|
180
|
+
function getSourceSnippet(sourceText, place) {
|
|
181
|
+
if (place?.start?.offset !== void 0 && place.end?.offset !== void 0) return sourceText.slice(place.start.offset, place.end.offset) || void 0;
|
|
182
|
+
if (place?.start?.line === void 0 || place.start.column === void 0) return;
|
|
183
|
+
const lines = sourceText.split(/\r?\n/u);
|
|
184
|
+
const startLineIndex = place.start.line - 1;
|
|
185
|
+
const endLineIndex = (place.end?.line ?? place.start.line) - 1;
|
|
186
|
+
if (startLineIndex < 0 || startLineIndex >= lines.length) return;
|
|
187
|
+
const selectedLines = lines.slice(startLineIndex, endLineIndex + 1);
|
|
188
|
+
if (selectedLines.length === 0) return;
|
|
189
|
+
selectedLines[0] = selectedLines[0].slice(place.start.column - 1);
|
|
190
|
+
const endColumn = place.end?.column;
|
|
191
|
+
if (endColumn !== void 0) {
|
|
192
|
+
const lastIndex = selectedLines.length - 1;
|
|
193
|
+
selectedLines[lastIndex] = selectedLines[lastIndex].slice(0, endColumn - 1);
|
|
194
|
+
}
|
|
195
|
+
return selectedLines.join("\n") || void 0;
|
|
196
|
+
}
|
|
197
|
+
function getErrorPlace(error) {
|
|
198
|
+
if (typeof error !== "object" || error === null) return;
|
|
199
|
+
const candidate = error;
|
|
200
|
+
return toPlace(candidate.place) ?? toPlace(candidate.position);
|
|
201
|
+
}
|
|
202
|
+
function toMessagePlace(message) {
|
|
203
|
+
return toPlace(message.place);
|
|
204
|
+
}
|
|
205
|
+
function toPlace(value) {
|
|
206
|
+
if (typeof value !== "object" || value === null) return;
|
|
207
|
+
const candidate = value;
|
|
208
|
+
if (candidate.start !== void 0 || candidate.end !== void 0) return {
|
|
209
|
+
start: toPoint(candidate.start),
|
|
210
|
+
end: toPoint(candidate.end)
|
|
211
|
+
};
|
|
212
|
+
const point = toPoint(candidate);
|
|
213
|
+
return point === void 0 ? void 0 : { start: point };
|
|
214
|
+
}
|
|
215
|
+
function toPoint(value) {
|
|
216
|
+
if (typeof value !== "object" || value === null) return;
|
|
217
|
+
const candidate = value;
|
|
218
|
+
const line = typeof candidate.line === "number" ? candidate.line : void 0;
|
|
219
|
+
const column = typeof candidate.column === "number" ? candidate.column : void 0;
|
|
220
|
+
const offset = typeof candidate.offset === "number" ? candidate.offset : void 0;
|
|
221
|
+
if (line === void 0 && column === void 0 && offset === void 0) return;
|
|
222
|
+
return {
|
|
223
|
+
line,
|
|
224
|
+
column,
|
|
225
|
+
offset
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function getErrorReason(error) {
|
|
229
|
+
if (error instanceof Error && error.message !== "") return error.message;
|
|
230
|
+
const reason = getErrorField(error, "reason");
|
|
231
|
+
if (reason !== void 0 && reason !== "") return reason;
|
|
232
|
+
return String(error);
|
|
233
|
+
}
|
|
234
|
+
function getErrorCause(error) {
|
|
235
|
+
if (typeof error !== "object" || error === null || !("cause" in error)) return;
|
|
236
|
+
const cause = error.cause;
|
|
237
|
+
if (cause instanceof Error) return {
|
|
238
|
+
name: cause.name,
|
|
239
|
+
message: cause.message
|
|
240
|
+
};
|
|
241
|
+
if (typeof cause === "string" && cause !== "") return { message: cause };
|
|
242
|
+
}
|
|
243
|
+
function getErrorField(error, field) {
|
|
244
|
+
if (typeof error !== "object" || error === null || !(field in error)) return;
|
|
245
|
+
const value = error[field];
|
|
246
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
247
|
+
}
|
|
248
|
+
function getErrorNumberField(error, field) {
|
|
249
|
+
if (typeof error !== "object" || error === null || !(field in error)) return;
|
|
250
|
+
const value = error[field];
|
|
251
|
+
return typeof value === "number" ? value : void 0;
|
|
252
|
+
}
|
|
253
|
+
function toSourceText(source) {
|
|
254
|
+
return typeof source === "string" ? source : new TextDecoder().decode(source);
|
|
255
|
+
}
|
|
63
256
|
//#endregion
|
|
64
|
-
export { MdxCompiler, remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
257
|
+
export { MdxCompileError, MdxCompiler, remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
65
258
|
|
|
66
259
|
//# sourceMappingURL=compiler.mjs.map
|
package/dist/compiler.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.mjs","names":["compileMdxJs"],"sources":["../src/compiler.ts"],"sourcesContent":["import {\n compile as compileMdxJs,\n type CompileOptions as MdxJsCompileOptions,\n} from \"@mdx-js/mdx\";\nimport remarkFrontmatterPlugin from \"remark-frontmatter\";\nimport remarkGfmPlugin from \"remark-gfm\";\nimport type { Pluggable, PluggableList, Plugin } from \"unified\";\nimport { VFile } from \"vfile\";\nimport { matter } from \"vfile-matter\";\nimport type { z } from \"zod\";\n\nimport type { HastNode } from \"./types\";\n\nexport { remarkFrontmatterPlugin, remarkGfmPlugin };\n\n/**\n * Represents the source content for an MDX document.\n */\nexport type MdxSource = string | Uint8Array;\n\n/**\n * Options for compiling an MDX document.\n */\nexport interface MdxCompileOptions {\n frontmatterOnly?: boolean | undefined;\n mdxOptions?: MdxJsCompileOptions;\n}\n\n/**\n * The result of compiling an MDX document.\n * Compiled content is optional, because sometimes we only need the frontmatter.\n */\nexport interface MdxArtifact<TFrontmatter = Record<string, unknown>> {\n compiled?: string | undefined;\n frontmatter: TFrontmatter;\n}\n\n/**\n * A reusable compiler for compiling MDX.\n */\nexport class MdxCompiler {\n private readonly mdxOptions: MdxJsCompileOptions;\n private readonly remarkPlugins: PluggableList;\n private readonly rehypePlugins: PluggableList;\n\n public constructor(mdxOptions: MdxJsCompileOptions = {}) {\n this.mdxOptions = mdxOptions;\n this.remarkPlugins = [remarkFrontmatterPlugin, remarkGfmPlugin];\n this.rehypePlugins = [];\n }\n\n public withRemarkPlugin<TOptions>(\n plugin: Plugin<[TOptions?], HastNode, HastNode>,\n options?: TOptions,\n ): MdxCompiler {\n if (options === undefined) {\n this.remarkPlugins.push(plugin as Pluggable);\n } else {\n this.remarkPlugins.push([plugin, options] as Pluggable);\n }\n return this;\n }\n\n public withRehypePlugin<TOptions>(\n plugin: Plugin<[TOptions?], HastNode, HastNode>,\n options?: TOptions,\n ): MdxCompiler {\n if (options === undefined) {\n this.rehypePlugins.push(plugin as Pluggable);\n } else {\n this.rehypePlugins.push([plugin, options] as Pluggable);\n }\n return this;\n }\n\n public async compile<TFrontmatterSchema extends z.ZodSchema>(\n source: MdxSource,\n { frontmatterOnly = false, mdxOptions }: MdxCompileOptions = {},\n frontmatterSchema?: TFrontmatterSchema,\n ): Promise<MdxArtifact<z.output<TFrontmatterSchema>>> {\n const vfile = new VFile({\n value: source,\n // Needed so vfile doesn't need to access fs.\n cwd: \"/\",\n path: \"/\",\n message: {},\n messages: {},\n });\n matter(vfile, { strip: true });\n\n const remarkPlugins = [\n ...this.remarkPlugins,\n ...(this.mdxOptions?.remarkPlugins ?? []),\n ...(mdxOptions?.remarkPlugins ?? []),\n ];\n const rehypePlugins = [\n ...this.rehypePlugins,\n ...(this.mdxOptions?.rehypePlugins ?? []),\n ...(mdxOptions?.rehypePlugins ?? []),\n ];\n\n let compiled: string | undefined;\n if (!frontmatterOnly) {\n const compiledFile = await compileMdxJs(vfile, {\n outputFormat: \"function-body\",\n ...(this.mdxOptions ?? {}),\n ...(mdxOptions ?? {}),\n remarkPlugins,\n rehypePlugins,\n });\n compiled = compiledFile.value.toString();\n }\n\n const frontmatter =\n frontmatterSchema === undefined\n ? (vfile.data.matter ?? {})\n : frontmatterSchema.parse(vfile.data.matter ?? {});\n\n return {\n compiled,\n frontmatter: frontmatter as z.output<TFrontmatterSchema>,\n };\n }\n}\n"],"mappings":";;;;;;;;;AAwCA,IAAa,cAAb,MAAyB;CACvB;CACA;CACA;CAEA,YAAmB,aAAkC,EAAE,EAAE;AACvD,OAAK,aAAa;AAClB,OAAK,gBAAgB,CAAC,yBAAyB,gBAAgB;AAC/D,OAAK,gBAAgB,EAAE;;CAGzB,iBACE,QACA,SACa;AACb,MAAI,YAAY,KAAA,EACd,MAAK,cAAc,KAAK,OAAoB;MAE5C,MAAK,cAAc,KAAK,CAAC,QAAQ,QAAQ,CAAc;AAEzD,SAAO;;CAGT,iBACE,QACA,SACa;AACb,MAAI,YAAY,KAAA,EACd,MAAK,cAAc,KAAK,OAAoB;MAE5C,MAAK,cAAc,KAAK,CAAC,QAAQ,QAAQ,CAAc;AAEzD,SAAO;;CAGT,MAAa,QACX,QACA,EAAE,kBAAkB,OAAO,eAAkC,EAAE,EAC/D,mBACoD;EACpD,MAAM,QAAQ,IAAI,MAAM;GACtB,OAAO;GAEP,KAAK;GACL,MAAM;GACN,SAAS,EAAE;GACX,UAAU,EAAE;GACb,CAAC;AACF,SAAO,OAAO,EAAE,OAAO,MAAM,CAAC;EAE9B,MAAM,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAI,KAAK,YAAY,iBAAiB,EAAE;GACxC,GAAI,YAAY,iBAAiB,EAAE;GACpC;EACD,MAAM,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAI,KAAK,YAAY,iBAAiB,EAAE;GACxC,GAAI,YAAY,iBAAiB,EAAE;GACpC;EAED,IAAI;AACJ,MAAI,CAAC,gBAQH,aAPqB,MAAMA,QAAa,OAAO;GAC7C,cAAc;GACd,GAAI,KAAK,cAAc,EAAE;GACzB,GAAI,cAAc,EAAE;GACpB;GACA;GACD,CAAC,EACsB,MAAM,UAAU;EAG1C,MAAM,cACJ,sBAAsB,KAAA,IACjB,MAAM,KAAK,UAAU,EAAE,GACxB,kBAAkB,MAAM,MAAM,KAAK,UAAU,EAAE,CAAC;AAEtD,SAAO;GACL;GACa;GACd"}
|
|
1
|
+
{"version":3,"file":"compiler.mjs","names":["compileMdxJs"],"sources":["../src/compiler.ts"],"sourcesContent":["import {\n compile as compileMdxJs,\n type CompileOptions as MdxJsCompileOptions,\n} from \"@mdx-js/mdx\";\nimport remarkFrontmatterPlugin from \"remark-frontmatter\";\nimport remarkGfmPlugin from \"remark-gfm\";\nimport type { Pluggable, PluggableList, Plugin } from \"unified\";\nimport { VFile } from \"vfile\";\nimport { matter } from \"vfile-matter\";\nimport type { z } from \"zod\";\n\nimport type { HastNode } from \"./types\";\n\nexport { remarkFrontmatterPlugin, remarkGfmPlugin };\n\n/**\n * Represents the source content for an MDX document.\n */\nexport type MdxSource = string | Uint8Array;\n\n/**\n * Options for compiling an MDX document.\n */\nexport interface MdxCompileOptions {\n frontmatterOnly?: boolean | undefined;\n mdxOptions?: MdxJsCompileOptions;\n}\n\nexport interface MdxMessagePoint {\n line?: number | undefined;\n column?: number | undefined;\n offset?: number | undefined;\n}\n\nexport interface MdxMessagePlace {\n start?: MdxMessagePoint | undefined;\n end?: MdxMessagePoint | undefined;\n}\n\nexport interface MdxMessage {\n message: string;\n reason: string;\n source?: string | undefined;\n ruleId?: string | undefined;\n fatal?: boolean | undefined;\n line?: number | undefined;\n column?: number | undefined;\n place?: MdxMessagePlace | undefined;\n sourceLine?: string | undefined;\n snippet?: string | undefined;\n cause?: {\n name?: string | undefined;\n message: string;\n };\n}\n\ntype VFileLikeMessage = VFile[\"messages\"][number];\n\n/**\n * The result of compiling an MDX document.\n * Compiled content is optional, because sometimes we only need the frontmatter.\n */\nexport interface MdxArtifact<TFrontmatter = Record<string, unknown>> {\n compiled?: string | undefined;\n frontmatter: TFrontmatter;\n messages: MdxMessage[];\n}\n\nexport class MdxCompileError extends Error {\n public readonly reason: string;\n public readonly source?: string | undefined;\n public readonly ruleId?: string | undefined;\n public readonly line?: number | undefined;\n public readonly column?: number | undefined;\n public readonly place?: MdxMessagePlace | undefined;\n public readonly sourceLine?: string | undefined;\n public readonly snippet?: string | undefined;\n public readonly diagnostics: MdxMessage[];\n\n public constructor(\n reason: string,\n options: {\n source?: string | undefined;\n ruleId?: string | undefined;\n line?: number | undefined;\n column?: number | undefined;\n place?: MdxMessagePlace | undefined;\n sourceLine?: string | undefined;\n snippet?: string | undefined;\n diagnostics?: MdxMessage[] | undefined;\n cause?: unknown;\n } = {},\n ) {\n super(\n formatDiagnosticMessage(reason, {\n source: options.source,\n ruleId: options.ruleId,\n line: options.line,\n column: options.column,\n sourceLine: options.sourceLine,\n snippet: options.snippet,\n }),\n options.cause === undefined ? undefined : { cause: options.cause },\n );\n\n this.name = \"MdxCompileError\";\n this.reason = reason;\n this.source = options.source;\n this.ruleId = options.ruleId;\n this.line = options.line;\n this.column = options.column;\n this.place = options.place;\n this.sourceLine = options.sourceLine;\n this.snippet = options.snippet;\n this.diagnostics = options.diagnostics ?? [];\n }\n}\n\n/**\n * A reusable compiler for compiling MDX.\n */\nexport class MdxCompiler {\n private readonly mdxOptions: MdxJsCompileOptions;\n private readonly remarkPlugins: PluggableList;\n private readonly rehypePlugins: PluggableList;\n\n public constructor(mdxOptions: MdxJsCompileOptions = {}) {\n this.mdxOptions = mdxOptions;\n this.remarkPlugins = [remarkFrontmatterPlugin, remarkGfmPlugin];\n this.rehypePlugins = [];\n }\n\n public withRemarkPlugin<TOptions>(\n plugin: Plugin<[TOptions?], HastNode, HastNode>,\n options?: TOptions,\n ): MdxCompiler {\n if (options === undefined) {\n this.remarkPlugins.push(plugin as Pluggable);\n } else {\n this.remarkPlugins.push([plugin, options] as Pluggable);\n }\n return this;\n }\n\n public withRehypePlugin<TOptions>(\n plugin: Plugin<[TOptions?], HastNode, HastNode>,\n options?: TOptions,\n ): MdxCompiler {\n if (options === undefined) {\n this.rehypePlugins.push(plugin as Pluggable);\n } else {\n this.rehypePlugins.push([plugin, options] as Pluggable);\n }\n return this;\n }\n\n public async compile<TFrontmatterSchema extends z.ZodSchema>(\n source: MdxSource,\n { frontmatterOnly = false, mdxOptions }: MdxCompileOptions = {},\n frontmatterSchema?: TFrontmatterSchema,\n ): Promise<MdxArtifact<z.output<TFrontmatterSchema>>> {\n const sourceText = toSourceText(source);\n const vfile = new VFile({\n value: source,\n // Needed so vfile doesn't need to access fs.\n cwd: \"/\",\n path: \"/source.mdx\",\n });\n matter(vfile, { strip: true });\n\n const remarkPlugins = [\n ...this.remarkPlugins,\n ...(this.mdxOptions?.remarkPlugins ?? []),\n ...(mdxOptions?.remarkPlugins ?? []),\n ];\n const rehypePlugins = [\n ...this.rehypePlugins,\n ...(this.mdxOptions?.rehypePlugins ?? []),\n ...(mdxOptions?.rehypePlugins ?? []),\n ];\n\n let compiled: string | undefined;\n if (!frontmatterOnly) {\n try {\n const compiledFile = await compileMdxJs(vfile, {\n outputFormat: \"function-body\",\n ...(this.mdxOptions ?? {}),\n ...(mdxOptions ?? {}),\n remarkPlugins,\n rehypePlugins,\n });\n compiled = compiledFile.value.toString();\n } catch (error) {\n throw toMdxCompileError(error, sourceText, vfile.messages);\n }\n }\n\n const frontmatter =\n frontmatterSchema === undefined\n ? (vfile.data.matter ?? {})\n : (frontmatterSchema as z.ZodSchema).parse(vfile.data.matter ?? {});\n\n return {\n compiled,\n frontmatter: frontmatter as z.output<TFrontmatterSchema>,\n messages: normalizeMessages(vfile.messages, sourceText),\n };\n }\n}\n\nfunction toMdxCompileError(\n error: unknown,\n sourceText: string,\n diagnostics: readonly VFileLikeMessage[],\n): MdxCompileError {\n const details = getDiagnosticDetails(sourceText, getErrorPlace(error), error);\n\n return new MdxCompileError(getErrorReason(error), {\n source: getErrorField(error, \"source\"),\n ruleId: getErrorField(error, \"ruleId\"),\n line: details.line,\n column: details.column,\n place: details.place,\n sourceLine: details.sourceLine,\n snippet: details.snippet,\n diagnostics: normalizeMessages(diagnostics, sourceText),\n cause: error,\n });\n}\n\nfunction normalizeMessages(\n messages: readonly VFileLikeMessage[],\n sourceText: string,\n): MdxMessage[] {\n return messages.map((message) => {\n const details = getDiagnosticDetails(\n sourceText,\n toMessagePlace(message),\n message,\n );\n const reason = getErrorReason(message);\n const source = getErrorField(message, \"source\");\n const ruleId = getErrorField(message, \"ruleId\");\n const cause = getErrorCause(message);\n\n return {\n message: formatDiagnosticMessage(reason, {\n source,\n ruleId,\n line: details.line,\n column: details.column,\n sourceLine: details.sourceLine,\n snippet: details.snippet,\n causeMessage: cause?.message,\n }),\n reason,\n source,\n ruleId,\n fatal: typeof message.fatal === \"boolean\" ? message.fatal : undefined,\n line: details.line,\n column: details.column,\n place: details.place,\n sourceLine: details.sourceLine,\n snippet: details.snippet,\n cause,\n };\n });\n}\n\nfunction formatDiagnosticMessage(\n reason: string,\n options: {\n source?: string | undefined;\n ruleId?: string | undefined;\n line?: number | undefined;\n column?: number | undefined;\n sourceLine?: string | undefined;\n snippet?: string | undefined;\n causeMessage?: string | undefined;\n },\n): string {\n const origin =\n options.source === undefined\n ? undefined\n : options.ruleId === undefined\n ? options.source\n : `${options.source}:${options.ruleId}`;\n const location =\n options.line === undefined\n ? undefined\n : options.column === undefined\n ? `at ${options.line}`\n : `at ${options.line}:${options.column}`;\n\n const lines = [[reason, origin, location].filter(Boolean).join(\" \")];\n\n if (options.snippet !== undefined) {\n lines.push(`Source: ${options.snippet}`);\n }\n if (\n options.sourceLine !== undefined &&\n options.sourceLine !== options.snippet\n ) {\n lines.push(`Line: ${options.sourceLine}`);\n }\n if (\n options.causeMessage !== undefined &&\n options.causeMessage !== \"\" &&\n options.causeMessage !== reason\n ) {\n lines.push(`Cause: ${options.causeMessage}`);\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction getDiagnosticDetails(\n sourceText: string,\n place: MdxMessagePlace | undefined,\n error: unknown,\n): {\n line?: number | undefined;\n column?: number | undefined;\n place?: MdxMessagePlace | undefined;\n sourceLine?: string | undefined;\n snippet?: string | undefined;\n} {\n const line = place?.start?.line ?? getErrorNumberField(error, \"line\");\n const column = place?.start?.column ?? getErrorNumberField(error, \"column\");\n const normalizedPlace =\n line === undefined && column === undefined && place === undefined\n ? undefined\n : {\n start: {\n line,\n column,\n offset: place?.start?.offset,\n },\n end:\n place?.end === undefined\n ? undefined\n : {\n line: place.end.line,\n column: place.end.column,\n offset: place.end.offset,\n },\n };\n\n return {\n line,\n column,\n place: normalizedPlace,\n sourceLine: getSourceLine(sourceText, line),\n snippet: getSourceSnippet(sourceText, normalizedPlace),\n };\n}\n\nfunction getSourceLine(\n sourceText: string,\n line: number | undefined,\n): string | undefined {\n if (line === undefined || line < 1) {\n return undefined;\n }\n return sourceText.split(/\\r?\\n/u)[line - 1];\n}\n\nfunction getSourceSnippet(\n sourceText: string,\n place: MdxMessagePlace | undefined,\n): string | undefined {\n if (place?.start?.offset !== undefined && place.end?.offset !== undefined) {\n return sourceText.slice(place.start.offset, place.end.offset) || undefined;\n }\n\n if (place?.start?.line === undefined || place.start.column === undefined) {\n return undefined;\n }\n\n const lines = sourceText.split(/\\r?\\n/u);\n const startLineIndex = place.start.line - 1;\n const endLineIndex = (place.end?.line ?? place.start.line) - 1;\n\n if (startLineIndex < 0 || startLineIndex >= lines.length) {\n return undefined;\n }\n\n const selectedLines = lines.slice(startLineIndex, endLineIndex + 1);\n if (selectedLines.length === 0) {\n return undefined;\n }\n\n selectedLines[0] = selectedLines[0].slice(place.start.column - 1);\n\n const endColumn = place.end?.column;\n if (endColumn !== undefined) {\n const lastIndex = selectedLines.length - 1;\n selectedLines[lastIndex] = selectedLines[lastIndex].slice(0, endColumn - 1);\n }\n\n return selectedLines.join(\"\\n\") || undefined;\n}\n\nfunction getErrorPlace(error: unknown): MdxMessagePlace | undefined {\n if (typeof error !== \"object\" || error === null) {\n return undefined;\n }\n\n const candidate = error as {\n place?: unknown;\n position?: unknown;\n };\n\n return toPlace(candidate.place) ?? toPlace(candidate.position);\n}\n\nfunction toMessagePlace(\n message: VFileLikeMessage,\n): MdxMessagePlace | undefined {\n return toPlace(message.place);\n}\n\nfunction toPlace(value: unknown): MdxMessagePlace | undefined {\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const candidate = value as {\n start?: unknown;\n end?: unknown;\n line?: unknown;\n column?: unknown;\n offset?: unknown;\n };\n\n if (candidate.start !== undefined || candidate.end !== undefined) {\n return {\n start: toPoint(candidate.start),\n end: toPoint(candidate.end),\n };\n }\n\n const point = toPoint(candidate);\n return point === undefined ? undefined : { start: point };\n}\n\nfunction toPoint(value: unknown): MdxMessagePoint | undefined {\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const candidate = value as {\n line?: unknown;\n column?: unknown;\n offset?: unknown;\n };\n const line = typeof candidate.line === \"number\" ? candidate.line : undefined;\n const column =\n typeof candidate.column === \"number\" ? candidate.column : undefined;\n const offset =\n typeof candidate.offset === \"number\" ? candidate.offset : undefined;\n\n if (line === undefined && column === undefined && offset === undefined) {\n return undefined;\n }\n\n return { line, column, offset };\n}\n\nfunction getErrorReason(error: unknown): string {\n if (error instanceof Error && error.message !== \"\") {\n return error.message;\n }\n\n const reason = getErrorField(error, \"reason\");\n if (reason !== undefined && reason !== \"\") {\n return reason;\n }\n\n return String(error);\n}\n\nfunction getErrorCause(\n error: unknown,\n): { name?: string | undefined; message: string } | undefined {\n if (typeof error !== \"object\" || error === null || !(\"cause\" in error)) {\n return undefined;\n }\n\n const cause = (error as { cause?: unknown }).cause;\n if (cause instanceof Error) {\n return {\n name: cause.name,\n message: cause.message,\n };\n }\n if (typeof cause === \"string\" && cause !== \"\") {\n return {\n message: cause,\n };\n }\n\n return undefined;\n}\n\nfunction getErrorField(\n error: unknown,\n field: \"source\" | \"ruleId\" | \"reason\",\n): string | undefined {\n if (typeof error !== \"object\" || error === null || !(field in error)) {\n return undefined;\n }\n\n const value = (error as Record<string, unknown>)[field];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\nfunction getErrorNumberField(\n error: unknown,\n field: \"line\" | \"column\",\n): number | undefined {\n if (typeof error !== \"object\" || error === null || !(field in error)) {\n return undefined;\n }\n\n const value = (error as Record<string, unknown>)[field];\n return typeof value === \"number\" ? value : undefined;\n}\n\nfunction toSourceText(source: MdxSource): string {\n return typeof source === \"string\" ? source : new TextDecoder().decode(source);\n}\n"],"mappings":";;;;;;AAoEA,IAAa,kBAAb,cAAqC,MAAM;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YACE,QACA,UAUI,EAAE,EACN;AACA,QACE,wBAAwB,QAAQ;GAC9B,QAAQ,QAAQ;GAChB,QAAQ,QAAQ;GAChB,MAAM,QAAQ;GACd,QAAQ,QAAQ;GAChB,YAAY,QAAQ;GACpB,SAAS,QAAQ;GAClB,CAAC,EACF,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,OAAO,CACn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AAQ,EAAE,SAAS,OAC5D;CAGF,MAAM,QAAS,MAAkC;AACjD,QAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;;AAG7C,SAAS,aAAa,QAA2B;AAC/C,QAAO,OAAO,WAAW,WAAW,SAAS,IAAI,aAAa,CAAC,OAAO,OAAO"}
|
package/dist/mod.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HastElement as Element, HastNode as Node } from "./types.mjs";
|
|
2
|
-
import { MdxArtifact, MdxCompileOptions, MdxCompiler, MdxSource, remarkFrontmatterPlugin, remarkGfmPlugin } from "./compiler.mjs";
|
|
2
|
+
import { MdxArtifact, MdxCompileError, MdxCompileOptions, MdxCompiler, MdxMessage, MdxMessagePlace, MdxMessagePoint, MdxSource, remarkFrontmatterPlugin, remarkGfmPlugin } from "./compiler.mjs";
|
|
3
3
|
import { HeadingIdPluginOptions, headingIdPlugin } from "./plugins/heading-id/plugin.mjs";
|
|
4
4
|
import { removeImportsExportsPlugin } from "./plugins/remove-imports-exports.mjs";
|
|
5
5
|
import { SyntaxHighlightPluginOptions, syntaxHighlightPlugin } from "./plugins/syntax-highlight/plugin.mjs";
|
|
6
6
|
import { MdxTreeProcessor, treeProcessorPlugin } from "./plugins/tree-processor/plugin.mjs";
|
|
7
|
-
export { Element as HastElement, Node as HastNode, HeadingIdPluginOptions, MdxArtifact, MdxCompileOptions, MdxCompiler, MdxSource, MdxTreeProcessor, SyntaxHighlightPluginOptions, headingIdPlugin, remarkFrontmatterPlugin, remarkGfmPlugin, removeImportsExportsPlugin, syntaxHighlightPlugin, treeProcessorPlugin };
|
|
7
|
+
export { Element as HastElement, Node as HastNode, HeadingIdPluginOptions, MdxArtifact, MdxCompileError, MdxCompileOptions, MdxCompiler, MdxMessage, MdxMessagePlace, MdxMessagePoint, MdxSource, MdxTreeProcessor, SyntaxHighlightPluginOptions, headingIdPlugin, remarkFrontmatterPlugin, remarkGfmPlugin, removeImportsExportsPlugin, syntaxHighlightPlugin, treeProcessorPlugin };
|
package/dist/mod.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MdxCompiler, remarkFrontmatterPlugin, remarkGfmPlugin } from "./compiler.mjs";
|
|
1
|
+
import { MdxCompileError, MdxCompiler, remarkFrontmatterPlugin, remarkGfmPlugin } from "./compiler.mjs";
|
|
2
2
|
import { headingIdPlugin } from "./plugins/heading-id/plugin.mjs";
|
|
3
3
|
import { removeImportsExportsPlugin } from "./plugins/remove-imports-exports.mjs";
|
|
4
4
|
import { syntaxHighlightPlugin } from "./plugins/syntax-highlight/plugin.mjs";
|
|
5
5
|
import { treeProcessorPlugin } from "./plugins/tree-processor/plugin.mjs";
|
|
6
6
|
import "./plugins/mod.mjs";
|
|
7
|
-
export { MdxCompiler, headingIdPlugin, remarkFrontmatterPlugin, remarkGfmPlugin, removeImportsExportsPlugin, syntaxHighlightPlugin, treeProcessorPlugin };
|
|
7
|
+
export { MdxCompileError, MdxCompiler, headingIdPlugin, remarkFrontmatterPlugin, remarkGfmPlugin, removeImportsExportsPlugin, syntaxHighlightPlugin, treeProcessorPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temelj/mdx",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "MDX processing utilities.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"hast-util-to-string": "^3.0.1",
|
|
28
28
|
"remark-frontmatter": "^5.0.0",
|
|
29
29
|
"remark-gfm": "^4.0.1",
|
|
30
|
+
"remark-math": "^6.0.0",
|
|
30
31
|
"remark-parse": "^11.0.0",
|
|
32
|
+
"rehype-katex": "^7.0.1",
|
|
31
33
|
"shiki": "^4.0.2",
|
|
32
34
|
"unified": "^11.0.5",
|
|
33
35
|
"unist-util-remove": "^4.0.0",
|