remark-mdat 1.0.5 → 1.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/.DS_Store +0 -0
- package/dist/index.d.ts +228 -10
- package/dist/index.js +29425 -61
- package/package.json +10 -11
- package/readme.md +1 -1
- package/dist/lib/mdast-utils/mdast-util-mdat-check.d.ts +0 -16
- package/dist/lib/mdast-utils/mdast-util-mdat-clean.d.ts +0 -13
- package/dist/lib/mdast-utils/mdast-util-mdat-expand.d.ts +0 -11
- package/dist/lib/mdast-utils/mdast-util-mdat-split.d.ts +0 -8
- package/dist/lib/mdast-utils/mdast-util-mdat.d.ts +0 -11
- package/dist/lib/mdat/deep-merge-defined.d.ts +0 -1
- package/dist/lib/mdat/log.d.ts +0 -12
- package/dist/lib/mdat/mdat-log.d.ts +0 -23
- package/dist/lib/mdat/parse.d.ts +0 -62
- package/dist/lib/mdat/rules.d.ts +0 -112
- package/dist/lib/remark-mdat.d.ts +0 -29
package/dist/.DS_Store
ADDED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,228 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 };
|