remark-mdat 2.0.1 → 2.0.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/index.d.ts +19 -12
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { JsonValue, MergeDeep, Simplify } from "type-fest";
|
|
|
6
6
|
import { Plugin } from "unified";
|
|
7
7
|
|
|
8
8
|
//#region src/lib/mdat/rules.d.ts
|
|
9
|
+
/** Recursively simplifies a type for cleaner IDE hover display. Approximation of type-fest's internal `SimplifyDeep`. */
|
|
9
10
|
type SimplifyDeep<T> = Simplify<MergeDeep<T, T>>;
|
|
10
11
|
/**
|
|
11
12
|
* Context passed to rule content functions during expansion.
|
|
@@ -97,7 +98,9 @@ type Rule =
|
|
|
97
98
|
* { basic-date: { order: 1, content: () => `${new Date().toISOString()}` } }
|
|
98
99
|
*/
|
|
99
100
|
type Rules = SimplifyDeep<Record<string, Rule>>;
|
|
101
|
+
/** A record mapping comment keywords to {@link NormalizedRule} objects. */
|
|
100
102
|
type NormalizedRules = SimplifyDeep<Record<string, NormalizedRule>>;
|
|
103
|
+
/** Zod schema for validating {@link Rules} records. */
|
|
101
104
|
declare const rulesSchema: z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
102
105
|
/**
|
|
103
106
|
* Returns the rule value from a single-rule record.
|
|
@@ -115,6 +118,7 @@ declare function getSoleRule<T extends NormalizedRules | Rules>(rules: T): T[key
|
|
|
115
118
|
declare function getSoleRuleKey<T extends NormalizedRules | Rules>(rules: T): keyof T;
|
|
116
119
|
//#endregion
|
|
117
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. */
|
|
118
122
|
declare function mdat(tree: Root, file: VFile, rules: NormalizedRules | Rules): Promise<void>;
|
|
119
123
|
//#endregion
|
|
120
124
|
//#region src/lib/mdast-utils/mdast-util-mdat-clean.d.ts
|
|
@@ -146,30 +150,33 @@ declare function mdatSplit(tree: Root, file: VFile): void;
|
|
|
146
150
|
declare function setLogger(logger?: ILogBasic | ILogLayer): void;
|
|
147
151
|
//#endregion
|
|
148
152
|
//#region src/lib/mdat/mdat-log.d.ts
|
|
149
|
-
/**
|
|
150
|
-
* Tries to provide a simpler wrapper to vfile.message
|
|
151
|
-
*/
|
|
153
|
+
/** A simplified representation of a {@link VFileMessage}. */
|
|
152
154
|
type MdatMessage = {
|
|
153
|
-
column?: number;
|
|
154
|
-
level: 'error' | 'info' | 'warn';
|
|
155
|
-
line?: number;
|
|
156
|
-
message: string;
|
|
155
|
+
/** Starting column of the message origin. */column?: number; /** Severity level. */
|
|
156
|
+
level: 'error' | 'info' | 'warn'; /** Starting line of the message origin. */
|
|
157
|
+
line?: number; /** Human-readable description of the issue. */
|
|
158
|
+
message: string; /** Namespace that produced the message (e.g. the rule name). */
|
|
157
159
|
source?: string;
|
|
158
160
|
};
|
|
161
|
+
/** Aggregated processing report for a single file. */
|
|
159
162
|
type MdatFileReport = {
|
|
160
|
-
destinationPath?: string;
|
|
161
|
-
errors: MdatMessage[];
|
|
162
|
-
infos: MdatMessage[];
|
|
163
|
-
sourcePath: string;
|
|
163
|
+
/** Output path if the file was written to a different location. */destinationPath?: string; /** Fatal errors that prevented successful processing. */
|
|
164
|
+
errors: MdatMessage[]; /** Informational messages. */
|
|
165
|
+
infos: MdatMessage[]; /** Original input file path. */
|
|
166
|
+
sourcePath: string; /** Non-fatal warnings encountered during processing. */
|
|
164
167
|
warnings: MdatMessage[];
|
|
165
168
|
};
|
|
169
|
+
/** Converts an array of processed VFiles into {@link MdatFileReport} objects. */
|
|
166
170
|
declare function getMdatReports(files: VFile[]): MdatFileReport[];
|
|
171
|
+
/** Logs a human-readable processing report for each VFile to the library logger. */
|
|
167
172
|
declare function reporterMdat(files: VFile[]): void;
|
|
168
173
|
//#endregion
|
|
169
174
|
//#region src/lib/remark-mdat.d.ts
|
|
175
|
+
/** Configuration for the remarkMdat plugin. */
|
|
170
176
|
type Options = {
|
|
171
|
-
rules?: Rules;
|
|
177
|
+
/** Rules mapping comment keywords to expansion content. Merged with built-in defaults. */rules?: Rules;
|
|
172
178
|
};
|
|
179
|
+
/** Zod schema for validating {@link Options}. */
|
|
173
180
|
declare const optionsSchema: z.ZodObject<{
|
|
174
181
|
rules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
175
182
|
}, z.core.$strip>;
|
package/dist/index.js
CHANGED
|
@@ -63,6 +63,7 @@ function vFileMessageToMdatMessage(vFileMessage) {
|
|
|
63
63
|
source: vFileMessage.source
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
/** Converts an array of processed VFiles into {@link MdatFileReport} objects. */
|
|
66
67
|
function getMdatReports(files) {
|
|
67
68
|
return files.map((file) => getMdatReport(file));
|
|
68
69
|
}
|
|
@@ -83,6 +84,7 @@ function getMdatReport(file) {
|
|
|
83
84
|
}
|
|
84
85
|
return mdatFileReport;
|
|
85
86
|
}
|
|
87
|
+
/** Logs a human-readable processing report for each VFile to the library logger. */
|
|
86
88
|
function reporterMdat(files) {
|
|
87
89
|
for (const file of files) {
|
|
88
90
|
const { destinationPath, errors, infos, sourcePath, warnings } = getMdatReport(file);
|
|
@@ -215,6 +217,7 @@ const NORMALIZED = Symbol("normalized");
|
|
|
215
217
|
function isNormalized(rules) {
|
|
216
218
|
return NORMALIZED in rules;
|
|
217
219
|
}
|
|
220
|
+
/** Converts flexible {@link Rules} into strict {@link NormalizedRules} for internal processing. */
|
|
218
221
|
function normalizeRules(rules) {
|
|
219
222
|
validateRules(rules);
|
|
220
223
|
const normalizedRules = {};
|
|
@@ -250,6 +253,7 @@ function normalizeRules(rules) {
|
|
|
250
253
|
Object.defineProperty(normalizedRules, NORMALIZED, { value: true });
|
|
251
254
|
return normalizedRules;
|
|
252
255
|
}
|
|
256
|
+
/** Validates rules against {@link rulesSchema}, throwing on invalid input. */
|
|
253
257
|
function validateRules(rules) {
|
|
254
258
|
try {
|
|
255
259
|
rulesSchema.parse(rules);
|
|
@@ -273,6 +277,7 @@ const ruleSchema = z.lazy(() => z.union([
|
|
|
273
277
|
]));
|
|
274
278
|
const COMMENT_PREFIX_REGEX = /^[/*#]/;
|
|
275
279
|
const keywordSchema = z.string().check(z.refine((key) => !COMMENT_PREFIX_REGEX.test(key), { message: "Rule keywords must not start with \"/\", \"*\", or \"#\" — these prefixes are reserved for comment syntax" }));
|
|
280
|
+
/** Zod schema for validating {@link Rules} records. */
|
|
276
281
|
const rulesSchema = z.record(keywordSchema, ruleSchema).describe("MDAT Rules");
|
|
277
282
|
/**
|
|
278
283
|
* Expand rule content. For compound rules (content arrays), individual
|
|
@@ -414,6 +419,7 @@ function mdatSplit(tree, file) {
|
|
|
414
419
|
}
|
|
415
420
|
});
|
|
416
421
|
}
|
|
422
|
+
/** Splits a single mdast HTML node containing multiple comments into individual HTML and text nodes. Exported for testing. */
|
|
417
423
|
function splitHtmlIntoMdastNodes(mdastNode) {
|
|
418
424
|
const htmlTree = fromHtml(mdastNode.value, { fragment: true });
|
|
419
425
|
const mdastNodes = [];
|
|
@@ -459,6 +465,7 @@ function getOriginalMarkup(mdastNode, hastNode) {
|
|
|
459
465
|
}
|
|
460
466
|
//#endregion
|
|
461
467
|
//#region src/lib/mdast-utils/mdast-util-mdat.ts
|
|
468
|
+
/** Mdast utility that splits, cleans, and expands all mdat comments in the tree. */
|
|
462
469
|
async function mdat(tree, file, rules) {
|
|
463
470
|
mdatSplit(tree, file);
|
|
464
471
|
mdatClean(tree, file);
|
|
@@ -467,6 +474,7 @@ async function mdat(tree, file, rules) {
|
|
|
467
474
|
//#endregion
|
|
468
475
|
//#region src/lib/remark-mdat.ts
|
|
469
476
|
const defaultRules = { mdat: `Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat).` };
|
|
477
|
+
/** Zod schema for validating {@link Options}. */
|
|
470
478
|
const optionsSchema = z.object({ rules: rulesSchema.optional() }).describe("MDAT Plugin Options");
|
|
471
479
|
/**
|
|
472
480
|
* A remark plugin that expands HTML comments in Markdown files.
|