remark-mdat 2.0.2 → 2.1.0

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.d.ts CHANGED
@@ -118,15 +118,26 @@ declare function getSoleRule<T extends NormalizedRules | Rules>(rules: T): T[key
118
118
  declare function getSoleRuleKey<T extends NormalizedRules | Rules>(rules: T): keyof T;
119
119
  //#endregion
120
120
  //#region src/lib/mdast-utils/mdast-util-mdat.d.ts
121
- /** Mdast utility that splits, cleans, and expands all mdat comments in the tree. */
121
+ /**
122
+ * Mdast utility that splits, collapses, and then re-expands all mdat comments
123
+ * in the tree.
124
+ */
122
125
  declare function mdat(tree: Root, file: VFile, rules: NormalizedRules | Rules): Promise<void>;
123
126
  //#endregion
124
- //#region src/lib/mdast-utils/mdast-util-mdat-clean.d.ts
127
+ //#region src/lib/mdast-utils/mdast-util-mdat-collapse.d.ts
125
128
  /**
126
129
  * Collapses any expanded mdat comments, effectively resetting the document to
127
- * its pre-expansion state. No-op if no mdat comments are found.
130
+ * its pre-expansion state, preserving the original comments. No-op if no mdat
131
+ * comments are found.
132
+ */
133
+ declare function mdatCollapse(tree: Root, file: VFile): void;
134
+ //#endregion
135
+ //#region src/lib/mdast-utils/mdast-util-mdat-clean.d.ts
136
+ /**
137
+ * @deprecated Use {@link mdatCollapse} instead. This alias will be removed in a
138
+ * future major version.
128
139
  */
129
- declare function mdatClean(tree: Root, file: VFile): void;
140
+ declare const mdatClean: typeof mdatCollapse;
130
141
  //#endregion
131
142
  //#region src/lib/mdast-utils/mdast-util-mdat-expand.d.ts
132
143
  /**
@@ -141,6 +152,14 @@ declare function mdatExpand(tree: Root, file: VFile, rules: NormalizedRules | Ru
141
152
  */
142
153
  declare function mdatSplit(tree: Root, file: VFile): void;
143
154
  //#endregion
155
+ //#region src/lib/mdast-utils/mdast-util-mdat-strip.d.ts
156
+ /**
157
+ * Strips all mdat comment nodes (both opening and closing) from the tree,
158
+ * preserving any content between them. Code-style comments (`//`, `#`, `/*`)
159
+ * are left untouched.
160
+ */
161
+ declare function mdatStrip(tree: Root, _file: VFile): void;
162
+ //#endregion
144
163
  //#region src/lib/mdat/log.d.ts
145
164
  /**
146
165
  * Set the logger instance for the module.
@@ -185,4 +204,4 @@ declare const optionsSchema: z.ZodObject<{
185
204
  */
186
205
  declare const remarkMdat: Plugin<[Options?], Root>;
187
206
  //#endregion
188
- export { type MdatFileReport, type MdatMessage, type NormalizedRule, type NormalizedRules, type Options, type Rule, type RuleContext, type Rules, type SimplifyDeep, remarkMdat as default, getMdatReports, getSoleRule, getSoleRuleKey, mdat, mdatClean, mdatExpand, mdatSplit, optionsSchema, reporterMdat, rulesSchema, setLogger };
207
+ export { type MdatFileReport, type MdatMessage, type NormalizedRule, type NormalizedRules, type Options, type Rule, type RuleContext, type Rules, type SimplifyDeep, remarkMdat as default, getMdatReports, getSoleRule, getSoleRuleKey, mdat, mdatClean, mdatCollapse, mdatExpand, mdatSplit, mdatStrip, optionsSchema, reporterMdat, rulesSchema, setLogger };
package/dist/index.js CHANGED
@@ -173,12 +173,13 @@ function isComment(text) {
173
173
  return trimmed.startsWith("<!--") && trimmed.endsWith("-->");
174
174
  }
175
175
  //#endregion
176
- //#region src/lib/mdast-utils/mdast-util-mdat-clean.ts
176
+ //#region src/lib/mdast-utils/mdast-util-mdat-collapse.ts
177
177
  /**
178
178
  * Collapses any expanded mdat comments, effectively resetting the document to
179
- * its pre-expansion state. No-op if no mdat comments are found.
179
+ * its pre-expansion state, preserving the original comments. No-op if no mdat
180
+ * comments are found.
180
181
  */
181
- function mdatClean(tree, file) {
182
+ function mdatCollapse(tree, file) {
182
183
  let lastOpenMarker;
183
184
  visit(tree, "html", (node, index, parent) => {
184
185
  if (parent === void 0 || index === void 0) return CONTINUE;
@@ -190,15 +191,15 @@ function mdatClean(tree, file) {
190
191
  }
191
192
  if (marker.type === "close") {
192
193
  if (lastOpenMarker === void 0) {
193
- saveLog(file, "error", "clean", "Found closing marker without opening marker", node);
194
+ saveLog(file, "error", "collapse", "Found closing marker without opening marker", node);
194
195
  return CONTINUE;
195
196
  }
196
197
  if (lastOpenMarker.parent !== marker.parent) {
197
- saveLog(file, "error", "clean", "Opening marker doesn't share a parent", node);
198
+ saveLog(file, "error", "collapse", "Opening marker doesn't share a parent", node);
198
199
  return CONTINUE;
199
200
  }
200
201
  if (lastOpenMarker.keyword !== marker.keyword) {
201
- saveLog(file, "error", "clean", "Opening marker doesn't share a keyword", node);
202
+ saveLog(file, "error", "collapse", "Opening marker doesn't share a keyword", node);
202
203
  return CONTINUE;
203
204
  }
204
205
  const openMarkerIndex = parent.children.indexOf(lastOpenMarker.node);
@@ -465,13 +466,38 @@ function getOriginalMarkup(mdastNode, hastNode) {
465
466
  }
466
467
  //#endregion
467
468
  //#region src/lib/mdast-utils/mdast-util-mdat.ts
468
- /** Mdast utility that splits, cleans, and expands all mdat comments in the tree. */
469
+ /**
470
+ * Mdast utility that splits, collapses, and then re-expands all mdat comments
471
+ * in the tree.
472
+ */
469
473
  async function mdat(tree, file, rules) {
470
474
  mdatSplit(tree, file);
471
- mdatClean(tree, file);
475
+ mdatCollapse(tree, file);
472
476
  await mdatExpand(tree, file, rules);
473
477
  }
474
478
  //#endregion
479
+ //#region src/lib/mdast-utils/mdast-util-mdat-clean.ts
480
+ /**
481
+ * @deprecated Use {@link mdatCollapse} instead. This alias will be removed in a
482
+ * future major version.
483
+ */
484
+ const mdatClean = mdatCollapse;
485
+ //#endregion
486
+ //#region src/lib/mdast-utils/mdast-util-mdat-strip.ts
487
+ /**
488
+ * Strips all mdat comment nodes (both opening and closing) from the tree,
489
+ * preserving any content between them. Code-style comments (`//`, `#`, `/*`)
490
+ * are left untouched.
491
+ */
492
+ function mdatStrip(tree, _file) {
493
+ visit(tree, "html", (node, index, parent) => {
494
+ if (parent === void 0 || index === void 0) return CONTINUE;
495
+ if (parseCommentNode(node, parent) === void 0) return CONTINUE;
496
+ parent.children.splice(index, 1);
497
+ return [CONTINUE, index];
498
+ });
499
+ }
500
+ //#endregion
475
501
  //#region src/lib/remark-mdat.ts
476
502
  const defaultRules = { mdat: `Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat).` };
477
503
  /** Zod schema for validating {@link Options}. */
@@ -489,4 +515,4 @@ const remarkMdat = function(options) {
489
515
  };
490
516
  };
491
517
  //#endregion
492
- export { remarkMdat as default, getMdatReports, getSoleRule, getSoleRuleKey, mdat, mdatClean, mdatExpand, mdatSplit, optionsSchema, reporterMdat, rulesSchema, setLogger };
518
+ export { remarkMdat as default, getMdatReports, getSoleRule, getSoleRuleKey, mdat, mdatClean, mdatCollapse, mdatExpand, mdatSplit, mdatStrip, optionsSchema, reporterMdat, rulesSchema, setLogger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-mdat",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "A remark plugin implementing the Markdown Autophagic Template (MDAT) system.",
5
5
  "keywords": [
6
6
  "mdat",
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "@arethetypeswrong/core": "^0.18.2",
62
- "@kitschpatrol/shared-config": "^7.0.0",
62
+ "@kitschpatrol/shared-config": "^7.0.1",
63
63
  "@types/node": "~20.19.37",
64
64
  "bumpp": "^11.0.1",
65
65
  "publint": "^0.3.18",
@@ -77,8 +77,8 @@
77
77
  }
78
78
  },
79
79
  "scripts": {
80
- "bench": "vitest bench --no-file-parallelism --compare test/benchmarks/baseline.json",
81
- "bench:baseline": "vitest bench --no-file-parallelism --outputJson test/benchmarks/baseline.json",
80
+ "bench": "vitest bench --run --no-file-parallelism --compare test/benchmarks/baseline.json",
81
+ "bench:baseline": "vitest bench --run --no-file-parallelism --outputJson test/benchmarks/baseline.json",
82
82
  "build": "tsdown",
83
83
  "clean": "git rm -f pnpm-lock.yaml ; git clean -fdX",
84
84
  "dev": "pnpm run test",
package/readme.md CHANGED
@@ -46,11 +46,13 @@
46
46
  - [Removed options](#removed-options)
47
47
  - [Removed rule properties](#removed-rule-properties)
48
48
  - [Changed rule properties](#changed-rule-properties)
49
+ - [Renamed `clean` to `collapse`](#renamed-clean-to-collapse)
49
50
  - [Removed validation utility](#removed-validation-utility)
50
51
  - [Rule function signature change](#rule-function-signature-change)
51
52
  - [Stricter argument syntax](#stricter-argument-syntax)
52
53
  - [Comment-style comments are ignored](#comment-style-comments-are-ignored)
53
54
  - [Compound rule error handling](#compound-rule-error-handling)
55
+ - [New utility: `mdatStrip`](#new-utility-mdatstrip)
54
56
  - [Removed export: `deepMergeDefined`](#removed-export-deepmergedefined)
55
57
  - [Implementation notes](#implementation-notes)
56
58
  - [Maintainers](#maintainers)
@@ -273,11 +275,11 @@ Errors and warnings are reported inline during expansion via [VFile messages](ht
273
275
 
274
276
  _Exported as `mdatSplit(tree: Root, file: VFile): void`_
275
277
 
276
- - [**`mdast-util-mdat-clean`**](./src/lib/mdast-utils/mdast-util-mdat-clean.ts)
278
+ - [**`mdast-util-mdat-collapse`**](./src/lib/mdast-utils/mdast-util-mdat-collapse.ts)
277
279
 
278
280
  Transformer function that resets all mdat comment expansions in a file, collapsing expanded comments back into single-line placeholders.
279
281
 
280
- _Exported as `mdatClean(tree: Root, file: VFile): void`_
282
+ _Exported as `mdatCollapse(tree: Root, file: VFile): void`_
281
283
 
282
284
  - [**`mdast-util-mdat-expand`**](./src/lib/mdast-utils/mdast-util-mdat-expand.ts)
283
285
 
@@ -285,6 +287,12 @@ Errors and warnings are reported inline during expansion via [VFile messages](ht
285
287
 
286
288
  _Exported as `mdatExpand(tree: Root, file: VFile, rules: Rules): Promise<void>`_
287
289
 
290
+ - [**`mdast-util-mdat-strip`**](./src/lib/mdast-utils/mdast-util-mdat-strip.ts)
291
+
292
+ Transformer function that strips all mdat comment nodes (both opening and closing) from the tree, preserving any content between them. Code-style comments (`<!-- // ... -->`, `<!-- # ... -->`, `<!-- /* ... */ -->`) are left untouched. Useful for producing a final Markdown document with all mdat scaffolding removed.
293
+
294
+ _Exported as `mdatStrip(tree: Root, file: VFile): void`_
295
+
288
296
  ## Migrating from 1.x to 2.x
289
297
 
290
298
  Version 2.0 simplifies and solidifies the API by removing several configuration options and validation features that added complexity without sufficient benefit. The core expansion behavior is unchanged — the plugin still matches HTML comments to rules and expands them — but the way you configure it has changed.
@@ -339,6 +347,10 @@ The following plugin options have been removed entirely:
339
347
  | ------------------ | ------------------ |
340
348
  | `applicationOrder` | Change to `order`. |
341
349
 
350
+ ### Renamed `clean` to `collapse`
351
+
352
+ The former `mdast-util-mdat-clean` / `mdatClean` is now `mdast-util-mdat-collapse` / `mdatCollapse` since this is more clearly the opposite of "expand", and aligns with language used in the Mdat CLI tool. (Note that `mdatClean` is still available as a deprecated alias, but it will be removed in 3.0.)
353
+
342
354
  ### Removed validation utility
343
355
 
344
356
  The `mdast-util-mdat-check` utility and its export `mdatCheck` have been removed. Validation logic (missing rules, empty content, rule errors) is now handled inline during expansion by `mdatExpand`, which reports issues as VFile messages. Use `reporterMdat` to format and display these messages.
@@ -391,6 +403,10 @@ HTML comments using code-style prefixes (`<!-- // ... -->`, `<!-- # ... -->`, `<
391
403
 
392
404
  In 1.x, a failing sub-rule in a compound rule (array of rules) caused the entire expansion to fail. In 2.x, individual sub-rule failures are reported as warnings and skipped — the expansion only fails if every sub-rule fails.
393
405
 
406
+ ### New utility: `mdatStrip`
407
+
408
+ A new `mdast-util-mdat-strip` utility is available for removing all mdat comment nodes from a document while preserving the content between them. Code-style comments (`//`, `#`, `/*`) are left untouched. This is useful for producing a final Markdown document with no mdat scaffolding. See the [Utilities](#utilities) section for details.
409
+
394
410
  ### Removed export: `deepMergeDefined`
395
411
 
396
412
  The `deepMergeDefined` utility has been moved to the [`mdat`](https://github.com/kitschpatrol/mdat) package. If you were importing it from `remark-mdat`, import it from `mdat` instead.