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.
Files changed (2) hide show
  1. package/dist/index.js +16 -4
  2. 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
- * Compound rule helpers for expanding rule content.
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
- subruleContent.push(await getRuleContent(subrule, subruleOptions ?? {}, context));
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-mdat",
3
- "version": "2.0.0-preview.2",
3
+ "version": "2.0.0-preview.3",
4
4
  "description": "A remark plugin implementing the Markdown Autophagic Template (MDAT) system.",
5
5
  "keywords": [
6
6
  "mdat",