@temelj/mdx 0.11.0 → 0.11.2
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 +56 -1
- package/dist/compiler.d.mts.map +1 -1
- package/dist/compiler.mjs +382 -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,33 @@ 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
|
+
sourcePointer?: string | undefined;
|
|
41
|
+
hint?: string | undefined;
|
|
42
|
+
cause?: {
|
|
43
|
+
name?: string | undefined;
|
|
44
|
+
message: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
20
47
|
/**
|
|
21
48
|
* The result of compiling an MDX document.
|
|
22
49
|
* Compiled content is optional, because sometimes we only need the frontmatter.
|
|
@@ -24,6 +51,34 @@ interface MdxCompileOptions {
|
|
|
24
51
|
interface MdxArtifact<TFrontmatter = Record<string, unknown>> {
|
|
25
52
|
compiled?: string | undefined;
|
|
26
53
|
frontmatter: TFrontmatter;
|
|
54
|
+
messages: MdxMessage[];
|
|
55
|
+
}
|
|
56
|
+
declare class MdxCompileError extends Error {
|
|
57
|
+
readonly reason: string;
|
|
58
|
+
readonly source?: string | undefined;
|
|
59
|
+
readonly ruleId?: string | undefined;
|
|
60
|
+
readonly line?: number | undefined;
|
|
61
|
+
readonly column?: number | undefined;
|
|
62
|
+
readonly place?: MdxMessagePlace | undefined;
|
|
63
|
+
readonly sourceLine?: string | undefined;
|
|
64
|
+
readonly snippet?: string | undefined;
|
|
65
|
+
readonly sourcePointer?: string | undefined;
|
|
66
|
+
readonly hint?: string | undefined;
|
|
67
|
+
readonly diagnostics: MdxMessage[];
|
|
68
|
+
constructor(reason: string, options?: {
|
|
69
|
+
source?: string | undefined;
|
|
70
|
+
ruleId?: string | undefined;
|
|
71
|
+
line?: number | undefined;
|
|
72
|
+
column?: number | undefined;
|
|
73
|
+
place?: MdxMessagePlace | undefined;
|
|
74
|
+
sourceLine?: string | undefined;
|
|
75
|
+
snippet?: string | undefined;
|
|
76
|
+
sourcePointer?: string | undefined;
|
|
77
|
+
hint?: string | undefined;
|
|
78
|
+
causeMessage?: string | undefined;
|
|
79
|
+
diagnostics?: MdxMessage[] | undefined;
|
|
80
|
+
cause?: unknown;
|
|
81
|
+
});
|
|
27
82
|
}
|
|
28
83
|
/**
|
|
29
84
|
* A reusable compiler for compiling MDX.
|
|
@@ -41,5 +96,5 @@ declare class MdxCompiler {
|
|
|
41
96
|
}?: MdxCompileOptions, frontmatterSchema?: TFrontmatterSchema): Promise<MdxArtifact<z.output<TFrontmatterSchema>>>;
|
|
42
97
|
}
|
|
43
98
|
//#endregion
|
|
44
|
-
export { MdxArtifact, MdxCompileOptions, MdxCompiler, MdxSource, remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
99
|
+
export { MdxArtifact, MdxCompileError, MdxCompileOptions, MdxCompiler, MdxMessage, MdxMessagePlace, MdxMessagePoint, MdxSource, remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
45
100
|
//# 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"],"mappings":";;;;;;;;;AAkBA;;KAAY,SAAA,YAAqB,UAAA;;;AAKjC;UAAiB,iBAAA;EACf,eAAA;EACA,UAAA,GAAa,cAAA;AAAA;;;;;
|
|
1
|
+
{"version":3,"file":"compiler.d.mts","names":[],"sources":["../src/compiler.ts"],"mappings":";;;;;;;;;AAkBA;;KAAY,SAAA,YAAqB,UAAA;;;AAKjC;UAAiB,iBAAA;EACf,eAAA;EACA,UAAA,GAAa,cAAA;AAAA;AAAA,UAGE,eAAA;EACf,IAAA;EACA,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,eAAA;EACf,KAAA,GAAQ,eAAA;EACR,GAAA,GAAM,eAAA;AAAA;AAAA,UAGS,UAAA;EACf,OAAA;EACA,MAAA;EACA,MAAA;EACA,MAAA;EACA,KAAA;EACA,IAAA;EACA,MAAA;EACA,KAAA,GAAQ,eAAA;EACR,UAAA;EACA,OAAA;EACA,aAAA;EACA,IAAA;EACA,KAAA;IACE,IAAA;IACA,OAAA;EAAA;AAAA;;;;;UAea,WAAA,gBAA2B,MAAA;EAC1C,QAAA;EACA,WAAA,EAAa,YAAA;EACb,QAAA,EAAU,UAAA;AAAA;AAAA,cAGC,eAAA,SAAwB,KAAA;EAAA,SACnB,MAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;EAAA,SACA,KAAA,GAAQ,eAAA;EAAA,SACR,UAAA;EAAA,SACA,OAAA;EAAA,SACA,aAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA,EAAa,UAAA;cAG3B,MAAA,UACA,OAAA;IACE,MAAA;IACA,MAAA;IACA,IAAA;IACA,MAAA;IACA,KAAA,GAAQ,eAAA;IACR,UAAA;IACA,OAAA;IACA,aAAA;IACA,IAAA;IACA,YAAA;IACA,WAAA,GAAc,UAAA;IACd,KAAA;EAAA;AAAA;;;;cAoCO,WAAA;EAAA,iBACM,UAAA;EAAA,iBACA,aAAA;EAAA,iBACA,aAAA;cAEE,UAAA,GAAY,cAAA;EAMxB,gBAAA,UAAA,CACL,MAAA,EAAQ,MAAA,EAAQ,QAAA,IAAY,IAAA,EAAU,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,44 @@ 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
|
+
sourcePointer;
|
|
17
|
+
hint;
|
|
18
|
+
diagnostics;
|
|
19
|
+
constructor(reason, options = {}) {
|
|
20
|
+
super(formatDiagnosticMessage(reason, {
|
|
21
|
+
source: options.source,
|
|
22
|
+
ruleId: options.ruleId,
|
|
23
|
+
line: options.line,
|
|
24
|
+
column: options.column,
|
|
25
|
+
sourceLine: options.sourceLine,
|
|
26
|
+
snippet: options.snippet,
|
|
27
|
+
sourcePointer: options.sourcePointer,
|
|
28
|
+
hint: options.hint,
|
|
29
|
+
causeMessage: options.causeMessage
|
|
30
|
+
}), options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
31
|
+
this.name = "MdxCompileError";
|
|
32
|
+
this.reason = reason;
|
|
33
|
+
this.source = options.source;
|
|
34
|
+
this.ruleId = options.ruleId;
|
|
35
|
+
this.line = options.line;
|
|
36
|
+
this.column = options.column;
|
|
37
|
+
this.place = options.place;
|
|
38
|
+
this.sourceLine = options.sourceLine;
|
|
39
|
+
this.snippet = options.snippet;
|
|
40
|
+
this.sourcePointer = options.sourcePointer;
|
|
41
|
+
this.hint = options.hint;
|
|
42
|
+
this.diagnostics = options.diagnostics ?? [];
|
|
43
|
+
}
|
|
44
|
+
};
|
|
7
45
|
/**
|
|
8
46
|
* A reusable compiler for compiling MDX.
|
|
9
47
|
*/
|
|
@@ -27,14 +65,14 @@ var MdxCompiler = class {
|
|
|
27
65
|
return this;
|
|
28
66
|
}
|
|
29
67
|
async compile(source, { frontmatterOnly = false, mdxOptions } = {}, frontmatterSchema) {
|
|
68
|
+
const sourceText = toSourceText(source);
|
|
30
69
|
const vfile = new VFile({
|
|
31
70
|
value: source,
|
|
32
71
|
cwd: "/",
|
|
33
|
-
path: "/"
|
|
34
|
-
message: {},
|
|
35
|
-
messages: {}
|
|
72
|
+
path: "/source.mdx"
|
|
36
73
|
});
|
|
37
74
|
matter(vfile, { strip: true });
|
|
75
|
+
const sourceContext = createDiagnosticSourceContext(sourceText, toSourceText(vfile.value));
|
|
38
76
|
const remarkPlugins = [
|
|
39
77
|
...this.remarkPlugins,
|
|
40
78
|
...this.mdxOptions?.remarkPlugins ?? [],
|
|
@@ -46,21 +84,353 @@ var MdxCompiler = class {
|
|
|
46
84
|
...mdxOptions?.rehypePlugins ?? []
|
|
47
85
|
];
|
|
48
86
|
let compiled;
|
|
49
|
-
if (!frontmatterOnly)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
87
|
+
if (!frontmatterOnly) try {
|
|
88
|
+
compiled = (await compile(vfile, {
|
|
89
|
+
outputFormat: "function-body",
|
|
90
|
+
...this.mdxOptions ?? {},
|
|
91
|
+
...mdxOptions ?? {},
|
|
92
|
+
remarkPlugins,
|
|
93
|
+
rehypePlugins
|
|
94
|
+
})).value.toString();
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw toMdxCompileError(error, sourceContext, vfile.messages);
|
|
97
|
+
}
|
|
56
98
|
const frontmatter = frontmatterSchema === void 0 ? vfile.data.matter ?? {} : frontmatterSchema.parse(vfile.data.matter ?? {});
|
|
57
99
|
return {
|
|
58
100
|
compiled,
|
|
59
|
-
frontmatter
|
|
101
|
+
frontmatter,
|
|
102
|
+
messages: normalizeMessages(vfile.messages, sourceContext)
|
|
60
103
|
};
|
|
61
104
|
}
|
|
62
105
|
};
|
|
106
|
+
function toMdxCompileError(error, sourceContext, diagnostics) {
|
|
107
|
+
const details = getDiagnosticDetails(sourceContext, getErrorPlace(error), error);
|
|
108
|
+
const cause = getErrorCause(error);
|
|
109
|
+
return new MdxCompileError(getErrorReason(error), {
|
|
110
|
+
source: getErrorField(error, "source"),
|
|
111
|
+
ruleId: getErrorField(error, "ruleId"),
|
|
112
|
+
line: details.line,
|
|
113
|
+
column: details.column,
|
|
114
|
+
place: details.place,
|
|
115
|
+
sourceLine: details.sourceLine,
|
|
116
|
+
snippet: details.snippet,
|
|
117
|
+
sourcePointer: details.sourcePointer,
|
|
118
|
+
hint: details.hint,
|
|
119
|
+
causeMessage: cause?.message,
|
|
120
|
+
diagnostics: normalizeMessages(diagnostics, sourceContext),
|
|
121
|
+
cause: error
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function normalizeMessages(messages, sourceContext) {
|
|
125
|
+
return messages.map((message) => {
|
|
126
|
+
const details = getDiagnosticDetails(sourceContext, toMessagePlace(message), message);
|
|
127
|
+
const reason = getErrorReason(message);
|
|
128
|
+
const source = getErrorField(message, "source");
|
|
129
|
+
const ruleId = getErrorField(message, "ruleId");
|
|
130
|
+
const cause = getErrorCause(message);
|
|
131
|
+
return {
|
|
132
|
+
message: formatDiagnosticMessage(reason, {
|
|
133
|
+
source,
|
|
134
|
+
ruleId,
|
|
135
|
+
line: details.line,
|
|
136
|
+
column: details.column,
|
|
137
|
+
sourceLine: details.sourceLine,
|
|
138
|
+
snippet: details.snippet,
|
|
139
|
+
sourcePointer: details.sourcePointer,
|
|
140
|
+
hint: details.hint,
|
|
141
|
+
causeMessage: cause?.message
|
|
142
|
+
}),
|
|
143
|
+
reason,
|
|
144
|
+
source,
|
|
145
|
+
ruleId,
|
|
146
|
+
fatal: typeof message.fatal === "boolean" ? message.fatal : void 0,
|
|
147
|
+
line: details.line,
|
|
148
|
+
column: details.column,
|
|
149
|
+
place: details.place,
|
|
150
|
+
sourceLine: details.sourceLine,
|
|
151
|
+
snippet: details.snippet,
|
|
152
|
+
sourcePointer: details.sourcePointer,
|
|
153
|
+
hint: details.hint,
|
|
154
|
+
cause
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function formatDiagnosticMessage(reason, options) {
|
|
159
|
+
const lines = [[
|
|
160
|
+
reason,
|
|
161
|
+
options.source === void 0 ? void 0 : options.ruleId === void 0 ? options.source : `${options.source}:${options.ruleId}`,
|
|
162
|
+
options.line === void 0 ? void 0 : options.column === void 0 ? `at ${options.line}` : `at ${options.line}:${options.column}`
|
|
163
|
+
].filter(Boolean).join(" ")];
|
|
164
|
+
if (options.snippet !== void 0) lines.push(`Source: ${options.snippet}`);
|
|
165
|
+
if (options.sourceLine !== void 0 && options.sourceLine !== options.snippet) {
|
|
166
|
+
lines.push(`Line: ${options.sourceLine}`);
|
|
167
|
+
if (options.sourcePointer !== void 0) lines.push(` ${options.sourcePointer}`);
|
|
168
|
+
}
|
|
169
|
+
if (options.causeMessage !== void 0 && options.causeMessage !== "" && options.causeMessage !== reason) lines.push(`Cause: ${options.causeMessage}`);
|
|
170
|
+
if (options.hint !== void 0) lines.push(`Hint: ${options.hint}`);
|
|
171
|
+
return lines.join("\n");
|
|
172
|
+
}
|
|
173
|
+
function getDiagnosticDetails(sourceContext, place, error) {
|
|
174
|
+
const compileLine = place?.start?.line ?? getErrorNumberField(error, "line");
|
|
175
|
+
let line = compileLine === void 0 ? void 0 : compileLine + sourceContext.lineOffset;
|
|
176
|
+
let column = place?.start?.column ?? getErrorNumberField(error, "column");
|
|
177
|
+
let normalizedPlace = mapPlaceToOriginalSource(place === void 0 && compileLine === void 0 && column === void 0 ? void 0 : {
|
|
178
|
+
start: {
|
|
179
|
+
line: compileLine,
|
|
180
|
+
column,
|
|
181
|
+
offset: place?.start?.offset
|
|
182
|
+
},
|
|
183
|
+
end: place?.end === void 0 ? void 0 : {
|
|
184
|
+
line: place.end.line,
|
|
185
|
+
column: place.end.column,
|
|
186
|
+
offset: place.end.offset
|
|
187
|
+
}
|
|
188
|
+
}, sourceContext.lineOffset);
|
|
189
|
+
let sourceLine = getSourceLine(sourceContext.originalSourceText, line);
|
|
190
|
+
let snippet = getSourceSnippet(sourceContext.originalSourceText, normalizedPlace);
|
|
191
|
+
let sourcePointer = getSourcePointer(column);
|
|
192
|
+
let hint;
|
|
193
|
+
const refinedExpressionContext = getMdxExpressionContext(sourceContext.originalSourceText, {
|
|
194
|
+
line,
|
|
195
|
+
column,
|
|
196
|
+
sourceLine,
|
|
197
|
+
snippet,
|
|
198
|
+
error
|
|
199
|
+
});
|
|
200
|
+
if (refinedExpressionContext !== void 0) {
|
|
201
|
+
line = refinedExpressionContext.line;
|
|
202
|
+
column = refinedExpressionContext.column;
|
|
203
|
+
sourceLine = refinedExpressionContext.sourceLine;
|
|
204
|
+
snippet = refinedExpressionContext.snippet;
|
|
205
|
+
sourcePointer = refinedExpressionContext.sourcePointer;
|
|
206
|
+
hint = refinedExpressionContext.hint;
|
|
207
|
+
normalizedPlace = {
|
|
208
|
+
start: {
|
|
209
|
+
line,
|
|
210
|
+
column,
|
|
211
|
+
offset: void 0
|
|
212
|
+
},
|
|
213
|
+
end: void 0
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
line,
|
|
218
|
+
column,
|
|
219
|
+
place: normalizedPlace,
|
|
220
|
+
sourceLine,
|
|
221
|
+
snippet,
|
|
222
|
+
sourcePointer,
|
|
223
|
+
hint
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function getMdxExpressionContext(sourceText, options) {
|
|
227
|
+
if (!shouldRefineMdxExpressionContext(options)) return;
|
|
228
|
+
const candidate = findSuspiciousBraceExpression(sourceText, options.line, options.column);
|
|
229
|
+
if (candidate === void 0) return;
|
|
230
|
+
return {
|
|
231
|
+
line: candidate.line,
|
|
232
|
+
column: candidate.column,
|
|
233
|
+
sourceLine: candidate.sourceLine,
|
|
234
|
+
snippet: candidate.snippet,
|
|
235
|
+
sourcePointer: getSourcePointer(candidate.column) ?? "^",
|
|
236
|
+
hint: getErrorCause(options.error)?.message === "Unexpected content after expression" ? "MDX treats `{...}` as JavaScript. If you meant literal braces in text, escape them or wrap the text in code." : void 0
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function shouldRefineMdxExpressionContext(options) {
|
|
240
|
+
const trimmedSourceLine = options.sourceLine?.trim();
|
|
241
|
+
return isMdxExpressionError(options.error) && getErrorCause(options.error)?.message === "Unexpected content after expression" && (options.sourceLine === void 0 || options.sourceLine.trim() === "" || options.snippet === void 0) && !(trimmedSourceLine?.startsWith("{") && trimmedSourceLine.endsWith("}"));
|
|
242
|
+
}
|
|
243
|
+
function getSourceLine(sourceText, line) {
|
|
244
|
+
if (line === void 0 || line < 1) return;
|
|
245
|
+
return sourceText.split(/\r?\n/u)[line - 1];
|
|
246
|
+
}
|
|
247
|
+
function getSourceSnippet(sourceText, place) {
|
|
248
|
+
if (place?.start?.offset !== void 0 && place.end?.offset !== void 0) return sourceText.slice(place.start.offset, place.end.offset) || void 0;
|
|
249
|
+
if (place?.start?.line === void 0 || place.start.column === void 0) return;
|
|
250
|
+
if (place.end === void 0) {
|
|
251
|
+
const line = sourceText.split(/\r?\n/u)[place.start.line - 1];
|
|
252
|
+
if (line === void 0) return;
|
|
253
|
+
const character = line.at(place.start.column - 1);
|
|
254
|
+
return character === void 0 || character.trim() === "" ? void 0 : character;
|
|
255
|
+
}
|
|
256
|
+
const lines = sourceText.split(/\r?\n/u);
|
|
257
|
+
const startLineIndex = place.start.line - 1;
|
|
258
|
+
const endLineIndex = (place.end?.line ?? place.start.line) - 1;
|
|
259
|
+
if (startLineIndex < 0 || startLineIndex >= lines.length) return;
|
|
260
|
+
const selectedLines = lines.slice(startLineIndex, endLineIndex + 1);
|
|
261
|
+
if (selectedLines.length === 0) return;
|
|
262
|
+
selectedLines[0] = selectedLines[0].slice(place.start.column - 1);
|
|
263
|
+
const endColumn = place.end?.column;
|
|
264
|
+
if (endColumn !== void 0) {
|
|
265
|
+
const lastIndex = selectedLines.length - 1;
|
|
266
|
+
selectedLines[lastIndex] = selectedLines[lastIndex].slice(0, endColumn - 1);
|
|
267
|
+
}
|
|
268
|
+
return selectedLines.join("\n") || void 0;
|
|
269
|
+
}
|
|
270
|
+
function getSourcePointer(column) {
|
|
271
|
+
if (column === void 0 || column < 1) return;
|
|
272
|
+
return `${" ".repeat(column - 1)}^`;
|
|
273
|
+
}
|
|
274
|
+
function mapPlaceToOriginalSource(place, lineOffset) {
|
|
275
|
+
if (place === void 0) return;
|
|
276
|
+
return {
|
|
277
|
+
start: mapPointToOriginalSource(place.start, lineOffset),
|
|
278
|
+
end: mapPointToOriginalSource(place.end, lineOffset)
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function mapPointToOriginalSource(point, lineOffset) {
|
|
282
|
+
if (point === void 0) return;
|
|
283
|
+
return {
|
|
284
|
+
line: point.line === void 0 ? void 0 : point.line + lineOffset,
|
|
285
|
+
column: point.column,
|
|
286
|
+
offset: lineOffset === 0 ? point.offset : void 0
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function findSuspiciousBraceExpression(sourceText, line, column) {
|
|
290
|
+
const lines = sourceText.split(/\r?\n/u);
|
|
291
|
+
const searchLines = getNearbyLineNumbers(line, lines.length, 2);
|
|
292
|
+
let bestMatch;
|
|
293
|
+
for (const lineNumber of searchLines) {
|
|
294
|
+
const sourceLine = lines[lineNumber - 1];
|
|
295
|
+
if (sourceLine === void 0 || sourceLine.trim() === "") continue;
|
|
296
|
+
const expression = findLineBraceExpression(sourceLine, lineNumber, column);
|
|
297
|
+
if (expression === void 0) continue;
|
|
298
|
+
const score = (line === void 0 ? 0 : Math.abs(lineNumber - line)) * 10 + expression.distance;
|
|
299
|
+
if (bestMatch === void 0 || score < bestMatch.score) bestMatch = {
|
|
300
|
+
...expression,
|
|
301
|
+
score
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return bestMatch;
|
|
305
|
+
}
|
|
306
|
+
function getNearbyLineNumbers(line, totalLines, radius) {
|
|
307
|
+
if (line === void 0) return Array.from({ length: totalLines }, (_, index) => index + 1);
|
|
308
|
+
const lineNumbers = [];
|
|
309
|
+
for (let distance = 0; distance <= radius; distance++) {
|
|
310
|
+
const before = line - distance;
|
|
311
|
+
if (before >= 1) lineNumbers.push(before);
|
|
312
|
+
if (distance === 0) continue;
|
|
313
|
+
const after = line + distance;
|
|
314
|
+
if (after <= totalLines) lineNumbers.push(after);
|
|
315
|
+
}
|
|
316
|
+
return lineNumbers;
|
|
317
|
+
}
|
|
318
|
+
function findLineBraceExpression(sourceLine, line, column) {
|
|
319
|
+
let bestMatch;
|
|
320
|
+
for (const match of sourceLine.matchAll(/\{[^{}\n]+\}/gu)) {
|
|
321
|
+
const braceStart = match.index;
|
|
322
|
+
if (braceStart === void 0) continue;
|
|
323
|
+
const expanded = expandBraceExpression(sourceLine, braceStart);
|
|
324
|
+
if (expanded === void 0) continue;
|
|
325
|
+
const distance = column === void 0 ? 0 : Math.abs(braceStart + 1 - column);
|
|
326
|
+
if (bestMatch === void 0 || distance < bestMatch.distance) bestMatch = {
|
|
327
|
+
line,
|
|
328
|
+
column: braceStart + 1,
|
|
329
|
+
sourceLine,
|
|
330
|
+
snippet: expanded,
|
|
331
|
+
distance
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return bestMatch;
|
|
335
|
+
}
|
|
336
|
+
function expandBraceExpression(sourceLine, braceStart) {
|
|
337
|
+
const braceEnd = sourceLine.indexOf("}", braceStart);
|
|
338
|
+
if (braceEnd === -1) return;
|
|
339
|
+
let start = braceStart;
|
|
340
|
+
while (start > 0 && /[A-Za-z0-9_]/u.test(sourceLine[start - 1])) start--;
|
|
341
|
+
let end = braceEnd + 1;
|
|
342
|
+
while (end < sourceLine.length) {
|
|
343
|
+
while (end < sourceLine.length && /[A-Za-z0-9_]/u.test(sourceLine[end])) end++;
|
|
344
|
+
if (sourceLine[end] !== "{") break;
|
|
345
|
+
const chainedEnd = sourceLine.indexOf("}", end);
|
|
346
|
+
if (chainedEnd === -1) break;
|
|
347
|
+
end = chainedEnd + 1;
|
|
348
|
+
}
|
|
349
|
+
return sourceLine.slice(start, end) || void 0;
|
|
350
|
+
}
|
|
351
|
+
function isMdxExpressionError(error) {
|
|
352
|
+
return getErrorField(error, "source") === "micromark-extension-mdx-expression" && getErrorField(error, "ruleId") === "acorn";
|
|
353
|
+
}
|
|
354
|
+
function createDiagnosticSourceContext(originalSourceText, compileSourceText) {
|
|
355
|
+
return {
|
|
356
|
+
originalSourceText,
|
|
357
|
+
lineOffset: getSourceLineOffset(originalSourceText, compileSourceText)
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function getSourceLineOffset(originalSourceText, compileSourceText) {
|
|
361
|
+
const originalLines = originalSourceText.split(/\r?\n/u);
|
|
362
|
+
const compileLines = compileSourceText.split(/\r?\n/u);
|
|
363
|
+
const maxOffset = originalLines.length - compileLines.length;
|
|
364
|
+
for (let offset = 0; offset <= maxOffset; offset++) {
|
|
365
|
+
let isMatch = true;
|
|
366
|
+
for (let index = 0; index < compileLines.length; index++) if (originalLines[offset + index] !== compileLines[index]) {
|
|
367
|
+
isMatch = false;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
if (isMatch) return offset;
|
|
371
|
+
}
|
|
372
|
+
return maxOffset > 0 ? maxOffset : 0;
|
|
373
|
+
}
|
|
374
|
+
function getErrorPlace(error) {
|
|
375
|
+
if (typeof error !== "object" || error === null) return;
|
|
376
|
+
const candidate = error;
|
|
377
|
+
return toPlace(candidate.place) ?? toPlace(candidate.position);
|
|
378
|
+
}
|
|
379
|
+
function toMessagePlace(message) {
|
|
380
|
+
return toPlace(message.place);
|
|
381
|
+
}
|
|
382
|
+
function toPlace(value) {
|
|
383
|
+
if (typeof value !== "object" || value === null) return;
|
|
384
|
+
const candidate = value;
|
|
385
|
+
if (candidate.start !== void 0 || candidate.end !== void 0) return {
|
|
386
|
+
start: toPoint(candidate.start),
|
|
387
|
+
end: toPoint(candidate.end)
|
|
388
|
+
};
|
|
389
|
+
const point = toPoint(candidate);
|
|
390
|
+
return point === void 0 ? void 0 : { start: point };
|
|
391
|
+
}
|
|
392
|
+
function toPoint(value) {
|
|
393
|
+
if (typeof value !== "object" || value === null) return;
|
|
394
|
+
const candidate = value;
|
|
395
|
+
const line = typeof candidate.line === "number" ? candidate.line : void 0;
|
|
396
|
+
const column = typeof candidate.column === "number" ? candidate.column : void 0;
|
|
397
|
+
const offset = typeof candidate.offset === "number" ? candidate.offset : void 0;
|
|
398
|
+
if (line === void 0 && column === void 0 && offset === void 0) return;
|
|
399
|
+
return {
|
|
400
|
+
line,
|
|
401
|
+
column,
|
|
402
|
+
offset
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function getErrorReason(error) {
|
|
406
|
+
if (error instanceof Error && error.message !== "") return error.message;
|
|
407
|
+
const reason = getErrorField(error, "reason");
|
|
408
|
+
if (reason !== void 0 && reason !== "") return reason;
|
|
409
|
+
return String(error);
|
|
410
|
+
}
|
|
411
|
+
function getErrorCause(error) {
|
|
412
|
+
if (typeof error !== "object" || error === null || !("cause" in error)) return;
|
|
413
|
+
const cause = error.cause;
|
|
414
|
+
if (cause instanceof Error) return {
|
|
415
|
+
name: cause.name,
|
|
416
|
+
message: cause.message
|
|
417
|
+
};
|
|
418
|
+
if (typeof cause === "string" && cause !== "") return { message: cause };
|
|
419
|
+
}
|
|
420
|
+
function getErrorField(error, field) {
|
|
421
|
+
if (typeof error !== "object" || error === null || !(field in error)) return;
|
|
422
|
+
const value = error[field];
|
|
423
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
424
|
+
}
|
|
425
|
+
function getErrorNumberField(error, field) {
|
|
426
|
+
if (typeof error !== "object" || error === null || !(field in error)) return;
|
|
427
|
+
const value = error[field];
|
|
428
|
+
return typeof value === "number" ? value : void 0;
|
|
429
|
+
}
|
|
430
|
+
function toSourceText(source) {
|
|
431
|
+
return typeof source === "string" ? source : new TextDecoder().decode(source);
|
|
432
|
+
}
|
|
63
433
|
//#endregion
|
|
64
|
-
export { MdxCompiler, remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
434
|
+
export { MdxCompileError, MdxCompiler, remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
65
435
|
|
|
66
436
|
//# 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 sourcePointer?: string | undefined;\n hint?: string | undefined;\n cause?: {\n name?: string | undefined;\n message: string;\n };\n}\n\ntype VFileLikeMessage = VFile[\"messages\"][number];\n\ninterface MdxDiagnosticSourceContext {\n originalSourceText: string;\n lineOffset: number;\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 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 sourcePointer?: string | undefined;\n public readonly hint?: 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 sourcePointer?: string | undefined;\n hint?: string | undefined;\n causeMessage?: 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 sourcePointer: options.sourcePointer,\n hint: options.hint,\n causeMessage: options.causeMessage,\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.sourcePointer = options.sourcePointer;\n this.hint = options.hint;\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 const compileSourceText = toSourceText(vfile.value as MdxSource);\n const sourceContext = createDiagnosticSourceContext(\n sourceText,\n compileSourceText,\n );\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, sourceContext, 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, sourceContext),\n };\n }\n}\n\nfunction toMdxCompileError(\n error: unknown,\n sourceContext: MdxDiagnosticSourceContext,\n diagnostics: readonly VFileLikeMessage[],\n): MdxCompileError {\n const details = getDiagnosticDetails(\n sourceContext,\n getErrorPlace(error),\n error,\n );\n const cause = getErrorCause(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 sourcePointer: details.sourcePointer,\n hint: details.hint,\n causeMessage: cause?.message,\n diagnostics: normalizeMessages(diagnostics, sourceContext),\n cause: error,\n });\n}\n\nfunction normalizeMessages(\n messages: readonly VFileLikeMessage[],\n sourceContext: MdxDiagnosticSourceContext,\n): MdxMessage[] {\n return messages.map((message) => {\n const details = getDiagnosticDetails(\n sourceContext,\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 sourcePointer: details.sourcePointer,\n hint: details.hint,\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 sourcePointer: details.sourcePointer,\n hint: details.hint,\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 sourcePointer?: string | undefined;\n hint?: 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 if (options.sourcePointer !== undefined) {\n lines.push(` ${options.sourcePointer}`);\n }\n }\n if (\n options.causeMessage !== undefined &&\n options.causeMessage !== \"\" &&\n options.causeMessage !== reason\n ) {\n lines.push(`Cause: ${options.causeMessage}`);\n }\n if (options.hint !== undefined) {\n lines.push(`Hint: ${options.hint}`);\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction getDiagnosticDetails(\n sourceContext: MdxDiagnosticSourceContext,\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 sourcePointer?: string | undefined;\n hint?: string | undefined;\n} {\n const compileLine = place?.start?.line ?? getErrorNumberField(error, \"line\");\n let line =\n compileLine === undefined\n ? undefined\n : compileLine + sourceContext.lineOffset;\n let column = place?.start?.column ?? getErrorNumberField(error, \"column\");\n let normalizedPlace = mapPlaceToOriginalSource(\n place === undefined && compileLine === undefined && column === undefined\n ? undefined\n : {\n start: {\n line: compileLine,\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 sourceContext.lineOffset,\n );\n let sourceLine = getSourceLine(sourceContext.originalSourceText, line);\n let snippet = getSourceSnippet(\n sourceContext.originalSourceText,\n normalizedPlace,\n );\n let sourcePointer = getSourcePointer(column);\n let hint: string | undefined;\n\n const refinedExpressionContext = getMdxExpressionContext(\n sourceContext.originalSourceText,\n {\n line,\n column,\n sourceLine,\n snippet,\n error,\n },\n );\n\n if (refinedExpressionContext !== undefined) {\n line = refinedExpressionContext.line;\n column = refinedExpressionContext.column;\n sourceLine = refinedExpressionContext.sourceLine;\n snippet = refinedExpressionContext.snippet;\n sourcePointer = refinedExpressionContext.sourcePointer;\n hint = refinedExpressionContext.hint;\n normalizedPlace = {\n start: {\n line,\n column,\n offset: undefined,\n },\n end: undefined,\n };\n }\n\n return {\n line,\n column,\n place: normalizedPlace,\n sourceLine,\n snippet,\n sourcePointer,\n hint,\n };\n}\n\nfunction getMdxExpressionContext(\n sourceText: string,\n options: {\n line?: number | undefined;\n column?: number | undefined;\n sourceLine?: string | undefined;\n snippet?: string | undefined;\n error: unknown;\n },\n):\n | {\n line: number;\n column: number;\n sourceLine: string;\n snippet: string;\n sourcePointer: string;\n hint?: string | undefined;\n }\n | undefined {\n if (!shouldRefineMdxExpressionContext(options)) {\n return undefined;\n }\n\n const candidate = findSuspiciousBraceExpression(\n sourceText,\n options.line,\n options.column,\n );\n if (candidate === undefined) {\n return undefined;\n }\n\n return {\n line: candidate.line,\n column: candidate.column,\n sourceLine: candidate.sourceLine,\n snippet: candidate.snippet,\n sourcePointer: getSourcePointer(candidate.column) ?? \"^\",\n hint:\n getErrorCause(options.error)?.message ===\n \"Unexpected content after expression\"\n ? \"MDX treats `{...}` as JavaScript. If you meant literal braces in text, escape them or wrap the text in code.\"\n : undefined,\n };\n}\n\nfunction shouldRefineMdxExpressionContext(options: {\n sourceLine?: string | undefined;\n snippet?: string | undefined;\n error: unknown;\n}): boolean {\n const trimmedSourceLine = options.sourceLine?.trim();\n\n return (\n isMdxExpressionError(options.error) &&\n getErrorCause(options.error)?.message ===\n \"Unexpected content after expression\" &&\n (options.sourceLine === undefined ||\n options.sourceLine.trim() === \"\" ||\n options.snippet === undefined) &&\n !(trimmedSourceLine?.startsWith(\"{\") && trimmedSourceLine.endsWith(\"}\"))\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 if (place.end === undefined) {\n const lines = sourceText.split(/\\r?\\n/u);\n const line = lines[place.start.line - 1];\n if (line === undefined) {\n return undefined;\n }\n\n const character = line.at(place.start.column - 1);\n return character === undefined || character.trim() === \"\"\n ? undefined\n : character;\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 getSourcePointer(column: number | undefined): string | undefined {\n if (column === undefined || column < 1) {\n return undefined;\n }\n\n return `${\" \".repeat(column - 1)}^`;\n}\n\nfunction mapPlaceToOriginalSource(\n place: MdxMessagePlace | undefined,\n lineOffset: number,\n): MdxMessagePlace | undefined {\n if (place === undefined) {\n return undefined;\n }\n\n return {\n start: mapPointToOriginalSource(place.start, lineOffset),\n end: mapPointToOriginalSource(place.end, lineOffset),\n };\n}\n\nfunction mapPointToOriginalSource(\n point: MdxMessagePoint | undefined,\n lineOffset: number,\n): MdxMessagePoint | undefined {\n if (point === undefined) {\n return undefined;\n }\n\n return {\n line: point.line === undefined ? undefined : point.line + lineOffset,\n column: point.column,\n offset: lineOffset === 0 ? point.offset : undefined,\n };\n}\n\nfunction findSuspiciousBraceExpression(\n sourceText: string,\n line: number | undefined,\n column: number | undefined,\n):\n | {\n line: number;\n column: number;\n sourceLine: string;\n snippet: string;\n }\n | undefined {\n const lines = sourceText.split(/\\r?\\n/u);\n const searchLines = getNearbyLineNumbers(line, lines.length, 2);\n let bestMatch:\n | {\n line: number;\n column: number;\n sourceLine: string;\n snippet: string;\n score: number;\n }\n | undefined;\n\n for (const lineNumber of searchLines) {\n const sourceLine = lines[lineNumber - 1];\n if (sourceLine === undefined || sourceLine.trim() === \"\") {\n continue;\n }\n\n const expression = findLineBraceExpression(sourceLine, lineNumber, column);\n if (expression === undefined) {\n continue;\n }\n\n const lineDistance = line === undefined ? 0 : Math.abs(lineNumber - line);\n const score = lineDistance * 10 + expression.distance;\n\n if (bestMatch === undefined || score < bestMatch.score) {\n bestMatch = {\n ...expression,\n score,\n };\n }\n }\n\n return bestMatch;\n}\n\nfunction getNearbyLineNumbers(\n line: number | undefined,\n totalLines: number,\n radius: number,\n): number[] {\n if (line === undefined) {\n return Array.from({ length: totalLines }, (_, index) => index + 1);\n }\n\n const lineNumbers: number[] = [];\n for (let distance = 0; distance <= radius; distance++) {\n const before = line - distance;\n if (before >= 1) {\n lineNumbers.push(before);\n }\n\n if (distance === 0) {\n continue;\n }\n\n const after = line + distance;\n if (after <= totalLines) {\n lineNumbers.push(after);\n }\n }\n\n return lineNumbers;\n}\n\nfunction findLineBraceExpression(\n sourceLine: string,\n line: number,\n column: number | undefined,\n):\n | {\n line: number;\n column: number;\n sourceLine: string;\n snippet: string;\n distance: number;\n }\n | undefined {\n let bestMatch:\n | {\n line: number;\n column: number;\n sourceLine: string;\n snippet: string;\n distance: number;\n }\n | undefined;\n\n for (const match of sourceLine.matchAll(/\\{[^{}\\n]+\\}/gu)) {\n const braceStart = match.index;\n if (braceStart === undefined) {\n continue;\n }\n\n const expanded = expandBraceExpression(sourceLine, braceStart);\n if (expanded === undefined) {\n continue;\n }\n\n const distance =\n column === undefined ? 0 : Math.abs(braceStart + 1 - column);\n if (bestMatch === undefined || distance < bestMatch.distance) {\n bestMatch = {\n line,\n column: braceStart + 1,\n sourceLine,\n snippet: expanded,\n distance,\n };\n }\n }\n\n return bestMatch;\n}\n\nfunction expandBraceExpression(\n sourceLine: string,\n braceStart: number,\n): string | undefined {\n const braceEnd = sourceLine.indexOf(\"}\", braceStart);\n if (braceEnd === -1) {\n return undefined;\n }\n\n let start = braceStart;\n while (start > 0 && /[A-Za-z0-9_]/u.test(sourceLine[start - 1])) {\n start--;\n }\n\n let end = braceEnd + 1;\n while (end < sourceLine.length) {\n while (end < sourceLine.length && /[A-Za-z0-9_]/u.test(sourceLine[end])) {\n end++;\n }\n\n if (sourceLine[end] !== \"{\") {\n break;\n }\n\n const chainedEnd = sourceLine.indexOf(\"}\", end);\n if (chainedEnd === -1) {\n break;\n }\n end = chainedEnd + 1;\n }\n\n return sourceLine.slice(start, end) || undefined;\n}\n\nfunction isMdxExpressionError(error: unknown): boolean {\n return (\n getErrorField(error, \"source\") === \"micromark-extension-mdx-expression\" &&\n getErrorField(error, \"ruleId\") === \"acorn\"\n );\n}\n\nfunction createDiagnosticSourceContext(\n originalSourceText: string,\n compileSourceText: string,\n): MdxDiagnosticSourceContext {\n return {\n originalSourceText,\n lineOffset: getSourceLineOffset(originalSourceText, compileSourceText),\n };\n}\n\nfunction getSourceLineOffset(\n originalSourceText: string,\n compileSourceText: string,\n): number {\n const originalLines = originalSourceText.split(/\\r?\\n/u);\n const compileLines = compileSourceText.split(/\\r?\\n/u);\n const maxOffset = originalLines.length - compileLines.length;\n\n for (let offset = 0; offset <= maxOffset; offset++) {\n let isMatch = true;\n for (let index = 0; index < compileLines.length; index++) {\n if (originalLines[offset + index] !== compileLines[index]) {\n isMatch = false;\n break;\n }\n }\n\n if (isMatch) {\n return offset;\n }\n }\n\n return maxOffset > 0 ? maxOffset : 0;\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":";;;;;;AA2EA,IAAa,kBAAb,cAAqC,MAAM;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YACE,QACA,UAaI,EAAE,EACN;AACA,QACE,wBAAwB,QAAQ;GAC9B,QAAQ,QAAQ;GAChB,QAAQ,QAAQ;GAChB,MAAM,QAAQ;GACd,QAAQ,QAAQ;GAChB,YAAY,QAAQ;GACpB,SAAS,QAAQ;GACjB,eAAe,QAAQ;GACvB,MAAM,QAAQ;GACd,cAAc,QAAQ;GACvB,CAAC,EACF,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,OAAO,CACnE;AAED,OAAK,OAAO;AACZ,OAAK,SAAS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AU,SAAS,KAAA;CAC5D,MAAM,SACJ,OAAO,UAAU,WAAW,WAAW,UAAU,SAAS,KAAA;AAE5D,KAAI,SAAS,KAAA,KAAa,WAAW,KAAA,KAAa,WAAW,KAAA,EAC3D;AAGF,QAAO;EAAE;EAAM;EAAQ;EAAQ;;AAGjC,SAAS,eAAe,OAAwB;AAC9C,KAAI,iBAAiB,SAAS,MAAM,YAAY,GAC9C,QAAO,MAAM;CAGf,MAAM,SAAS,cAAc,OAAO,SAAS;AAC7C,KAAI,WAAW,KAAA,KAAa,WAAW,GACrC,QAAO;AAGT,QAAO,OAAO,MAAM;;AAGtB,SAAS,cACP,OAC4D;AAC5D,KAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,WAAW,OAC9D;CAGF,MAAM,QAAS,MAA8B;AAC7C,KAAI,iBAAiB,MACnB,QAAO;EACL,MAAM,MAAM;EACZ,SAAS,MAAM;EAChB;AAEH,KAAI,OAAO,UAAU,YAAY,UAAU,GACzC,QAAO,EACL,SAAS,OACV;;AAML,SAAS,cACP,OACA,OACoB;AACpB,KAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,SAAS,OAC5D;CAGF,MAAM,QAAS,MAAkC;AACjD,QAAO,OAAO,UAAU,YAAY,UAAU,KAAK,QAAQ,KAAA;;AAG7D,SAAS,oBACP,OACA,OACoB;AACpB,KAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,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.2",
|
|
4
4
|
"description": "MDX processing utilities.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
"github-slugger": "^2.0.0",
|
|
26
26
|
"hast": "^1.0.0",
|
|
27
27
|
"hast-util-to-string": "^3.0.1",
|
|
28
|
+
"rehype-katex": "^7.0.1",
|
|
28
29
|
"remark-frontmatter": "^5.0.0",
|
|
29
30
|
"remark-gfm": "^4.0.1",
|
|
31
|
+
"remark-math": "^6.0.0",
|
|
30
32
|
"remark-parse": "^11.0.0",
|
|
31
33
|
"shiki": "^4.0.2",
|
|
32
34
|
"unified": "^11.0.5",
|