remark-mdat 1.1.0 → 1.1.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/.DS_Store CHANGED
Binary file
package/dist/index.d.ts CHANGED
@@ -1,228 +1,10 @@
1
- import { z } from "zod";
2
- import { Plugin } from "unified";
3
- import { VFile } from "vfile";
4
- import { Root } from "mdast";
5
- import { JsonValue, Merge, MergeDeep, SetOptional, Simplify } from "type-fest";
6
-
7
- //#region src/lib/mdat/rules.d.ts
8
- type SimplifyDeep<T> = Simplify<MergeDeep<T, T>>;
9
- /**
10
- * Strict normalized rules used internally.
11
- * Rules normalized to a form with async content functions and other default metadata
12
- * Simplifies processing elsewhere, while retaining flexibility for rule authors
13
- */
14
- type NormalizedRule = {
15
- /**
16
- * The order in which the rule should be applied during processing
17
- * Helpful if a rule depends on the presence of content generated by another rule
18
- * Defaults to 0.
19
- */
20
- applicationOrder: number;
21
- /**
22
- * The function that generates the expanded Markdown string.
23
- * For 'compound' rules, this can be an array of rules (without keywords).
24
- */
25
- content: ((options: JsonValue, tree: Root) => Promise<string>) | NormalizedRule[];
26
- /**
27
- * The expected order of the keyword in the document relative to other expander comments.
28
- * Used for validation purposes.
29
- * Leave undefined to order skip validation.
30
- * Defaults to undefined, which means order is not enforced.
31
- */
32
- order: number | undefined;
33
- /**
34
- * Whether the presence of the keyword comment in the document is required.
35
- * Used for validation purposes.
36
- * Defaults to false.
37
- */
38
- required: boolean;
39
- };
40
- type Rule =
41
- /**
42
- * Function that returns the Markdown string to expand at the comment site.
43
- */
44
- ((options: JsonValue, tree: Root) => Promise<string> | string)
45
- /**
46
- * Compound rules may be defined an array of rules, without keywords.
47
- * Can be defined at the top level, if no validation metadata is required, or as the 'content' value
48
- * of a rule object with validation metadata.
49
- */ | Rule[]
50
- /**
51
- * The Markdown string to expand at the comment site.
52
- */ | SetOptional<Merge<NormalizedRule, {
53
- /**
54
- * Gets content to expand into the comment.
55
- * Can be a simple string for direct replacement, a function that returns a string, or an async function that returns a string.
56
- *
57
- * If a function is provided, it will be passed the following arguments:
58
- * @param options
59
- * JSON value of options parsed immediately after the comment keyword in the comment, e.g.:
60
- * `<!-- keyword({something: true}) -->` or
61
- * `<!-- keyword {something: true}-->`
62
- * Sets options to {something: true}
63
- * @param tree
64
- * Markdown (mdast) abstract syntax tree containing the entire parsed document. Useful for expanders that need the entire document context, such as when generating a table of contents. Do not mutate the AST, instead return a new string.
65
- * @returns A string with the generated content. The string will be parsed as Markdown and inserted into the document at the comment's location.
66
- */
67
- content: ((options: JsonValue, tree: Root) => Promise<string> | string) | Rule[] | string;
68
- }>, 'applicationOrder' | 'order' | 'required'> | string;
69
- /**
70
- * Rules are record objects whose keys match strings inside a Markdown comment, and values explain what should be expanded at the comment site.
71
- *
72
- * The record value may be a string, or an object containing additional metadata, possibly with a function to invoke to generate content.
73
- * @example
74
- * Most basic rule:
75
- * ```ts
76
- * { basic: 'content' }
77
- * ```
78
- *
79
- * Rule with dynamic content:
80
- * ```ts
81
- * { basic: () => `${new Date().toISOString()}` }
82
- * ```
83
- *
84
- * Rule with metadata:
85
- * ```ts
86
- * { basic-meta: { required: true, content: 'content'} }
87
- * ```
88
- *
89
- * Rule with dynamic content and metadata:
90
- * { basic-date: { required: true, content: () => `${new Date().toISOString()}` } }
91
- */
92
- type Rules = SimplifyDeep<Record<string, Rule>>;
93
- type NormalizedRules = SimplifyDeep<Record<string, NormalizedRule>>;
94
- declare const rulesSchema: z.ZodRecord<z.ZodString, z.ZodType<any, z.ZodTypeDef, any>>;
95
- /**
96
- * Returns the rule value from a single-rule record.
97
- * Useful when aliasing rules or invoking them programmatically.
98
- *
99
- * Throws if there are no entries or more than one entry.
100
- */
101
- declare function getSoleRule<T extends NormalizedRules | Rules>(rules: T): T[keyof T];
102
- /**
103
- * Returns the rule key from a single-rule record.
104
- * Useful for comment placeholder validation.
105
- *
106
- * Throws if there are no entries or more than one entry.
107
- */
108
- declare function getSoleRuleKey<T extends NormalizedRules | Rules>(rules: T): keyof T;
109
- //#endregion
110
- //#region src/lib/mdast-utils/mdast-util-mdat.d.ts
111
- type Options$3 = {
112
- addMetaComment: boolean;
113
- closingPrefix: string;
114
- keywordPrefix: string;
115
- metaCommentIdentifier: string;
116
- rules: Rules;
117
- };
118
- declare function mdat(tree: Root, file: VFile, options: Options$3): Promise<void>;
119
- //#endregion
120
- //#region src/lib/mdast-utils/mdast-util-mdat-check.d.ts
121
- type Options = {
122
- addMetaComment: boolean;
123
- closingPrefix: string;
124
- keywordPrefix: string;
125
- metaCommentIdentifier: string;
126
- /** Enable extra checks, too noisy for real life. */
127
- paranoid: boolean;
128
- rules: Rules;
129
- };
130
- /**
131
- * Mdast utility function to check mdat source document, and output.
132
- */
133
- declare function mdatCheck(tree: Root, file: VFile, options: Options): Promise<void>;
134
- //#endregion
135
- //#region src/lib/mdast-utils/mdast-util-mdat-clean.d.ts
136
- type Options$1 = {
137
- closingPrefix: string;
138
- keywordPrefix: string;
139
- metaCommentIdentifier: string;
140
- };
141
- /**
142
- * Collapses any expanded mdat comments and removes meta comments,
143
- * effectively resetting the document to its pre-expansion state. No-op if no
144
- * mdat comments are found.
145
- */
146
- declare function mdatClean(tree: Root, file: VFile, options: Options$1): void;
147
- //#endregion
148
- //#region src/lib/mdast-utils/mdast-util-mdat-expand.d.ts
149
- type Options$2 = {
150
- addMetaComment: boolean;
151
- closingPrefix: string;
152
- keywordPrefix: string;
153
- metaCommentIdentifier: string;
154
- rules: Rules;
155
- };
156
- declare function mdatExpand(tree: Root, file: VFile, options: Options$2): Promise<void>;
157
- //#endregion
158
- //#region src/lib/mdast-utils/mdast-util-mdat-split.d.ts
159
- /**
160
- * Mdast utility plugin to split any multi-comment nodes and their content into individual MDAST HTML
161
- * nodes. They're wrapped in a paragraph so as not to introduce new breaks.
162
- */
163
- declare function mdatSplit(tree: Root, file: VFile): void;
164
- //#endregion
165
- //#region src/lib/mdat/deep-merge-defined.d.ts
166
- declare function deepMergeDefined<T extends Record<string, unknown>>(...objects: T[]): T;
167
- //#endregion
168
- //#region src/lib/mdat/log.d.ts
169
- declare const log: {
170
- verbose: boolean;
171
- log(...data: unknown[]): void;
172
- logPrefixed(prefix: string, ...data: unknown[]): void;
173
- info(...data: unknown[]): void;
174
- infoPrefixed(prefix: string, ...data: unknown[]): void;
175
- warn(...data: unknown[]): void;
176
- warnPrefixed(prefix: string, ...data: unknown[]): void;
177
- error(...data: unknown[]): void;
178
- errorPrefixed(prefix: string, ...data: unknown[]): void;
179
- };
180
- //#endregion
181
- //#region src/lib/mdat/mdat-log.d.ts
182
- /**
183
- * Tries to provide a simpler wrapper to vfile.message
184
- */
185
- type MdatMessage = {
186
- column?: number;
187
- level: 'error' | 'info' | 'warn';
188
- line?: number;
189
- message: string;
190
- source?: string;
191
- };
192
- type MdatFileReport = {
193
- destinationPath?: string;
194
- errors: MdatMessage[];
195
- infos: MdatMessage[];
196
- sourcePath: string;
197
- warnings: MdatMessage[];
198
- };
199
- declare function getMdatReports(files: VFile[]): MdatFileReport[];
200
- declare function reporterMdat(files: VFile[]): void;
201
- //#endregion
202
- //#region src/lib/remark-mdat.d.ts
203
- type Options$4 = Partial<Options$3>;
204
- declare const optionsSchema: z.ZodObject<{
205
- addMetaComment: z.ZodOptional<z.ZodBoolean>;
206
- closingPrefix: z.ZodOptional<z.ZodString>;
207
- keywordPrefix: z.ZodOptional<z.ZodString>;
208
- metaCommentIdentifier: z.ZodOptional<z.ZodString>;
209
- rules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<any, z.ZodTypeDef, any>>>;
210
- }, "strip", z.ZodTypeAny, {
211
- addMetaComment?: boolean | undefined;
212
- closingPrefix?: string | undefined;
213
- keywordPrefix?: string | undefined;
214
- metaCommentIdentifier?: string | undefined;
215
- rules?: Record<string, any> | undefined;
216
- }, {
217
- addMetaComment?: boolean | undefined;
218
- closingPrefix?: string | undefined;
219
- keywordPrefix?: string | undefined;
220
- metaCommentIdentifier?: string | undefined;
221
- rules?: Record<string, any> | undefined;
222
- }>;
223
- /**
224
- * A remark plugin that expands HTML comments in Markdown files.
225
- */
226
- declare const remarkMdat: Plugin<[Options$4], Root>;
227
- //#endregion
228
- export { type Options as MdatCheckOptions, type Options$1 as MdatCleanOptions, type Options$2 as MdatExpandOptions, type MdatFileReport, type MdatMessage, type Options$3 as MdatOptions, type NormalizedRule, type NormalizedRules, type Options$4 as Options, type Rule, type Rules, type SimplifyDeep, deepMergeDefined, remarkMdat as default, getMdatReports, getSoleRule, getSoleRuleKey, log, mdat, mdatCheck, mdatClean, mdatExpand, mdatSplit, optionsSchema, reporterMdat, rulesSchema };
1
+ export { mdat, type Options as MdatOptions } from './lib/mdast-utils/mdast-util-mdat';
2
+ export { mdatCheck, type Options as MdatCheckOptions, } from './lib/mdast-utils/mdast-util-mdat-check';
3
+ export { mdatClean, type Options as MdatCleanOptions, } from './lib/mdast-utils/mdast-util-mdat-clean';
4
+ export { mdatExpand, type Options as MdatExpandOptions, } from './lib/mdast-utils/mdast-util-mdat-expand';
5
+ export { mdatSplit } from './lib/mdast-utils/mdast-util-mdat-split';
6
+ export { deepMergeDefined } from './lib/mdat/deep-merge-defined';
7
+ export { default as log } from './lib/mdat/log';
8
+ export { getMdatReports, type MdatFileReport, type MdatMessage, reporterMdat, } from './lib/mdat/mdat-log';
9
+ export { getSoleRule, getSoleRuleKey, type NormalizedRule, type NormalizedRules, type Rule, type Rules, rulesSchema, type SimplifyDeep, } from './lib/mdat/rules';
10
+ export { default, type Options, optionsSchema } from './lib/remark-mdat';
package/dist/index.js CHANGED
@@ -150,8 +150,7 @@ var require_utils = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/cli-table3@
150
150
  break;
151
151
  case "center": {
152
152
  let right = Math.ceil(padlen / 2);
153
- let left = padlen - right;
154
- str = repeat(pad$1, left) + str + repeat(pad$1, right);
153
+ str = repeat(pad$1, padlen - right) + str + repeat(pad$1, right);
155
154
  break;
156
155
  }
157
156
  default:
@@ -541,8 +540,7 @@ var require_supports_colors = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/@
541
540
  return min;
542
541
  }
543
542
  function getSupportLevel(stream) {
544
- var level$1 = supportsColor(stream);
545
- return translateLevel(level$1);
543
+ return translateLevel(supportsColor(stream));
546
544
  }
547
545
  module.exports = {
548
546
  supportsColor: getSupportLevel,
@@ -1451,13 +1449,12 @@ var require_layout_manager = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/cl
1451
1449
  let yMin1 = cell1.y;
1452
1450
  let yMax1 = cell1.y - 1 + (cell1.rowSpan || 1);
1453
1451
  let yMin2 = cell2.y;
1454
- let yMax2 = cell2.y - 1 + (cell2.rowSpan || 1);
1455
- let yConflict = !(yMin1 > yMax2 || yMin2 > yMax1);
1452
+ let yConflict = !(yMin1 > cell2.y - 1 + (cell2.rowSpan || 1) || yMin2 > yMax1);
1456
1453
  let xMin1 = cell1.x;
1457
1454
  let xMax1 = cell1.x - 1 + (cell1.colSpan || 1);
1458
1455
  let xMin2 = cell2.x;
1459
- let xMax2 = cell2.x - 1 + (cell2.colSpan || 1);
1460
- return yConflict && !(xMin1 > xMax2 || xMin2 > xMax1);
1456
+ let xConflict = !(xMin1 > cell2.x - 1 + (cell2.colSpan || 1) || xMin2 > xMax1);
1457
+ return yConflict && xConflict;
1461
1458
  }
1462
1459
  function conflictExists(rows, x, y) {
1463
1460
  let i_max = Math.min(rows.length - 1, y);
@@ -1702,7 +1699,7 @@ var require_cli_table3 = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/cli-ta
1702
1699
  }) });
1703
1700
 
1704
1701
  //#endregion
1705
- //#region node_modules/.pnpm/unist-util-is@6.0.0/node_modules/unist-util-is/lib/index.js
1702
+ //#region node_modules/.pnpm/unist-util-is@6.0.1/node_modules/unist-util-is/lib/index.js
1706
1703
  /**
1707
1704
  * Generate an assertion from a test.
1708
1705
  *
@@ -1724,7 +1721,7 @@ var require_cli_table3 = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/cli-ta
1724
1721
  const convert = (function(test) {
1725
1722
  if (test === null || test === void 0) return ok$1;
1726
1723
  if (typeof test === "function") return castFactory(test);
1727
- if (typeof test === "object") return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
1724
+ if (typeof test === "object") return Array.isArray(test) ? anyFactory(test) : propertiesFactory(test);
1728
1725
  if (typeof test === "string") return typeFactory(test);
1729
1726
  throw new Error("Expected function, string, or object as test");
1730
1727
  });
@@ -1754,7 +1751,7 @@ function anyFactory(tests) {
1754
1751
  * @param {Props} check
1755
1752
  * @returns {Check}
1756
1753
  */
1757
- function propsFactory(check) {
1754
+ function propertiesFactory(check) {
1758
1755
  const checkAsRecord = check;
1759
1756
  return castFactory(all$2);
1760
1757
  /**
@@ -1812,7 +1809,7 @@ function looksLikeANode(value) {
1812
1809
  }
1813
1810
 
1814
1811
  //#endregion
1815
- //#region node_modules/.pnpm/unist-util-visit-parents@6.0.1/node_modules/unist-util-visit-parents/lib/color.node.js
1812
+ //#region node_modules/.pnpm/unist-util-visit-parents@6.0.2/node_modules/unist-util-visit-parents/lib/color.node.js
1816
1813
  /**
1817
1814
  * @param {string} d
1818
1815
  * @returns {string}
@@ -1822,7 +1819,7 @@ function color(d) {
1822
1819
  }
1823
1820
 
1824
1821
  //#endregion
1825
- //#region node_modules/.pnpm/unist-util-visit-parents@6.0.1/node_modules/unist-util-visit-parents/lib/index.js
1822
+ //#region node_modules/.pnpm/unist-util-visit-parents@6.0.2/node_modules/unist-util-visit-parents/lib/index.js
1826
1823
  /** @type {Readonly<ActionTuple>} */
1827
1824
  const empty = [];
1828
1825
  /**
@@ -2140,8 +2137,7 @@ function mdatMessageToLogString(sourcePath, mdatMessage) {
2140
2137
  const { column: column$1, level: level$1, line: line$1, message, source: source$1 } = mdatMessage;
2141
2138
  const resolvedSource = source$1 ? picocolors.gray(`[${source$1}] `) : "";
2142
2139
  const lineColumn = line$1 && column$1 ? `:${line$1}:${column$1}` : "";
2143
- const highlightedMessage = highlightComments(message, level$1);
2144
- return `${resolvedSource}${highlightedMessage} ${picocolors.whiteBright(sourcePath + lineColumn)}`;
2140
+ return `${resolvedSource}${highlightComments(message, level$1)} ${picocolors.whiteBright(sourcePath + lineColumn)}`;
2145
2141
  }
2146
2142
  function highlightComments(text$4, level$1) {
2147
2143
  return text$4.replaceAll(/<!--.+-->/g, (match) => level$1 === "info" ? picocolors.green(match) : level$1 === "warn" ? picocolors.yellow(match) : picocolors.red(match));
@@ -2191,7 +2187,7 @@ var require_parse = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/json5@2.2.3
2191
2187
  let token;
2192
2188
  let key;
2193
2189
  let root$1;
2194
- module.exports = function parse$5(text$4, reviver) {
2190
+ module.exports = function parse$4(text$4, reviver) {
2195
2191
  source = String(text$4);
2196
2192
  parseState = "start";
2197
2193
  stack = [];
@@ -2930,7 +2926,7 @@ var require_parse = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/json5@2.2.3
2930
2926
  //#region node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/stringify.js
2931
2927
  var require_stringify = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/stringify.js": ((exports, module) => {
2932
2928
  const util = require_util();
2933
- module.exports = function stringify$1(value, replacer, space) {
2929
+ module.exports = function stringify(value, replacer, space) {
2934
2930
  const stack$1 = [];
2935
2931
  let indent$1 = "";
2936
2932
  let propertyList;
@@ -3096,11 +3092,9 @@ var require_stringify = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/json5@2
3096
3092
  //#endregion
3097
3093
  //#region node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/index.js
3098
3094
  var require_lib = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/index.js": ((exports, module) => {
3099
- const parse$4 = require_parse();
3100
- const stringify = require_stringify();
3101
3095
  const JSON5 = {
3102
- parse: parse$4,
3103
- stringify
3096
+ parse: require_parse(),
3097
+ stringify: require_stringify()
3104
3098
  };
3105
3099
  module.exports = JSON5;
3106
3100
  }) });
@@ -3621,7 +3615,7 @@ function getSoleRuleKey(rules) {
3621
3615
  * that are only supposed to contain a single rule.
3622
3616
  * @param record The record to get the sole entry from
3623
3617
  * @returns The value of the sole entry in the record
3624
- * @throws If there are no entries or more than one entry
3618
+ * @throws {Error} If there are no entries or more than one entry
3625
3619
  */
3626
3620
  function getSoleRecord(record) {
3627
3621
  const recordValues = Object.values(record);
@@ -3825,9 +3819,7 @@ const emptyOptions$2 = {};
3825
3819
  */
3826
3820
  function toString(value, options) {
3827
3821
  const settings = options || emptyOptions$2;
3828
- const includeImageAlt = typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true;
3829
- const includeHtml = typeof settings.includeHtml === "boolean" ? settings.includeHtml : true;
3830
- return one$1(value, includeImageAlt, includeHtml);
3822
+ return one$1(value, typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true, typeof settings.includeHtml === "boolean" ? settings.includeHtml : true);
3831
3823
  }
3832
3824
  /**
3833
3825
  * One node or several nodes.
@@ -12739,8 +12731,7 @@ function createTokenizer(parser, initialize, from) {
12739
12731
  function start(code$2) {
12740
12732
  const left = code$2 !== null && map$4[code$2];
12741
12733
  const all$2 = code$2 !== null && map$4.null;
12742
- const list$3 = [...Array.isArray(left) ? left : left ? [left] : [], ...Array.isArray(all$2) ? all$2 : all$2 ? [all$2] : []];
12743
- return handleListOfConstructs(list$3)(code$2);
12734
+ return handleListOfConstructs([...Array.isArray(left) ? left : left ? [left] : [], ...Array.isArray(all$2) ? all$2 : all$2 ? [all$2] : []])(code$2);
12744
12735
  }
12745
12736
  }
12746
12737
  /**
@@ -13288,10 +13279,7 @@ function compiler(options) {
13288
13279
  const listStack = [];
13289
13280
  let index$1 = -1;
13290
13281
  while (++index$1 < events.length) if (events[index$1][1].type === "listOrdered" || events[index$1][1].type === "listUnordered") if (events[index$1][0] === "enter") listStack.push(index$1);
13291
- else {
13292
- const tail = listStack.pop();
13293
- index$1 = prepareList(events, tail, index$1);
13294
- }
13282
+ else index$1 = prepareList(events, listStack.pop(), index$1);
13295
13283
  index$1 = -1;
13296
13284
  while (++index$1 < events.length) {
13297
13285
  const handler = config[events[index$1][0]];
@@ -17257,8 +17245,7 @@ function gfmTableToMarkdown(options) {
17257
17245
  * @param {TableRow} node
17258
17246
  */
17259
17247
  function handleTableRow(node$1, _, state, info$1) {
17260
- const row = handleTableRowAsData(node$1, state, info$1);
17261
- const value = serializeData([row]);
17248
+ const value = serializeData([handleTableRowAsData(node$1, state, info$1)]);
17262
17249
  return value.slice(0, value.indexOf("\n"));
17263
17250
  }
17264
17251
  /**
@@ -19721,7 +19708,7 @@ async function mdatExpand(tree, file, options) {
19721
19708
  keywordPrefix,
19722
19709
  metaCommentIdentifier
19723
19710
  });
19724
- if (commentMarker !== void 0 && commentMarker.type === "open" && rules[commentMarker.keyword] !== void 0) commentMarkers.push(commentMarker);
19711
+ if (commentMarker?.type === "open" && rules[commentMarker.keyword] !== void 0) commentMarkers.push(commentMarker);
19725
19712
  });
19726
19713
  commentMarkers.sort((a, b) => rules[a.keyword].applicationOrder - rules[b.keyword].applicationOrder);
19727
19714
  for (const comment of commentMarkers) {
@@ -26283,8 +26270,7 @@ var Parser = class {
26283
26270
  }
26284
26271
  if (!token$1.location) return;
26285
26272
  const siblings = this.treeAdapter.getChildNodes(parent);
26286
- const textNodeIdx = beforeElement ? siblings.lastIndexOf(beforeElement) : siblings.length;
26287
- const textNode = siblings[textNodeIdx - 1];
26273
+ const textNode = siblings[(beforeElement ? siblings.lastIndexOf(beforeElement) : siblings.length) - 1];
26288
26274
  if (this.treeAdapter.getNodeSourceCodeLocation(textNode)) {
26289
26275
  const { endLine, endCol, endOffset } = token$1.location;
26290
26276
  this.treeAdapter.updateNodeSourceCodeLocation(textNode, {
@@ -26499,8 +26485,7 @@ var Parser = class {
26499
26485
  }
26500
26486
  /** @protected */
26501
26487
  _isSpecialElement(element$1, id) {
26502
- const ns = this.treeAdapter.getNamespaceURI(element$1);
26503
- return SPECIAL_ELEMENTS[ns].has(id);
26488
+ return SPECIAL_ELEMENTS[this.treeAdapter.getNamespaceURI(element$1)].has(id);
26504
26489
  }
26505
26490
  /** @internal */
26506
26491
  onCharacter(token$1) {
@@ -26987,8 +26972,7 @@ function aaRecreateElementFromEntry(p, elementEntry) {
26987
26972
  return newElement;
26988
26973
  }
26989
26974
  function aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement) {
26990
- const tn = p.treeAdapter.getTagName(commonAncestor);
26991
- const tid = getTagID(tn);
26975
+ const tid = getTagID(p.treeAdapter.getTagName(commonAncestor));
26992
26976
  if (p._isElementCausesFosterParenting(tid)) p._fosterParentElement(lastElement);
26993
26977
  else {
26994
26978
  const ns = p.treeAdapter.getNamespaceURI(commonAncestor);
@@ -28868,12 +28852,11 @@ function fromHtml(value, options) {
28868
28852
  const file = value instanceof VFile ? value : new VFile(value);
28869
28853
  const parseFunction = settings.fragment ? parseFragment : parse;
28870
28854
  const document$2 = String(file);
28871
- const p5Document = parseFunction(document$2, {
28855
+ return fromParse5(parseFunction(document$2, {
28872
28856
  sourceCodeLocationInfo: true,
28873
28857
  onParseError: settings.onerror ? internalOnerror : null,
28874
28858
  scriptingEnabled: false
28875
- });
28876
- return fromParse5(p5Document, {
28859
+ }), {
28877
28860
  file,
28878
28861
  space: settings.space,
28879
28862
  verbose: settings.verbose
@@ -28945,8 +28928,7 @@ function fromHtml(value, options) {
28945
28928
  */
28946
28929
  function formatC(_, $1, $2) {
28947
28930
  const offset = ($2 ? Number.parseInt($2, 10) : 0) * ($1 === "-" ? -1 : 1);
28948
- const char = document$2.charAt(error.startOffset + offset);
28949
- return visualizeCharacter(char);
28931
+ return visualizeCharacter(document$2.charAt(error.startOffset + offset));
28950
28932
  }
28951
28933
  /**
28952
28934
  * Format the character code.
@@ -29214,11 +29196,10 @@ function mergeRecords$1(values, utils$2, meta) {
29214
29196
  const propValues = [];
29215
29197
  for (const value of values) if (objectHasProperty(value, key$1)) propValues.push(value[key$1]);
29216
29198
  if (propValues.length === 0) continue;
29217
- const updatedMeta = utils$2.metaDataUpdater(meta, {
29199
+ const propertyResult = mergeUnknowns(propValues, utils$2, utils$2.metaDataUpdater(meta, {
29218
29200
  key: key$1,
29219
29201
  parents: values
29220
- });
29221
- const propertyResult = mergeUnknowns(propValues, utils$2, updatedMeta);
29202
+ }));
29222
29203
  if (propertyResult === actions.skip) continue;
29223
29204
  if (key$1 === "__proto__") Object.defineProperty(result, key$1, {
29224
29205
  value: propertyResult,
@@ -29390,8 +29371,7 @@ function stripUndefinedDeep(object) {
29390
29371
  }, {});
29391
29372
  }
29392
29373
  function deepMergeDefined(...objects) {
29393
- const stripped = objects.map((v, i) => i === 0 ? v : stripUndefinedDeep(v));
29394
- return deepmerge(...stripped);
29374
+ return deepmerge(...objects.map((v, i) => i === 0 ? v : stripUndefinedDeep(v)));
29395
29375
  }
29396
29376
 
29397
29377
  //#endregion
@@ -0,0 +1,16 @@
1
+ import type { Root } from 'mdast';
2
+ import type { VFile } from 'vfile';
3
+ import type { Rules } from '../mdat/rules';
4
+ export type Options = {
5
+ addMetaComment: boolean;
6
+ closingPrefix: string;
7
+ keywordPrefix: string;
8
+ metaCommentIdentifier: string;
9
+ /** Enable extra checks, too noisy for real life. */
10
+ paranoid: boolean;
11
+ rules: Rules;
12
+ };
13
+ /**
14
+ * Mdast utility function to check mdat source document, and output.
15
+ */
16
+ export declare function mdatCheck(tree: Root, file: VFile, options: Options): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import type { Root } from 'mdast';
2
+ import type { VFile } from 'vfile';
3
+ export type Options = {
4
+ closingPrefix: string;
5
+ keywordPrefix: string;
6
+ metaCommentIdentifier: string;
7
+ };
8
+ /**
9
+ * Collapses any expanded mdat comments and removes meta comments,
10
+ * effectively resetting the document to its pre-expansion state. No-op if no
11
+ * mdat comments are found.
12
+ */
13
+ export declare function mdatClean(tree: Root, file: VFile, options: Options): void;
@@ -0,0 +1,11 @@
1
+ import type { Root } from 'mdast';
2
+ import type { VFile } from 'vfile';
3
+ import type { Rules } from '../mdat/rules';
4
+ export type Options = {
5
+ addMetaComment: boolean;
6
+ closingPrefix: string;
7
+ keywordPrefix: string;
8
+ metaCommentIdentifier: string;
9
+ rules: Rules;
10
+ };
11
+ export declare function mdatExpand(tree: Root, file: VFile, options: Options): Promise<void>;
@@ -0,0 +1,8 @@
1
+ import type { Html, Root, Text } from 'mdast';
2
+ import type { VFile } from 'vfile';
3
+ /**
4
+ * Mdast utility plugin to split any multi-comment nodes and their content into individual MDAST HTML
5
+ * nodes. They're wrapped in a paragraph so as not to introduce new breaks.
6
+ */
7
+ export declare function mdatSplit(tree: Root, file: VFile): void;
8
+ export declare function splitHtmlIntoMdastNodes(mdastNode: Html): Array<Html | Text>;
@@ -0,0 +1,11 @@
1
+ import type { Root } from 'mdast';
2
+ import type { VFile } from 'vfile';
3
+ import type { Rules } from '../mdat/rules';
4
+ export type Options = {
5
+ addMetaComment: boolean;
6
+ closingPrefix: string;
7
+ keywordPrefix: string;
8
+ metaCommentIdentifier: string;
9
+ rules: Rules;
10
+ };
11
+ export declare function mdat(tree: Root, file: VFile, options: Options): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function deepMergeDefined<T extends Record<string, unknown>>(...objects: T[]): T;
@@ -0,0 +1,12 @@
1
+ declare const log: {
2
+ verbose: boolean;
3
+ log(...data: unknown[]): void;
4
+ logPrefixed(prefix: string, ...data: unknown[]): void;
5
+ info(...data: unknown[]): void;
6
+ infoPrefixed(prefix: string, ...data: unknown[]): void;
7
+ warn(...data: unknown[]): void;
8
+ warnPrefixed(prefix: string, ...data: unknown[]): void;
9
+ error(...data: unknown[]): void;
10
+ errorPrefixed(prefix: string, ...data: unknown[]): void;
11
+ };
12
+ export default log;
@@ -0,0 +1,23 @@
1
+ import type { Node } from 'unist';
2
+ import type { VFile } from 'vfile';
3
+ /**
4
+ * Tries to provide a simpler wrapper to vfile.message
5
+ */
6
+ export type MdatMessage = {
7
+ column?: number;
8
+ level: 'error' | 'info' | 'warn';
9
+ line?: number;
10
+ message: string;
11
+ source?: string;
12
+ };
13
+ export type MdatFileReport = {
14
+ destinationPath?: string;
15
+ errors: MdatMessage[];
16
+ infos: MdatMessage[];
17
+ sourcePath: string;
18
+ warnings: MdatMessage[];
19
+ };
20
+ export declare function saveLog(file: VFile, level: 'error' | 'info' | 'warn', source: string, message: string, line?: number, column?: number): void;
21
+ export declare function saveLog(file: VFile, level: 'error' | 'info' | 'warn', source: string, message: string, node?: Node): void;
22
+ export declare function getMdatReports(files: VFile[]): MdatFileReport[];
23
+ export declare function reporterMdat(files: VFile[]): void;
@@ -0,0 +1,62 @@
1
+ import type { Html, Parent } from 'mdast';
2
+ import type { JsonValue, Simplify } from 'type-fest';
3
+ /**
4
+ * Structured data about a parsed comment.
5
+ * Note that this is a discriminated union based on the `type` field.
6
+ */
7
+ type CommentMarker = Simplify<{
8
+ /** The complete original comment, e.g. `<!-- keyword -->` */
9
+ html: string;
10
+ } & ({
11
+ /** Character used to delimit closing tags, e.g. the `/` in `<!-- /keyword -->` */
12
+ closingPrefix: string;
13
+ /** The first complete word in the comment */
14
+ keyword: string;
15
+ /** The unique keyword prefix */
16
+ keywordPrefix: string;
17
+ /** Parsed JSON object of argument string that followed the keyword, empty object if nothing passed */
18
+ options: JsonValue;
19
+ /**
20
+ * `open`: A mdat-style opening comment tag, e.g. `<!-- keyword -->` \
21
+ * `close`: A mdat-style closing comment tag, e.g. `<!-- /keyword -->`
22
+ */
23
+ type: 'close' | 'open';
24
+ } | {
25
+ /** The original text inside the comment, e.g. `<!-- content -->` */
26
+ content: string;
27
+ /**
28
+ * `meta`: A mdat-style generated meta comment tag \
29
+ * `native`: A normal comment that does not match the the `keywordPrefix` (if specified)
30
+ */
31
+ type: 'meta' | 'native';
32
+ })>;
33
+ /**
34
+ * Parsed comment with additional information about the Mdast Node and its Parent.
35
+ */
36
+ export type CommentMarkerNode = Simplify<CommentMarker & {
37
+ /** Original Mdast HTML Node where the comment was found. */
38
+ node: Html;
39
+ /** Parent of original Mdast HTML Node where the comment was found. */
40
+ parent: Parent;
41
+ }>;
42
+ type CommentMarkerParseOptions = {
43
+ /** Character to identify closing tags, e.g. the `/` in `<!-- /keyword -->` */
44
+ closingPrefix: string;
45
+ /** Prefix to require on all mdat comments, e.g. `mm-` */
46
+ keywordPrefix: string;
47
+ /** Means of identifying mdat generated meta comments, e.g. `+` */
48
+ metaCommentIdentifier: string;
49
+ };
50
+ /**
51
+ * Parse an Mdast HTML comment node into structured data.
52
+ * @returns A discriminated union of CommentMarkerNode based on comment type, or
53
+ * undefined if the node is not a comment.
54
+ */
55
+ export declare function parseCommentNode(node: Html, parent: Parent, options: CommentMarkerParseOptions): CommentMarkerNode | undefined;
56
+ /**
57
+ * Parse any comment string into structured data.
58
+ * @returns A discriminated union of CommentMarker based on comment type, or
59
+ * undefined if the node is not a comment.
60
+ */
61
+ export declare function parseComment(text: string, options: CommentMarkerParseOptions): CommentMarker | undefined;
62
+ export {};
@@ -0,0 +1,112 @@
1
+ import type { Root } from 'mdast';
2
+ import type { JsonValue, Merge, MergeDeep, SetOptional, Simplify } from 'type-fest';
3
+ import { z } from 'zod';
4
+ export type SimplifyDeep<T> = Simplify<MergeDeep<T, T>>;
5
+ /**
6
+ * Strict normalized rules used internally.
7
+ * Rules normalized to a form with async content functions and other default metadata
8
+ * Simplifies processing elsewhere, while retaining flexibility for rule authors
9
+ */
10
+ export type NormalizedRule = {
11
+ /**
12
+ * The order in which the rule should be applied during processing
13
+ * Helpful if a rule depends on the presence of content generated by another rule
14
+ * Defaults to 0.
15
+ */
16
+ applicationOrder: number;
17
+ /**
18
+ * The function that generates the expanded Markdown string.
19
+ * For 'compound' rules, this can be an array of rules (without keywords).
20
+ */
21
+ content: ((options: JsonValue, tree: Root) => Promise<string>) | NormalizedRule[];
22
+ /**
23
+ * The expected order of the keyword in the document relative to other expander comments.
24
+ * Used for validation purposes.
25
+ * Leave undefined to order skip validation.
26
+ * Defaults to undefined, which means order is not enforced.
27
+ */
28
+ order: number | undefined;
29
+ /**
30
+ * Whether the presence of the keyword comment in the document is required.
31
+ * Used for validation purposes.
32
+ * Defaults to false.
33
+ */
34
+ required: boolean;
35
+ };
36
+ export type Rule =
37
+ /**
38
+ * Function that returns the Markdown string to expand at the comment site.
39
+ */
40
+ ((options: JsonValue, tree: Root) => Promise<string> | string)
41
+ /**
42
+ * Compound rules may be defined an array of rules, without keywords.
43
+ * Can be defined at the top level, if no validation metadata is required, or as the 'content' value
44
+ * of a rule object with validation metadata.
45
+ */
46
+ | Rule[]
47
+ /**
48
+ * The Markdown string to expand at the comment site.
49
+ */
50
+ | SetOptional<Merge<NormalizedRule, {
51
+ /**
52
+ * Gets content to expand into the comment.
53
+ * Can be a simple string for direct replacement, a function that returns a string, or an async function that returns a string.
54
+ *
55
+ * If a function is provided, it will be passed the following arguments:
56
+ * @param options
57
+ * JSON value of options parsed immediately after the comment keyword in the comment, e.g.:
58
+ * `<!-- keyword({something: true}) -->` or
59
+ * `<!-- keyword {something: true}-->`
60
+ * Sets options to {something: true}
61
+ * @param tree
62
+ * Markdown (mdast) abstract syntax tree containing the entire parsed document. Useful for expanders that need the entire document context, such as when generating a table of contents. Do not mutate the AST, instead return a new string.
63
+ * @returns A string with the generated content. The string will be parsed as Markdown and inserted into the document at the comment's location.
64
+ */
65
+ content: ((options: JsonValue, tree: Root) => Promise<string> | string) | Rule[] | string;
66
+ }>, 'applicationOrder' | 'order' | 'required'> | string;
67
+ /**
68
+ * Rules are record objects whose keys match strings inside a Markdown comment, and values explain what should be expanded at the comment site.
69
+ *
70
+ * The record value may be a string, or an object containing additional metadata, possibly with a function to invoke to generate content.
71
+ * @example
72
+ * Most basic rule:
73
+ * ```ts
74
+ * { basic: 'content' }
75
+ * ```
76
+ *
77
+ * Rule with dynamic content:
78
+ * ```ts
79
+ * { basic: () => `${new Date().toISOString()}` }
80
+ * ```
81
+ *
82
+ * Rule with metadata:
83
+ * ```ts
84
+ * { basic-meta: { required: true, content: 'content'} }
85
+ * ```
86
+ *
87
+ * Rule with dynamic content and metadata:
88
+ * { basic-date: { required: true, content: () => `${new Date().toISOString()}` } }
89
+ */
90
+ export type Rules = SimplifyDeep<Record<string, Rule>>;
91
+ export type NormalizedRules = SimplifyDeep<Record<string, NormalizedRule>>;
92
+ export declare function normalizeRules(rules: Rules): NormalizedRules;
93
+ export declare function validateRules(rules: Rules): void;
94
+ export declare const rulesSchema: z.ZodRecord<z.ZodString, z.ZodType<any, z.ZodTypeDef, any>>;
95
+ /**
96
+ * Compound rule helpers, used in both "expand" and "check" utilities
97
+ */
98
+ export declare function getRuleContent(rule: NormalizedRule, options: JsonValue, tree: Root, check?: boolean): Promise<string>;
99
+ /**
100
+ * Returns the rule value from a single-rule record.
101
+ * Useful when aliasing rules or invoking them programmatically.
102
+ *
103
+ * Throws if there are no entries or more than one entry.
104
+ */
105
+ export declare function getSoleRule<T extends NormalizedRules | Rules>(rules: T): T[keyof T];
106
+ /**
107
+ * Returns the rule key from a single-rule record.
108
+ * Useful for comment placeholder validation.
109
+ *
110
+ * Throws if there are no entries or more than one entry.
111
+ */
112
+ export declare function getSoleRuleKey<T extends NormalizedRules | Rules>(rules: T): keyof T;
@@ -0,0 +1,29 @@
1
+ import type { Root } from 'mdast';
2
+ import type { Plugin } from 'unified';
3
+ import { z } from 'zod';
4
+ import type { Options as MdatOptions } from './mdast-utils/mdast-util-mdat';
5
+ export type Options = Partial<MdatOptions>;
6
+ export declare const optionsSchema: z.ZodObject<{
7
+ addMetaComment: z.ZodOptional<z.ZodBoolean>;
8
+ closingPrefix: z.ZodOptional<z.ZodString>;
9
+ keywordPrefix: z.ZodOptional<z.ZodString>;
10
+ metaCommentIdentifier: z.ZodOptional<z.ZodString>;
11
+ rules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<any, z.ZodTypeDef, any>>>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ closingPrefix?: string | undefined;
14
+ keywordPrefix?: string | undefined;
15
+ metaCommentIdentifier?: string | undefined;
16
+ rules?: Record<string, any> | undefined;
17
+ addMetaComment?: boolean | undefined;
18
+ }, {
19
+ closingPrefix?: string | undefined;
20
+ keywordPrefix?: string | undefined;
21
+ metaCommentIdentifier?: string | undefined;
22
+ rules?: Record<string, any> | undefined;
23
+ addMetaComment?: boolean | undefined;
24
+ }>;
25
+ /**
26
+ * A remark plugin that expands HTML comments in Markdown files.
27
+ */
28
+ declare const remarkMdat: Plugin<[Options], Root>;
29
+ export default remarkMdat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-mdat",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A remark plugin implementing the Markdown Autophagic Template (MDAT) system.",
5
5
  "keywords": [
6
6
  "mdat",
@@ -35,28 +35,28 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@types/mdast": "^4.0.4",
38
- "@types/node": "^20.19.17",
38
+ "@types/node": "^20.19.24",
39
39
  "@types/unist": "^3.0.3",
40
40
  "picocolors": "^1.1.1",
41
- "type-fest": "^5.0.1",
41
+ "type-fest": "^5.2.0",
42
42
  "unified": "^11.0.5",
43
43
  "vfile": "^6.0.3",
44
44
  "zod": "^3.25.76"
45
45
  },
46
46
  "devDependencies": {
47
- "@kitschpatrol/shared-config": "^5.7.0",
48
- "bumpp": "^10.2.3",
47
+ "@kitschpatrol/shared-config": "^5.7.4",
48
+ "bumpp": "^10.3.1",
49
49
  "cli-table3": "^0.6.5",
50
50
  "deepmerge-ts": "^7.1.5",
51
51
  "hast-util-from-html": "^2.0.3",
52
52
  "json5": "^2.2.3",
53
53
  "remark": "^15.0.1",
54
54
  "remark-gfm": "^4.0.1",
55
- "tsdown": "^0.15.5",
56
- "typescript": "~5.9.2",
55
+ "tsdown": "^0.15.12",
56
+ "typescript": "~5.9.3",
57
57
  "unist-util-visit": "^5.0.0",
58
58
  "vfile-message": "^4.0.3",
59
- "vitest": "^3.2.4"
59
+ "vitest": "^4.0.6"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">=20.19.0"
@@ -65,12 +65,12 @@
65
65
  "access": "public"
66
66
  },
67
67
  "scripts": {
68
- "build": "tsdown --tsconfig ./tsconfig.build.json",
68
+ "build": "tsdown --dts false && tsc -p tsconfig.build.json",
69
69
  "clean": "git rm -f pnpm-lock.yaml ; git clean -fdX",
70
70
  "dev": "pnpm run test",
71
71
  "fix": "ksc fix",
72
72
  "lint": "ksc lint",
73
- "release": "bumpp --commit 'Release: %s' && pnpm run build && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
73
+ "release": "bumpp --commit 'Release: %s' && pnpm run build && NPM_AUTH_TOKEN=$(op read 'op://Personal/npm/token') && pnpm publish",
74
74
  "test": "vitest"
75
75
  }
76
76
  }