remark-mdat 2.0.0-preview.2 → 2.0.0-preview.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -276,15 +276,25 @@ const keywordSchema = z.string().check(z.refine((key) => !/^[/*#]/.test(key), {
|
|
|
276
276
|
const rulesSchema = z.record(keywordSchema, ruleSchema).describe("MDAT Rules");
|
|
277
277
|
const normalizedRulesSchema = z.record(keywordSchema, normalizedRuleSchema).describe("MDAT Rules");
|
|
278
278
|
/**
|
|
279
|
-
*
|
|
279
|
+
* Expand rule content. For compound rules (content arrays), individual
|
|
280
|
+
* sub-rule failures are reported via `onWarning` and skipped. The entire
|
|
281
|
+
* expansion only fails if every sub-rule fails.
|
|
280
282
|
*/
|
|
281
|
-
async function getRuleContent(rule, options, context) {
|
|
283
|
+
async function getRuleContent(rule, options, context, onWarning) {
|
|
282
284
|
if (Array.isArray(rule.content)) {
|
|
283
285
|
const subruleContent = [];
|
|
286
|
+
const errors = [];
|
|
284
287
|
for (const [index, subrule] of rule.content.entries()) {
|
|
285
288
|
const subruleOptions = Array.isArray(options) ? options.at(index) : void 0;
|
|
286
|
-
|
|
289
|
+
try {
|
|
290
|
+
subruleContent.push(await getRuleContent(subrule, subruleOptions ?? {}, context, onWarning));
|
|
291
|
+
} catch (error) {
|
|
292
|
+
const message = error instanceof Error ? error.cause instanceof Error ? error.cause.message : error.message : String(error);
|
|
293
|
+
onWarning?.(`Sub-rule ${String(index)} failed: ${message}`);
|
|
294
|
+
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
295
|
+
}
|
|
287
296
|
}
|
|
297
|
+
if (subruleContent.length === 0) throw new AggregateError(errors, "All sub-rules failed in compound rule");
|
|
288
298
|
return subruleContent.join("\n\n");
|
|
289
299
|
}
|
|
290
300
|
try {
|
|
@@ -363,7 +373,9 @@ async function mdatExpand(tree, file, rules) {
|
|
|
363
373
|
const rule = normalizedRules[keyword];
|
|
364
374
|
let newMarkdownString = "";
|
|
365
375
|
try {
|
|
366
|
-
newMarkdownString = await getRuleContent(rule, options, context)
|
|
376
|
+
newMarkdownString = await getRuleContent(rule, options, context, (warning) => {
|
|
377
|
+
saveLog(file, "warn", "expand", `${html}: ${warning}`, node);
|
|
378
|
+
});
|
|
367
379
|
if (newMarkdownString.trim() === "") saveLog(file, "error", "expand", `Got empty content when expanding ${html}`, node);
|
|
368
380
|
} catch (error) {
|
|
369
381
|
if (error instanceof Error) {
|