@effected/markdown 0.2.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/Frontmatter.js +272 -0
- package/FrontmatterResolver.js +273 -0
- package/JsonFrontmatter.js +46 -0
- package/LICENSE +21 -0
- package/Markdown.js +251 -0
- package/MarkdownDiagnostic.js +85 -0
- package/MarkdownDocument.js +248 -0
- package/MarkdownEdit.js +52 -0
- package/MarkdownFormat.js +380 -0
- package/MarkdownNode.js +641 -0
- package/MarkdownVisitor.js +88 -0
- package/Mdast.js +384 -0
- package/README.md +255 -0
- package/TomlFrontmatter.js +44 -0
- package/YamlFrontmatter.js +45 -0
- package/index.d.ts +2190 -0
- package/index.js +15 -0
- package/internal/blockParser.js +419 -0
- package/internal/blockRegistry.js +90 -0
- package/internal/blockTypes.js +27 -0
- package/internal/blocks/atxHeading.js +54 -0
- package/internal/blocks/blockquote.js +40 -0
- package/internal/blocks/code.js +90 -0
- package/internal/blocks/document.js +17 -0
- package/internal/blocks/fencedCode.js +26 -0
- package/internal/blocks/footnoteDefinition.js +84 -0
- package/internal/blocks/frontmatter.js +56 -0
- package/internal/blocks/htmlBlock.js +72 -0
- package/internal/blocks/indentedCode.js +16 -0
- package/internal/blocks/linkReferenceDefinition.js +72 -0
- package/internal/blocks/list.js +159 -0
- package/internal/blocks/paragraph.js +27 -0
- package/internal/blocks/setextHeading.js +24 -0
- package/internal/blocks/table.js +378 -0
- package/internal/blocks/taskListItem.js +36 -0
- package/internal/blocks/thematicBreak.js +35 -0
- package/internal/carriers.js +42 -0
- package/internal/entities.js +26 -0
- package/internal/entityMap.js +7 -0
- package/internal/htmlTags.js +18 -0
- package/internal/inlineNode.js +54 -0
- package/internal/inlineParser.js +403 -0
- package/internal/inlineRegistry.js +68 -0
- package/internal/inlines/autolink.js +36 -0
- package/internal/inlines/autolinkLiteral.js +374 -0
- package/internal/inlines/codeSpan.js +32 -0
- package/internal/inlines/emphasis.js +79 -0
- package/internal/inlines/entity.js +21 -0
- package/internal/inlines/escape.js +34 -0
- package/internal/inlines/footnoteReference.js +63 -0
- package/internal/inlines/lineBreak.js +25 -0
- package/internal/inlines/link.js +212 -0
- package/internal/inlines/rawHtml.js +27 -0
- package/internal/inlines/strikethrough.js +81 -0
- package/internal/inlines/text.js +22 -0
- package/internal/lineIndex.js +76 -0
- package/internal/patterns.js +26 -0
- package/internal/preprocess.js +58 -0
- package/internal/rawInline.js +57 -0
- package/internal/references.js +160 -0
- package/internal/segments.js +36 -0
- package/internal/stringify.js +519 -0
- package/internal/unescape.js +18 -0
- package/package.json +61 -0
- package/tsdoc-metadata.json +11 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,2190 @@
|
|
|
1
|
+
import { Data, Effect, Result, Schema, Stream } from "effect";
|
|
2
|
+
//#region src/MarkdownNode.d.ts
|
|
3
|
+
declare const Point_base: Schema.Class<Point, Schema.Struct<{
|
|
4
|
+
readonly line: Schema.Number;
|
|
5
|
+
readonly column: Schema.Number;
|
|
6
|
+
readonly offset: Schema.Number;
|
|
7
|
+
}>, {}>;
|
|
8
|
+
/**
|
|
9
|
+
* A single point in a source document: 1-based `line` and `column`, 0-based
|
|
10
|
+
* `offset`.
|
|
11
|
+
*
|
|
12
|
+
* `offset` is the index into the source string, which is what the edit layer
|
|
13
|
+
* splices against; `line`/`column` are the human-facing coordinates unist
|
|
14
|
+
* specifies.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
declare class Point extends Point_base {}
|
|
19
|
+
declare const Position_base: Schema.Class<Position, Schema.Struct<{
|
|
20
|
+
readonly start: typeof Point;
|
|
21
|
+
readonly end: typeof Point;
|
|
22
|
+
}>, {}>;
|
|
23
|
+
/**
|
|
24
|
+
* The source span of a node: `start` inclusive, `end` exclusive.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
declare class Position extends Position_base {
|
|
29
|
+
/**
|
|
30
|
+
* The zero-width synthetic position: line 1, column 1, offset 0 at both
|
|
31
|
+
* ends — the span every node class's `make` fills in when `position` is
|
|
32
|
+
* omitted, and the same sentinel `Mdast.fromMdast` synthesizes for foreign
|
|
33
|
+
* nodes that carry none.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Clearly synthetic and inert for rendering: trees carrying it serve
|
|
37
|
+
* tree-level workflows (stringify, the visitor, `MarkdownFormat.modify`
|
|
38
|
+
* replacement fragments, projection out), not offset-splice editing, whose
|
|
39
|
+
* offsets must come from a real parse.
|
|
40
|
+
*/
|
|
41
|
+
static readonly synthetic: Position;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The explicitness of a reference, per mdast's `referenceType` enum.
|
|
45
|
+
*
|
|
46
|
+
* - `shortcut` — implicit, identifier inferred from the content (`[foo]`).
|
|
47
|
+
* - `collapsed` — explicit, identifier inferred from the content (`[foo][]`).
|
|
48
|
+
* - `full` — explicit, identifier explicitly set (`[foo][bar]`).
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
declare const ReferenceType: Schema.Literals<readonly ["shortcut", "collapsed", "full"]>;
|
|
53
|
+
/**
|
|
54
|
+
* The union of all reference-type string literals.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
type ReferenceType = typeof ReferenceType.Type;
|
|
59
|
+
/**
|
|
60
|
+
* The two ways CommonMark spells a heading: `atx` (`# Title`) and `setext`
|
|
61
|
+
* (a title underlined with `=` or `-`).
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
declare const HeadingStyle: Schema.Literals<readonly ["atx", "setext"]>;
|
|
66
|
+
/**
|
|
67
|
+
* The union of all heading-style string literals.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
type HeadingStyle = typeof HeadingStyle.Type;
|
|
72
|
+
/**
|
|
73
|
+
* The two ways CommonMark spells a hard line break: a trailing backslash or
|
|
74
|
+
* two-or-more trailing spaces.
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
declare const BreakStyle: Schema.Literals<readonly ["backslash", "spaces"]>;
|
|
79
|
+
/**
|
|
80
|
+
* The union of all break-style string literals.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
type BreakStyle = typeof BreakStyle.Type;
|
|
85
|
+
/**
|
|
86
|
+
* The two fence characters a fenced code block may use.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
declare const FenceChar: Schema.Literals<readonly ["`", "~"]>;
|
|
91
|
+
/**
|
|
92
|
+
* The union of all fence-character literals.
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
type FenceChar = typeof FenceChar.Type;
|
|
97
|
+
/**
|
|
98
|
+
* The three bullet characters an unordered list may use.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
declare const BulletChar: Schema.Literals<readonly ["-", "*", "+"]>;
|
|
103
|
+
/**
|
|
104
|
+
* The union of all bullet-character literals.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
type BulletChar = typeof BulletChar.Type;
|
|
109
|
+
/**
|
|
110
|
+
* The two delimiters an ordered list marker may use (`1.` or `1)`).
|
|
111
|
+
*
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
declare const ListDelimiter: Schema.Literals<readonly [".", ")"]>;
|
|
115
|
+
/**
|
|
116
|
+
* The union of all ordered-list delimiter literals.
|
|
117
|
+
*
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
type ListDelimiter = typeof ListDelimiter.Type;
|
|
121
|
+
/**
|
|
122
|
+
* The three characters a thematic break may be drawn with.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
declare const ThematicBreakChar: Schema.Literals<readonly ["-", "_", "*"]>;
|
|
127
|
+
/**
|
|
128
|
+
* The union of all thematic-break character literals.
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
type ThematicBreakChar = typeof ThematicBreakChar.Type;
|
|
133
|
+
/**
|
|
134
|
+
* The two characters emphasis and strong emphasis may be marked with.
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
declare const EmphasisChar: Schema.Literals<readonly ["*", "_"]>;
|
|
139
|
+
/**
|
|
140
|
+
* The union of all emphasis-marker character literals.
|
|
141
|
+
*
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
144
|
+
type EmphasisChar = typeof EmphasisChar.Type;
|
|
145
|
+
/**
|
|
146
|
+
* The six legal ATX/setext heading depths.
|
|
147
|
+
*
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
declare const HeadingDepth: Schema.Literals<readonly [1, 2, 3, 4, 5, 6]>;
|
|
151
|
+
/**
|
|
152
|
+
* The union of all legal heading depths.
|
|
153
|
+
*
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
type HeadingDepth = typeof HeadingDepth.Type;
|
|
157
|
+
/**
|
|
158
|
+
* The three alignments a GFM table column may declare. A `null` entry in a
|
|
159
|
+
* {@link Table}'s `align` array means the column carries no alignment.
|
|
160
|
+
*
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
163
|
+
declare const TableAlign: Schema.Literals<readonly ["left", "right", "center"]>;
|
|
164
|
+
/**
|
|
165
|
+
* The union of all table-alignment string literals.
|
|
166
|
+
*
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
type TableAlign = typeof TableAlign.Type;
|
|
170
|
+
declare const Text_base: Schema.Class<Text, Schema.Struct<{
|
|
171
|
+
readonly type: Schema.tag<"text">;
|
|
172
|
+
readonly value: Schema.String;
|
|
173
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
174
|
+
}>, {}>;
|
|
175
|
+
/**
|
|
176
|
+
* Text — a run of literal characters, with entity references and backslash
|
|
177
|
+
* escapes already resolved into `value`.
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
declare class Text extends Text_base {}
|
|
182
|
+
declare const InlineCode_base: Schema.Class<InlineCode, Schema.Struct<{
|
|
183
|
+
readonly type: Schema.tag<"inlineCode">;
|
|
184
|
+
readonly value: Schema.String;
|
|
185
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
186
|
+
}>, {}>;
|
|
187
|
+
/**
|
|
188
|
+
* InlineCode — a code span: `foo` written between backtick fences in the
|
|
189
|
+
* source. `value` holds the span's content with the backtick fence stripped
|
|
190
|
+
* and the spec's space-stripping applied.
|
|
191
|
+
*
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
declare class InlineCode extends InlineCode_base {}
|
|
195
|
+
declare const Html_base: Schema.Class<Html, Schema.Struct<{
|
|
196
|
+
readonly type: Schema.tag<"html">;
|
|
197
|
+
readonly value: Schema.String;
|
|
198
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
199
|
+
}>, {}>;
|
|
200
|
+
/**
|
|
201
|
+
* Html — a fragment of raw HTML, kept verbatim. Used for both HTML blocks
|
|
202
|
+
* (flow) and inline raw HTML (phrasing); the same node type serves both, as
|
|
203
|
+
* mdast specifies.
|
|
204
|
+
*
|
|
205
|
+
* @public
|
|
206
|
+
*/
|
|
207
|
+
declare class Html extends Html_base {}
|
|
208
|
+
declare const Break_base: Schema.Class<Break, Schema.Struct<{
|
|
209
|
+
readonly type: Schema.tag<"break">;
|
|
210
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
211
|
+
readonly breakStyle: Schema.optionalKey<Schema.Literals<readonly ["backslash", "spaces"]>>;
|
|
212
|
+
}>, {}>;
|
|
213
|
+
/**
|
|
214
|
+
* Break — a hard line break.
|
|
215
|
+
*
|
|
216
|
+
* `breakStyle` is a fidelity extra recording which of the two CommonMark
|
|
217
|
+
* spellings produced it.
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
declare class Break extends Break_base {}
|
|
222
|
+
declare const Image_base: Schema.Class<Image, Schema.Struct<{
|
|
223
|
+
readonly type: Schema.tag<"image">;
|
|
224
|
+
readonly url: Schema.String;
|
|
225
|
+
readonly title: Schema.optionalKey<Schema.String>;
|
|
226
|
+
readonly alt: Schema.optionalKey<Schema.String>;
|
|
227
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
228
|
+
}>, {}>;
|
|
229
|
+
/**
|
|
230
|
+
* Image — an inline image (``).
|
|
231
|
+
*
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
declare class Image extends Image_base {}
|
|
235
|
+
declare const ImageReference_base: Schema.Class<ImageReference, Schema.Struct<{
|
|
236
|
+
readonly type: Schema.tag<"imageReference">;
|
|
237
|
+
readonly identifier: Schema.String;
|
|
238
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
239
|
+
readonly referenceType: Schema.Literals<readonly ["shortcut", "collapsed", "full"]>;
|
|
240
|
+
readonly alt: Schema.optionalKey<Schema.String>;
|
|
241
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
242
|
+
}>, {}>;
|
|
243
|
+
/**
|
|
244
|
+
* ImageReference — an image referring to a {@link Definition} by identifier
|
|
245
|
+
* (`![alt][ref]`).
|
|
246
|
+
*
|
|
247
|
+
* The parser emits these unresolved, whether or not a matching definition
|
|
248
|
+
* exists in the tree — resolution is the consumer's business.
|
|
249
|
+
*
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
declare class ImageReference extends ImageReference_base {}
|
|
253
|
+
declare const Emphasis_base: Schema.Class<Emphasis, Schema.Struct<{
|
|
254
|
+
readonly type: Schema.tag<"emphasis">;
|
|
255
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<PhrasingContent, PhrasingContent, never, never>>>;
|
|
256
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
257
|
+
readonly markerChar: Schema.optionalKey<Schema.Literals<readonly ["*", "_"]>>;
|
|
258
|
+
}>, {}>;
|
|
259
|
+
/**
|
|
260
|
+
* Emphasis — `*foo*` or `_foo_`.
|
|
261
|
+
*
|
|
262
|
+
* `markerChar` is a fidelity extra recording which marker produced it.
|
|
263
|
+
*
|
|
264
|
+
* @public
|
|
265
|
+
*/
|
|
266
|
+
declare class Emphasis extends Emphasis_base {}
|
|
267
|
+
declare const Strong_base: Schema.Class<Strong, Schema.Struct<{
|
|
268
|
+
readonly type: Schema.tag<"strong">;
|
|
269
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<PhrasingContent, PhrasingContent, never, never>>>;
|
|
270
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
271
|
+
readonly markerChar: Schema.optionalKey<Schema.Literals<readonly ["*", "_"]>>;
|
|
272
|
+
}>, {}>;
|
|
273
|
+
/**
|
|
274
|
+
* Strong — `**foo**` or `__foo__`.
|
|
275
|
+
*
|
|
276
|
+
* `markerChar` is a fidelity extra recording which marker produced it.
|
|
277
|
+
*
|
|
278
|
+
* @public
|
|
279
|
+
*/
|
|
280
|
+
declare class Strong extends Strong_base {}
|
|
281
|
+
declare const Delete_base: Schema.Class<Delete, Schema.Struct<{
|
|
282
|
+
readonly type: Schema.tag<"delete">;
|
|
283
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<PhrasingContent, PhrasingContent, never, never>>>;
|
|
284
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
285
|
+
}>, {}>;
|
|
286
|
+
/**
|
|
287
|
+
* Delete — GFM strikethrough (`~~foo~~`). Content that is no longer accurate
|
|
288
|
+
* or relevant.
|
|
289
|
+
*
|
|
290
|
+
* `~~` is the only marker `~~foo~~` renders through, so unlike
|
|
291
|
+
* {@link Emphasis} and {@link Strong} there is no marker-character fidelity
|
|
292
|
+
* extra to carry.
|
|
293
|
+
*
|
|
294
|
+
* @public
|
|
295
|
+
*/
|
|
296
|
+
declare class Delete extends Delete_base {}
|
|
297
|
+
declare const Link_base: Schema.Class<Link, Schema.Struct<{
|
|
298
|
+
readonly type: Schema.tag<"link">;
|
|
299
|
+
readonly url: Schema.String;
|
|
300
|
+
readonly title: Schema.optionalKey<Schema.String>;
|
|
301
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<PhrasingContent, PhrasingContent, never, never>>>;
|
|
302
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
303
|
+
}>, {}>;
|
|
304
|
+
/**
|
|
305
|
+
* Link — an inline link (`[text](url "title")`), including autolinks.
|
|
306
|
+
*
|
|
307
|
+
* @public
|
|
308
|
+
*/
|
|
309
|
+
declare class Link extends Link_base {}
|
|
310
|
+
declare const LinkReference_base: Schema.Class<LinkReference, Schema.Struct<{
|
|
311
|
+
readonly type: Schema.tag<"linkReference">;
|
|
312
|
+
readonly identifier: Schema.String;
|
|
313
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
314
|
+
readonly referenceType: Schema.Literals<readonly ["shortcut", "collapsed", "full"]>;
|
|
315
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<PhrasingContent, PhrasingContent, never, never>>>;
|
|
316
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
317
|
+
}>, {}>;
|
|
318
|
+
/**
|
|
319
|
+
* LinkReference — a link referring to a {@link Definition} by identifier
|
|
320
|
+
* (`[text][ref]`).
|
|
321
|
+
*
|
|
322
|
+
* Emitted unresolved, on the same terms as {@link ImageReference}.
|
|
323
|
+
*
|
|
324
|
+
* @public
|
|
325
|
+
*/
|
|
326
|
+
declare class LinkReference extends LinkReference_base {}
|
|
327
|
+
declare const FootnoteReference_base: Schema.Class<FootnoteReference, Schema.Struct<{
|
|
328
|
+
readonly type: Schema.tag<"footnoteReference">;
|
|
329
|
+
readonly identifier: Schema.String;
|
|
330
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
331
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
332
|
+
}>, {}>;
|
|
333
|
+
/**
|
|
334
|
+
* FootnoteReference — a GFM footnote marker (`[^alpha]`), associating this
|
|
335
|
+
* point in the text with a {@link FootnoteDefinition} by identifier.
|
|
336
|
+
*
|
|
337
|
+
* Has no content model of its own — the marker carries no children, only the
|
|
338
|
+
* mdast Association pair `identifier`/`label`. Like {@link LinkReference},
|
|
339
|
+
* the parser emits these unresolved: resolution against a matching
|
|
340
|
+
* `FootnoteDefinition` is the consumer's business.
|
|
341
|
+
*
|
|
342
|
+
* @public
|
|
343
|
+
*/
|
|
344
|
+
declare class FootnoteReference extends FootnoteReference_base {}
|
|
345
|
+
/**
|
|
346
|
+
* The union of every node that may appear where mdast expects **phrasing**
|
|
347
|
+
* content — the text of a document and its markup.
|
|
348
|
+
*
|
|
349
|
+
* Defined lazily via `Schema.suspend` to break the recursive reference chain
|
|
350
|
+
* `PhrasingContent -> Emphasis/Strong/Link/LinkReference -> PhrasingContent`.
|
|
351
|
+
*
|
|
352
|
+
* @public
|
|
353
|
+
*/
|
|
354
|
+
declare const PhrasingContent: Schema.Codec<PhrasingContent>;
|
|
355
|
+
/**
|
|
356
|
+
* The union of all phrasing-content node types.
|
|
357
|
+
*
|
|
358
|
+
* @public
|
|
359
|
+
*/
|
|
360
|
+
type PhrasingContent = Break | Delete | Emphasis | FootnoteReference | Html | Image | ImageReference | InlineCode | Link | LinkReference | Strong | Text;
|
|
361
|
+
declare const ThematicBreak_base: Schema.Class<ThematicBreak, Schema.Struct<{
|
|
362
|
+
readonly type: Schema.tag<"thematicBreak">;
|
|
363
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
364
|
+
readonly markerChar: Schema.optionalKey<Schema.Literals<readonly ["-", "_", "*"]>>;
|
|
365
|
+
}>, {}>;
|
|
366
|
+
/**
|
|
367
|
+
* ThematicBreak — a horizontal rule (`---`, `***`, `___`).
|
|
368
|
+
*
|
|
369
|
+
* `markerChar` is a fidelity extra recording which character drew it.
|
|
370
|
+
*
|
|
371
|
+
* @public
|
|
372
|
+
*/
|
|
373
|
+
declare class ThematicBreak extends ThematicBreak_base {}
|
|
374
|
+
declare const Code_base: Schema.Class<Code, Schema.Struct<{
|
|
375
|
+
readonly type: Schema.tag<"code">;
|
|
376
|
+
readonly value: Schema.String;
|
|
377
|
+
readonly lang: Schema.optionalKey<Schema.String>;
|
|
378
|
+
readonly meta: Schema.optionalKey<Schema.String>;
|
|
379
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
380
|
+
readonly fenceChar: Schema.optionalKey<Schema.Literals<readonly ["`", "~"]>>;
|
|
381
|
+
readonly fenceLength: Schema.optionalKey<Schema.Number>;
|
|
382
|
+
}>, {}>;
|
|
383
|
+
/**
|
|
384
|
+
* Code — a code block, fenced or indented.
|
|
385
|
+
*
|
|
386
|
+
* `lang` and `meta` split the fence's info string at the first run of
|
|
387
|
+
* whitespace. The fidelity extras `fenceChar` and `fenceLength` are present
|
|
388
|
+
* for fenced blocks and **absent for indented blocks** — their absence is how
|
|
389
|
+
* the two are told apart on the way back out.
|
|
390
|
+
*
|
|
391
|
+
* @public
|
|
392
|
+
*/
|
|
393
|
+
declare class Code extends Code_base {}
|
|
394
|
+
declare const Definition_base: Schema.Class<Definition, Schema.Struct<{
|
|
395
|
+
readonly type: Schema.tag<"definition">;
|
|
396
|
+
readonly identifier: Schema.String;
|
|
397
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
398
|
+
readonly url: Schema.String;
|
|
399
|
+
readonly title: Schema.optionalKey<Schema.String>;
|
|
400
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
401
|
+
}>, {}>;
|
|
402
|
+
/**
|
|
403
|
+
* Definition — a link reference definition (`[ref]: /url "title"`).
|
|
404
|
+
*
|
|
405
|
+
* Kept in the tree at its source position rather than stripped, which is the
|
|
406
|
+
* deliberate departure from commonmark.js and the reason references can stay
|
|
407
|
+
* unresolved.
|
|
408
|
+
*
|
|
409
|
+
* @public
|
|
410
|
+
*/
|
|
411
|
+
declare class Definition extends Definition_base {}
|
|
412
|
+
declare const FootnoteDefinition_base: Schema.Class<FootnoteDefinition, Schema.Struct<{
|
|
413
|
+
readonly type: Schema.tag<"footnoteDefinition">;
|
|
414
|
+
readonly identifier: Schema.String;
|
|
415
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
416
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<FlowContent, FlowContent, never, never>>>;
|
|
417
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
418
|
+
}>, {}>;
|
|
419
|
+
/**
|
|
420
|
+
* FootnoteDefinition — a GFM footnote definition (`[^alpha]: bravo.`), the
|
|
421
|
+
* content a {@link FootnoteReference} points at.
|
|
422
|
+
*
|
|
423
|
+
* Kept in the tree at its source position, on the same terms as
|
|
424
|
+
* {@link Definition} — the parser never relocates it; a consumer that wants
|
|
425
|
+
* cmark-gfm's end-of-document footnote section renders it there instead.
|
|
426
|
+
*
|
|
427
|
+
* @public
|
|
428
|
+
*/
|
|
429
|
+
declare class FootnoteDefinition extends FootnoteDefinition_base {}
|
|
430
|
+
declare const Paragraph_base: Schema.Class<Paragraph, Schema.Struct<{
|
|
431
|
+
readonly type: Schema.tag<"paragraph">;
|
|
432
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<PhrasingContent, PhrasingContent, never, never>>>;
|
|
433
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
434
|
+
}>, {}>;
|
|
435
|
+
/**
|
|
436
|
+
* Paragraph — a run of phrasing content.
|
|
437
|
+
*
|
|
438
|
+
* @public
|
|
439
|
+
*/
|
|
440
|
+
declare class Paragraph extends Paragraph_base {}
|
|
441
|
+
declare const Heading_base: Schema.Class<Heading, Schema.Struct<{
|
|
442
|
+
readonly type: Schema.tag<"heading">;
|
|
443
|
+
readonly depth: Schema.Literals<readonly [1, 2, 3, 4, 5, 6]>;
|
|
444
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<PhrasingContent, PhrasingContent, never, never>>>;
|
|
445
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
446
|
+
readonly headingStyle: Schema.optionalKey<Schema.Literals<readonly ["atx", "setext"]>>;
|
|
447
|
+
}>, {}>;
|
|
448
|
+
/**
|
|
449
|
+
* Heading — an ATX or setext heading of depth 1 to 6.
|
|
450
|
+
*
|
|
451
|
+
* `headingStyle` is a fidelity extra recording which spelling produced it;
|
|
452
|
+
* setext headings can only be depth 1 or 2.
|
|
453
|
+
*
|
|
454
|
+
* @public
|
|
455
|
+
*/
|
|
456
|
+
declare class Heading extends Heading_base {}
|
|
457
|
+
declare const ListItem_base: Schema.Class<ListItem, Schema.Struct<{
|
|
458
|
+
readonly type: Schema.tag<"listItem">;
|
|
459
|
+
readonly spread: Schema.optionalKey<Schema.Boolean>;
|
|
460
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<FlowContent, FlowContent, never, never>>>;
|
|
461
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
462
|
+
readonly checked: Schema.optionalKey<Schema.Boolean>;
|
|
463
|
+
}>, {}>;
|
|
464
|
+
/**
|
|
465
|
+
* ListItem — one item of a {@link List}.
|
|
466
|
+
*
|
|
467
|
+
* `spread` follows mdast in being optional: absent means "not known", which a
|
|
468
|
+
* hand-built tree may legitimately be. The parser always sets it.
|
|
469
|
+
*
|
|
470
|
+
* `checked` is a GFM extra (task-list items, `- [ ] foo` / `- [x] foo`):
|
|
471
|
+
* `true` for done, `false` for not done, and **absent** — never `null` — for
|
|
472
|
+
* an item that is not a task-list item at all. The parser only ever sets it
|
|
473
|
+
* on items it recognized as task-list markers.
|
|
474
|
+
*
|
|
475
|
+
* @public
|
|
476
|
+
*/
|
|
477
|
+
declare class ListItem extends ListItem_base {}
|
|
478
|
+
declare const List_base: Schema.Class<List, Schema.Struct<{
|
|
479
|
+
readonly type: Schema.tag<"list">;
|
|
480
|
+
readonly ordered: Schema.optionalKey<Schema.Boolean>;
|
|
481
|
+
readonly start: Schema.optionalKey<Schema.Number>;
|
|
482
|
+
readonly spread: Schema.optionalKey<Schema.Boolean>;
|
|
483
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<ListItem, ListItem, never, never>>>;
|
|
484
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
485
|
+
readonly bulletChar: Schema.optionalKey<Schema.Literals<readonly ["-", "*", "+"]>>;
|
|
486
|
+
readonly delimiter: Schema.optionalKey<Schema.Literals<readonly [".", ")"]>>;
|
|
487
|
+
}>, {}>;
|
|
488
|
+
/**
|
|
489
|
+
* List — an ordered or unordered list.
|
|
490
|
+
*
|
|
491
|
+
* `ordered`, `start` and `spread` are all optional per mdast (absent meaning
|
|
492
|
+
* "not known"); the parser always sets `ordered` and `spread`, and sets
|
|
493
|
+
* `start` only for ordered lists.
|
|
494
|
+
*
|
|
495
|
+
* The fidelity extras record the marker actually used: `bulletChar` for
|
|
496
|
+
* unordered lists, `delimiter` for ordered ones.
|
|
497
|
+
*
|
|
498
|
+
* @public
|
|
499
|
+
*/
|
|
500
|
+
declare class List extends List_base {}
|
|
501
|
+
declare const Blockquote_base: Schema.Class<Blockquote, Schema.Struct<{
|
|
502
|
+
readonly type: Schema.tag<"blockquote">;
|
|
503
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<FlowContent, FlowContent, never, never>>>;
|
|
504
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
505
|
+
}>, {}>;
|
|
506
|
+
/**
|
|
507
|
+
* Blockquote — a section quoted from somewhere else.
|
|
508
|
+
*
|
|
509
|
+
* @public
|
|
510
|
+
*/
|
|
511
|
+
declare class Blockquote extends Blockquote_base {}
|
|
512
|
+
declare const TableCell_base: Schema.Class<TableCell, Schema.Struct<{
|
|
513
|
+
readonly type: Schema.tag<"tableCell">;
|
|
514
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<PhrasingContent, PhrasingContent, never, never>>>;
|
|
515
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
516
|
+
}>, {}>;
|
|
517
|
+
/**
|
|
518
|
+
* TableCell — one cell of a {@link TableRow}: a header cell if its
|
|
519
|
+
* grandparent {@link Table}'s first row, a data cell otherwise.
|
|
520
|
+
*
|
|
521
|
+
* mdast's content model for `TableCell` is phrasing content **excluding**
|
|
522
|
+
* `Break` nodes — GFM tables are single-line source, so a hard break cannot
|
|
523
|
+
* occur inside one. This schema does not carve that exclusion out of
|
|
524
|
+
* `PhrasingContent`: a second phrasing union just for table cells would
|
|
525
|
+
* duplicate the whole recursive-suspend machinery above for one excluded
|
|
526
|
+
* member, and a parser that never emits `Break` inside a cell satisfies the
|
|
527
|
+
* exclusion in practice without it.
|
|
528
|
+
*
|
|
529
|
+
* @public
|
|
530
|
+
*/
|
|
531
|
+
declare class TableCell extends TableCell_base {}
|
|
532
|
+
/**
|
|
533
|
+
* The union of every node that may appear where mdast expects **row**
|
|
534
|
+
* content — the cells in a {@link TableRow}. A one-member union, kept because
|
|
535
|
+
* mdast names the category.
|
|
536
|
+
*
|
|
537
|
+
* @public
|
|
538
|
+
*/
|
|
539
|
+
declare const RowContent: Schema.Codec<RowContent>;
|
|
540
|
+
/**
|
|
541
|
+
* The union of all row-content node types.
|
|
542
|
+
*
|
|
543
|
+
* @public
|
|
544
|
+
*/
|
|
545
|
+
type RowContent = TableCell;
|
|
546
|
+
declare const TableRow_base: Schema.Class<TableRow, Schema.Struct<{
|
|
547
|
+
readonly type: Schema.tag<"tableRow">;
|
|
548
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<TableCell, TableCell, never, never>>>;
|
|
549
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
550
|
+
}>, {}>;
|
|
551
|
+
/**
|
|
552
|
+
* TableRow — one row of a {@link Table}: the labels of the columns if it is
|
|
553
|
+
* the table's first row, a data row otherwise.
|
|
554
|
+
*
|
|
555
|
+
* @public
|
|
556
|
+
*/
|
|
557
|
+
declare class TableRow extends TableRow_base {}
|
|
558
|
+
/**
|
|
559
|
+
* The union of every node that may appear where mdast expects **table**
|
|
560
|
+
* content — the rows in a {@link Table}. A one-member union, kept because
|
|
561
|
+
* mdast names the category.
|
|
562
|
+
*
|
|
563
|
+
* @public
|
|
564
|
+
*/
|
|
565
|
+
declare const TableContent: Schema.Codec<TableContent>;
|
|
566
|
+
/**
|
|
567
|
+
* The union of all table-content node types.
|
|
568
|
+
*
|
|
569
|
+
* @public
|
|
570
|
+
*/
|
|
571
|
+
type TableContent = TableRow;
|
|
572
|
+
declare const Table_base: Schema.Class<Table, Schema.Struct<{
|
|
573
|
+
readonly type: Schema.tag<"table">;
|
|
574
|
+
readonly align: Schema.optionalKey<Schema.$Array<Schema.NullOr<Schema.Literals<readonly ["left", "right", "center"]>>>>;
|
|
575
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<TableRow, TableRow, never, never>>>;
|
|
576
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
577
|
+
}>, {}>;
|
|
578
|
+
/**
|
|
579
|
+
* Table — GFM two-dimensional data.
|
|
580
|
+
*
|
|
581
|
+
* `align` is optional per mdast: absent means "not known" — which the parser
|
|
582
|
+
* never produces, since a GFM table's delimiter row always yields one
|
|
583
|
+
* `TableAlign | null` entry per column, but a hand-built tree may omit it.
|
|
584
|
+
* When present, each entry is `null` for a column with no declared alignment.
|
|
585
|
+
*
|
|
586
|
+
* @public
|
|
587
|
+
*/
|
|
588
|
+
declare class Table extends Table_base {}
|
|
589
|
+
/**
|
|
590
|
+
* The union of every node that may appear where mdast expects **flow**
|
|
591
|
+
* content — the sections of a document.
|
|
592
|
+
*
|
|
593
|
+
* Defined lazily via `Schema.suspend` to break the recursive reference chain
|
|
594
|
+
* `FlowContent -> Blockquote/List -> FlowContent`. Widened for GFM with
|
|
595
|
+
* {@link FootnoteDefinition} and {@link Table}, per mdast's `FlowContent`
|
|
596
|
+
* (GFM) category.
|
|
597
|
+
*
|
|
598
|
+
* @public
|
|
599
|
+
*/
|
|
600
|
+
declare const FlowContent: Schema.Codec<FlowContent>;
|
|
601
|
+
/**
|
|
602
|
+
* The union of all flow-content node types. Includes mdast's `Content`
|
|
603
|
+
* category (`Definition | Paragraph`) inline, as the spec's `FlowContent`
|
|
604
|
+
* definition does, and the GFM extras `FootnoteDefinition` and `Table`.
|
|
605
|
+
*
|
|
606
|
+
* @public
|
|
607
|
+
*/
|
|
608
|
+
type FlowContent = Blockquote | Code | Definition | FootnoteDefinition | Heading | Html | List | Paragraph | Table | ThematicBreak;
|
|
609
|
+
/**
|
|
610
|
+
* The union of every node that may appear where mdast expects **list**
|
|
611
|
+
* content. A one-member union, kept because mdast names the category and
|
|
612
|
+
* later dialects widen it.
|
|
613
|
+
*
|
|
614
|
+
* @public
|
|
615
|
+
*/
|
|
616
|
+
declare const ListContent: Schema.Codec<ListContent>;
|
|
617
|
+
/**
|
|
618
|
+
* The union of all list-content node types.
|
|
619
|
+
*
|
|
620
|
+
* @public
|
|
621
|
+
*/
|
|
622
|
+
type ListContent = ListItem;
|
|
623
|
+
/**
|
|
624
|
+
* The frontmatter formats the capture recognizes, keyed by their opening
|
|
625
|
+
* fence: `---` is yaml, `+++` is toml and `---json` is json.
|
|
626
|
+
*
|
|
627
|
+
* @public
|
|
628
|
+
*/
|
|
629
|
+
declare const FrontmatterFormat: Schema.Literals<readonly ["yaml", "toml", "json"]>;
|
|
630
|
+
/**
|
|
631
|
+
* The union of all frontmatter format string literals.
|
|
632
|
+
*
|
|
633
|
+
* @public
|
|
634
|
+
*/
|
|
635
|
+
type FrontmatterFormat = typeof FrontmatterFormat.Type;
|
|
636
|
+
declare const Frontmatter_base: Schema.Class<Frontmatter, Schema.Struct<{
|
|
637
|
+
readonly type: Schema.tag<"frontmatter">;
|
|
638
|
+
readonly format: Schema.Literals<readonly ["yaml", "toml", "json"]>;
|
|
639
|
+
readonly value: Schema.String;
|
|
640
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
641
|
+
}>, {}>;
|
|
642
|
+
/**
|
|
643
|
+
* Frontmatter — the raw, fidelity-preserving capture of a document's metadata
|
|
644
|
+
* block. `value` is the source text between the fences, exactly as written
|
|
645
|
+
* (never inline-parsed, never decoded); `format` records which fence captured
|
|
646
|
+
* it. The position spans the whole block including both fence lines.
|
|
647
|
+
*
|
|
648
|
+
* mdast has no single frontmatter node: it names `yaml` in the readme and
|
|
649
|
+
* `toml` through the frontmatter extension, and json has no mdast name at
|
|
650
|
+
* all. This package captures all three through ONE node — the design doc's
|
|
651
|
+
* "text plus a format marker" — and the `Mdast` projection (P5) maps
|
|
652
|
+
* `format` onto the mdast type names where they exist. Decoding the value is
|
|
653
|
+
* the codec modules' job (`YamlFrontmatter`/`TomlFrontmatter`/
|
|
654
|
+
* `JsonFrontmatter`, P3 Task 2); the engine never looks inside it.
|
|
655
|
+
*
|
|
656
|
+
* Only ever the first child of {@link Root}, and only when parsing opted in
|
|
657
|
+
* via `MarkdownParseOptions.frontmatter` — mdast's "limited to one node, only
|
|
658
|
+
* as head" constraint is structural here, not validated.
|
|
659
|
+
*
|
|
660
|
+
* @public
|
|
661
|
+
*/
|
|
662
|
+
declare class Frontmatter extends Frontmatter_base {}
|
|
663
|
+
/**
|
|
664
|
+
* The union of every node that may appear where mdast expects
|
|
665
|
+
* **frontmatter** content — a one-member union, kept because mdast names the
|
|
666
|
+
* category (its member there is `Yaml`; ours is the format-agnostic capture).
|
|
667
|
+
*
|
|
668
|
+
* @public
|
|
669
|
+
*/
|
|
670
|
+
declare const FrontmatterContent: Schema.Codec<FrontmatterContent>;
|
|
671
|
+
/**
|
|
672
|
+
* The union of all frontmatter-content node types.
|
|
673
|
+
*
|
|
674
|
+
* @public
|
|
675
|
+
*/
|
|
676
|
+
type FrontmatterContent = Frontmatter;
|
|
677
|
+
declare const Root_base: Schema.Class<Root, Schema.Struct<{
|
|
678
|
+
readonly type: Schema.tag<"root">;
|
|
679
|
+
readonly children: Schema.$Array<Schema.suspend<Schema.Codec<Frontmatter | FlowContent, Frontmatter | FlowContent, never, never>>>;
|
|
680
|
+
readonly position: Schema.withConstructorDefault<typeof Position>;
|
|
681
|
+
}>, {}>;
|
|
682
|
+
/**
|
|
683
|
+
* Root — a whole document, and the only node that is never a child.
|
|
684
|
+
*
|
|
685
|
+
* mdast leaves a root's content model open; a parsed markdown document is
|
|
686
|
+
* flow content, optionally headed by one {@link Frontmatter} node — mdast's
|
|
687
|
+
* `FlowContentFrontmatter` merge, which admits frontmatter at the root and
|
|
688
|
+
* nowhere else.
|
|
689
|
+
*
|
|
690
|
+
* @public
|
|
691
|
+
*/
|
|
692
|
+
declare class Root extends Root_base {}
|
|
693
|
+
/**
|
|
694
|
+
* The union of every mdast node type this package produces — the content
|
|
695
|
+
* categories plus {@link Root}.
|
|
696
|
+
*
|
|
697
|
+
* @public
|
|
698
|
+
*/
|
|
699
|
+
type MarkdownNode = Root | FrontmatterContent | FlowContent | ListContent | PhrasingContent | RowContent | TableContent;
|
|
700
|
+
/**
|
|
701
|
+
* A schema matching any node in the tree.
|
|
702
|
+
*
|
|
703
|
+
* @public
|
|
704
|
+
*/
|
|
705
|
+
declare const MarkdownNode: Schema.Codec<MarkdownNode>;
|
|
706
|
+
/**
|
|
707
|
+
* The union of every node `type` tag this package produces — the selector
|
|
708
|
+
* vocabulary of `MarkdownDocument.find`/`findAll`.
|
|
709
|
+
*
|
|
710
|
+
* @public
|
|
711
|
+
*/
|
|
712
|
+
type MarkdownNodeType = MarkdownNode["type"];
|
|
713
|
+
/**
|
|
714
|
+
* The node class whose `type` tag is `T` — how a type-string selector narrows
|
|
715
|
+
* its result (`MarkdownNodeOfType<"heading">` is {@link Heading}).
|
|
716
|
+
*
|
|
717
|
+
* @public
|
|
718
|
+
*/
|
|
719
|
+
type MarkdownNodeOfType<T extends MarkdownNodeType> = Extract<MarkdownNode, {
|
|
720
|
+
readonly type: T;
|
|
721
|
+
}>;
|
|
722
|
+
//#endregion
|
|
723
|
+
//#region src/MarkdownDiagnostic.d.ts
|
|
724
|
+
/**
|
|
725
|
+
* Error codes `Markdown.parse`/`MarkdownDocument.parse` can fail with. P1
|
|
726
|
+
* registers exactly the hardening-guard trip; later phases widen the union
|
|
727
|
+
* as new fatal (as opposed to diagnostic-only) conditions are identified.
|
|
728
|
+
*
|
|
729
|
+
* @public
|
|
730
|
+
*/
|
|
731
|
+
declare const MarkdownParseErrorCode: Schema.Literals<readonly ["NestingDepthExceeded"]>;
|
|
732
|
+
/**
|
|
733
|
+
* The union of all markdown parse-error code string literals.
|
|
734
|
+
*
|
|
735
|
+
* @public
|
|
736
|
+
*/
|
|
737
|
+
type MarkdownParseErrorCode = typeof MarkdownParseErrorCode.Type;
|
|
738
|
+
declare const MarkdownDiagnostic_base: Schema.Class<MarkdownDiagnostic, Schema.Struct<{
|
|
739
|
+
readonly code: Schema.Literals<readonly ["NestingDepthExceeded"]>;
|
|
740
|
+
readonly message: Schema.String;
|
|
741
|
+
readonly offset: Schema.Number;
|
|
742
|
+
readonly length: Schema.Number;
|
|
743
|
+
readonly line: Schema.Number;
|
|
744
|
+
readonly character: Schema.Number;
|
|
745
|
+
}>, {}>;
|
|
746
|
+
/**
|
|
747
|
+
* One structured diagnostic: its {@link (MarkdownParseErrorCode:type)}, a
|
|
748
|
+
* human-readable `message`, and its exact position (`offset`/`length`, plus
|
|
749
|
+
* zero-based `line`/`character`).
|
|
750
|
+
*
|
|
751
|
+
* @remarks
|
|
752
|
+
* The five-field positional core (`code`/`offset`/`length`/`line`/`character`)
|
|
753
|
+
* is structurally identical to `@effected/toml`'s `TomlDiagnostic` (and, by
|
|
754
|
+
* the same cross-package contract, `@effected/jsonc`'s parse-error detail
|
|
755
|
+
* shape and `@effected/yaml`'s `YamlDiagnostic`); `message` is this
|
|
756
|
+
* package's additive extra. `line`/`character` here are zero-based to match
|
|
757
|
+
* that contract — a different numbering from the one-based `line`/`column`
|
|
758
|
+
* unist `Point`s carried on `MarkdownNode` positions (`internal/lineIndex.ts`),
|
|
759
|
+
* which is a deliberate, unrelated convention for the AST rather than a
|
|
760
|
+
* mismatch to reconcile.
|
|
761
|
+
*
|
|
762
|
+
* @public
|
|
763
|
+
*/
|
|
764
|
+
declare class MarkdownDiagnostic extends MarkdownDiagnostic_base {
|
|
765
|
+
/**
|
|
766
|
+
* Materialize an engine record, deriving zero-based `line`/`character`
|
|
767
|
+
* from `offset` against the source `text`. Advanced — the parse entry
|
|
768
|
+
* points call this for you.
|
|
769
|
+
*/
|
|
770
|
+
static fromRaw(source: string, raw: {
|
|
771
|
+
readonly code: MarkdownParseErrorCode;
|
|
772
|
+
readonly message: string;
|
|
773
|
+
readonly offset: number;
|
|
774
|
+
readonly length: number;
|
|
775
|
+
}): MarkdownDiagnostic;
|
|
776
|
+
}
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/Markdown.d.ts
|
|
779
|
+
/**
|
|
780
|
+
* The markdown dialects the parser can be pointed at. `"gfm"` — CommonMark
|
|
781
|
+
* 0.31.2 plus the GitHub extensions (tables, strikethrough, autolink
|
|
782
|
+
* literals, task-list items, footnotes, and the tagfilter's output contract)
|
|
783
|
+
* — is the default; `"commonmark"` opts out of every extension. A dialect is
|
|
784
|
+
* a registry composition in the engine, so widening this union is additive
|
|
785
|
+
* and never changes an existing dialect's behavior.
|
|
786
|
+
*
|
|
787
|
+
* @public
|
|
788
|
+
*/
|
|
789
|
+
declare const MarkdownDialect: Schema.Literals<readonly ["commonmark", "gfm"]>;
|
|
790
|
+
/**
|
|
791
|
+
* The union of all markdown dialect string literals.
|
|
792
|
+
*
|
|
793
|
+
* @public
|
|
794
|
+
*/
|
|
795
|
+
type MarkdownDialect = typeof MarkdownDialect.Type;
|
|
796
|
+
declare const MarkdownParseOptions_base: Schema.Class<MarkdownParseOptions, Schema.Struct<{
|
|
797
|
+
readonly dialect: Schema.optionalKey<Schema.Literals<readonly ["commonmark", "gfm"]>>;
|
|
798
|
+
readonly frontmatter: Schema.optionalKey<Schema.Boolean>;
|
|
799
|
+
}>, {}>;
|
|
800
|
+
/**
|
|
801
|
+
* Options controlling parse behavior: `dialect` (omitted, `"gfm"`) and
|
|
802
|
+
* `frontmatter` (omitted, `false` — capture is opt-in).
|
|
803
|
+
*
|
|
804
|
+
* @remarks
|
|
805
|
+
* Frontmatter capture is OFF by default because it changes how a document
|
|
806
|
+
* opening with `---` parses: CommonMark reads the fence document
|
|
807
|
+
* `---\nfoo: bar\n---` as a thematic break and a setext heading, and that
|
|
808
|
+
* spec-conformant reading must hold unless a consumer opts in. Enabled, the
|
|
809
|
+
* engine captures `---`/`+++`/`---json` blocks at offset 0 into a raw
|
|
810
|
+
* `Frontmatter` head node — decoding it is the frontmatter codec modules'
|
|
811
|
+
* job.
|
|
812
|
+
*
|
|
813
|
+
* @public
|
|
814
|
+
*/
|
|
815
|
+
declare class MarkdownParseOptions extends MarkdownParseOptions_base {}
|
|
816
|
+
declare const MarkdownParseError_base: Schema.Class<MarkdownParseError, Schema.TaggedStruct<"MarkdownParseError", {
|
|
817
|
+
readonly diagnostic: typeof MarkdownDiagnostic;
|
|
818
|
+
}>, import("effect/Cause").YieldableError>;
|
|
819
|
+
/**
|
|
820
|
+
* Parse failure: the {@link MarkdownDiagnostic} describing why the document
|
|
821
|
+
* was rejected.
|
|
822
|
+
*
|
|
823
|
+
* @remarks
|
|
824
|
+
* CommonMark has no syntax errors — every string is a valid document — so
|
|
825
|
+
* this error carries only hardening-guard trips (P1: `NestingDepthExceeded`).
|
|
826
|
+
* Recoverable oddities are diagnostics on {@link MarkdownDocument}, not
|
|
827
|
+
* failures. A malformed-looking document parses; a nesting bomb fails here
|
|
828
|
+
* rather than crashing with a `RangeError`.
|
|
829
|
+
*
|
|
830
|
+
* @public
|
|
831
|
+
*/
|
|
832
|
+
declare class MarkdownParseError extends MarkdownParseError_base {
|
|
833
|
+
get message(): string;
|
|
834
|
+
}
|
|
835
|
+
declare const MarkdownStringifyError_base: Schema.Class<MarkdownStringifyError, Schema.TaggedStruct<"MarkdownStringifyError", {
|
|
836
|
+
readonly diagnostic: typeof MarkdownDiagnostic;
|
|
837
|
+
}>, import("effect/Cause").YieldableError>;
|
|
838
|
+
/**
|
|
839
|
+
* Stringify failure: the {@link MarkdownDiagnostic} describing why the tree
|
|
840
|
+
* was refused.
|
|
841
|
+
*
|
|
842
|
+
* @remarks
|
|
843
|
+
* Serialization is total over parser-produced trees — the parser cannot
|
|
844
|
+
* produce one that nests past the guard, because parsing it would have been
|
|
845
|
+
* refused first. The only failures here are hardening-guard trips on
|
|
846
|
+
* synthesized or decoded hostile trees, symmetric with
|
|
847
|
+
* {@link MarkdownParseError}'s posture on parse. Stringify has no source
|
|
848
|
+
* text to derive positions from, so the diagnostic's `line`/`character` are
|
|
849
|
+
* `0` and `offset` carries whatever the offending node's position claimed.
|
|
850
|
+
*
|
|
851
|
+
* @public
|
|
852
|
+
*/
|
|
853
|
+
declare class MarkdownStringifyError extends MarkdownStringifyError_base {
|
|
854
|
+
get message(): string;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* The markdown facade: parse markdown source — GFM by default, CommonMark by
|
|
858
|
+
* option — into an mdast-shaped {@link Root} tree, as a pure `Result` or as
|
|
859
|
+
* an `Effect`.
|
|
860
|
+
*
|
|
861
|
+
* @public
|
|
862
|
+
*/
|
|
863
|
+
declare class Markdown {
|
|
864
|
+
/**
|
|
865
|
+
* Parse markdown into a {@link Root} tree, synchronously, as a `Result`.
|
|
866
|
+
* The pure primitive: a non-Effect caller (a build script, a Vite plugin,
|
|
867
|
+
* a language-server tick) can call this directly instead of wrapping
|
|
868
|
+
* `Effect.runSync(Effect.result(Markdown.parse(text)))`.
|
|
869
|
+
*
|
|
870
|
+
* @remarks
|
|
871
|
+
* {@link Markdown.parse} is defined in terms of this function; the two
|
|
872
|
+
* never diverge. Reach for the `Effect` variant inside Effect code — it
|
|
873
|
+
* carries the `Markdown.parse` tracing span — and for this one at
|
|
874
|
+
* synchronous boundaries. This function carries no span: it is not an
|
|
875
|
+
* `Effect`.
|
|
876
|
+
*
|
|
877
|
+
* Failure is rare by design: every string is a valid markdown document in
|
|
878
|
+
* both dialects, so the only failures are hardening-guard trips such as
|
|
879
|
+
* nesting past the 256-container cap. Programmer errors are not converted
|
|
880
|
+
* — they propagate as thrown defects.
|
|
881
|
+
*
|
|
882
|
+
* @example
|
|
883
|
+
* ```ts
|
|
884
|
+
* import { Markdown } from "@effected/markdown";
|
|
885
|
+
* import { Result } from "effect";
|
|
886
|
+
*
|
|
887
|
+
* const ok = Markdown.parseResult("# Title\n\nBody *text*.\n");
|
|
888
|
+
* if (Result.isSuccess(ok)) {
|
|
889
|
+
* console.log(ok.success.children.length); // => 2
|
|
890
|
+
* }
|
|
891
|
+
* ```
|
|
892
|
+
*
|
|
893
|
+
* @param text - The markdown source to parse.
|
|
894
|
+
* @param options - Optional {@link MarkdownParseOptions}; the dialect
|
|
895
|
+
* defaults to `"gfm"`.
|
|
896
|
+
* @returns A `Result` succeeding with the document {@link Root}, or
|
|
897
|
+
* failing with {@link MarkdownParseError}.
|
|
898
|
+
*/
|
|
899
|
+
static parseResult(text: string, options?: MarkdownParseOptions): Result.Result<Root, MarkdownParseError>;
|
|
900
|
+
/**
|
|
901
|
+
* Parse markdown into a {@link Root} tree. Defined in terms of
|
|
902
|
+
* {@link Markdown.parseResult} — synchronous callers can use that variant
|
|
903
|
+
* directly.
|
|
904
|
+
*
|
|
905
|
+
* @param text - The markdown source to parse.
|
|
906
|
+
* @param options - Optional {@link MarkdownParseOptions}; the dialect
|
|
907
|
+
* defaults to `"gfm"`.
|
|
908
|
+
* @returns An `Effect` that succeeds with the document {@link Root}, or
|
|
909
|
+
* fails with {@link MarkdownParseError}.
|
|
910
|
+
*/
|
|
911
|
+
static readonly parse: (text: string, options?: MarkdownParseOptions | undefined) => Effect.Effect<Root, MarkdownParseError, never>;
|
|
912
|
+
/**
|
|
913
|
+
* Serialize a {@link Root} tree to canonical markdown, synchronously, as a
|
|
914
|
+
* `Result`. The pure primitive twin of {@link Markdown.stringify}, on the
|
|
915
|
+
* same terms as {@link Markdown.parseResult}.
|
|
916
|
+
*
|
|
917
|
+
* @remarks
|
|
918
|
+
* Canonical serialization: fidelity fields (marker characters, fence
|
|
919
|
+
* style, heading spelling) win when present; documented canonical
|
|
920
|
+
* defaults apply when absent. The output re-parses to a render-equivalent
|
|
921
|
+
* document — the corpus-pinned contract — but is not a byte-level
|
|
922
|
+
* round-trip of any original source; surgical editing goes through the
|
|
923
|
+
* offset-splice edit layer instead.
|
|
924
|
+
*
|
|
925
|
+
* Failure is rare by design, symmetric with parse: only a hardening-guard
|
|
926
|
+
* trip on a tree nesting past the depth cap fails, and only synthesized
|
|
927
|
+
* or decoded trees can nest that far.
|
|
928
|
+
*
|
|
929
|
+
* @param root - The document tree to serialize.
|
|
930
|
+
* @returns A `Result` succeeding with markdown source, or failing with
|
|
931
|
+
* {@link MarkdownStringifyError}.
|
|
932
|
+
*/
|
|
933
|
+
static stringifyResult(root: Root): Result.Result<string, MarkdownStringifyError>;
|
|
934
|
+
/**
|
|
935
|
+
* Serialize a {@link Root} tree to canonical markdown. Defined in terms of
|
|
936
|
+
* {@link Markdown.stringifyResult} — synchronous callers can use that
|
|
937
|
+
* variant directly.
|
|
938
|
+
*
|
|
939
|
+
* @param root - The document tree to serialize.
|
|
940
|
+
* @returns An `Effect` that succeeds with markdown source, or fails with
|
|
941
|
+
* {@link MarkdownStringifyError}.
|
|
942
|
+
*/
|
|
943
|
+
static readonly stringify: (root: Root) => Effect.Effect<string, MarkdownStringifyError, never>;
|
|
944
|
+
/**
|
|
945
|
+
* A `Schema<Root, string>` decoding markdown source into a {@link Root}
|
|
946
|
+
* tree and encoding a tree back to canonical markdown via
|
|
947
|
+
* {@link Markdown.stringifyResult}.
|
|
948
|
+
*
|
|
949
|
+
* @remarks
|
|
950
|
+
* Schema-producing: each call returns a fresh schema whose derivation
|
|
951
|
+
* caches are not shared across calls. Bind the result to a `const` on hot
|
|
952
|
+
* paths; the pre-bound {@link Markdown.MarkdownFromString} covers the
|
|
953
|
+
* common case.
|
|
954
|
+
*
|
|
955
|
+
* @param options - Optional {@link MarkdownParseOptions} applied on
|
|
956
|
+
* decode.
|
|
957
|
+
* @returns A `Schema.Codec<Root, string>`.
|
|
958
|
+
*/
|
|
959
|
+
static fromString(options?: MarkdownParseOptions): Schema.Codec<Root, string>;
|
|
960
|
+
/**
|
|
961
|
+
* The zero-config `Schema<Root, string>` — `Markdown.fromString()`
|
|
962
|
+
* pre-bound so the common case needs no memoization discipline.
|
|
963
|
+
*/
|
|
964
|
+
static readonly MarkdownFromString: Schema.Codec<Root, string>;
|
|
965
|
+
}
|
|
966
|
+
//#endregion
|
|
967
|
+
//#region src/MarkdownEdit.d.ts
|
|
968
|
+
/**
|
|
969
|
+
* A single path segment: a `number` for child indices in the node tree, or a
|
|
970
|
+
* `string` for named addressing (reserved for the navigation surface — e.g.
|
|
971
|
+
* definition identifiers — which arrives with the visitor phase).
|
|
972
|
+
*
|
|
973
|
+
* @public
|
|
974
|
+
*/
|
|
975
|
+
type MarkdownSegment = string | number;
|
|
976
|
+
/**
|
|
977
|
+
* An ordered sequence of {@link MarkdownSegment} values describing a location
|
|
978
|
+
* within a markdown document tree.
|
|
979
|
+
*
|
|
980
|
+
* @public
|
|
981
|
+
*/
|
|
982
|
+
type MarkdownPath = ReadonlyArray<MarkdownSegment>;
|
|
983
|
+
declare const MarkdownRange_base: Schema.Class<MarkdownRange, Schema.Struct<{
|
|
984
|
+
readonly offset: Schema.Number;
|
|
985
|
+
readonly length: Schema.Number;
|
|
986
|
+
}>, {}>;
|
|
987
|
+
/**
|
|
988
|
+
* A range within a markdown document, expressed as a zero-based character
|
|
989
|
+
* `offset` and a `length` in UTF-16 code units. Pass to `MarkdownFormat.format`
|
|
990
|
+
* to restrict formatting to a region.
|
|
991
|
+
*
|
|
992
|
+
* @public
|
|
993
|
+
*/
|
|
994
|
+
declare class MarkdownRange extends MarkdownRange_base {}
|
|
995
|
+
declare const MarkdownEdit_base: Schema.Class<MarkdownEdit, Schema.Struct<{
|
|
996
|
+
readonly offset: Schema.Number;
|
|
997
|
+
readonly length: Schema.Number;
|
|
998
|
+
readonly content: Schema.String;
|
|
999
|
+
}>, {}>;
|
|
1000
|
+
/**
|
|
1001
|
+
* A non-mutating text edit: replace the span `[offset, offset + length)` with
|
|
1002
|
+
* `content`. Set `length` to `0` to insert, `content` to `""` to delete.
|
|
1003
|
+
*
|
|
1004
|
+
* @remarks
|
|
1005
|
+
* Structurally identical to `@effected/jsonc`'s, `@effected/yaml`'s and
|
|
1006
|
+
* `@effected/toml`'s edit shapes (same field names, types and semantics) per
|
|
1007
|
+
* the cross-package parity convention, so consumer code can be written once
|
|
1008
|
+
* over "a document codec's Edit/Range/Path".
|
|
1009
|
+
*
|
|
1010
|
+
* @public
|
|
1011
|
+
*/
|
|
1012
|
+
declare class MarkdownEdit extends MarkdownEdit_base {
|
|
1013
|
+
/**
|
|
1014
|
+
* Apply `edits` to `text`, producing a new string. Edits are applied in
|
|
1015
|
+
* reverse-offset order so earlier offsets stay valid; the input `edits`
|
|
1016
|
+
* array is not mutated. Overlapping edits are a programmer error and throw
|
|
1017
|
+
* as a defect — `MarkdownFormat` never produces them.
|
|
1018
|
+
*/
|
|
1019
|
+
static applyAll(text: string, edits: ReadonlyArray<MarkdownEdit>): string;
|
|
1020
|
+
}
|
|
1021
|
+
//#endregion
|
|
1022
|
+
//#region src/MarkdownDocument.d.ts
|
|
1023
|
+
/**
|
|
1024
|
+
* A heading entry from {@link MarkdownDocument.headings}: the {@link Heading}
|
|
1025
|
+
* node plus the derivations navigation wants — its `depth` and its plain-text
|
|
1026
|
+
* content.
|
|
1027
|
+
*
|
|
1028
|
+
* @remarks
|
|
1029
|
+
* `text` concatenates the values of text and inline-code descendants, uses
|
|
1030
|
+
* image `alt` text where present, renders a hard break as a single space and
|
|
1031
|
+
* contributes nothing for raw HTML or footnote references.
|
|
1032
|
+
*
|
|
1033
|
+
* @public
|
|
1034
|
+
*/
|
|
1035
|
+
interface DocumentHeading {
|
|
1036
|
+
readonly node: Heading;
|
|
1037
|
+
readonly depth: HeadingDepth;
|
|
1038
|
+
readonly text: string;
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* A heading-delimited span from {@link MarkdownDocument.sections}: the
|
|
1042
|
+
* heading, its depth, the source `range` the section occupies and the
|
|
1043
|
+
* root-level blocks that follow the heading inside it.
|
|
1044
|
+
*
|
|
1045
|
+
* @remarks
|
|
1046
|
+
* A section runs from its heading's start offset to the start of the next
|
|
1047
|
+
* root-level heading of equal or shallower depth, or to the end of the
|
|
1048
|
+
* source. Deeper headings nest inside, so a parent section's `range` and
|
|
1049
|
+
* `children` include its subsections — the list is flat, in document order,
|
|
1050
|
+
* with `depth` carrying the hierarchy.
|
|
1051
|
+
*
|
|
1052
|
+
* @public
|
|
1053
|
+
*/
|
|
1054
|
+
interface DocumentSection {
|
|
1055
|
+
readonly heading: Heading;
|
|
1056
|
+
readonly depth: HeadingDepth;
|
|
1057
|
+
readonly range: MarkdownRange;
|
|
1058
|
+
readonly children: ReadonlyArray<FlowContent>;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* The node types {@link MarkdownDocument.links} collects: the nodes that
|
|
1062
|
+
* carry an outbound URL themselves ({@link Link}, {@link Image},
|
|
1063
|
+
* {@link Definition}) and the reference nodes that reach one through the
|
|
1064
|
+
* definition index ({@link LinkReference}, {@link ImageReference}).
|
|
1065
|
+
*
|
|
1066
|
+
* @public
|
|
1067
|
+
*/
|
|
1068
|
+
type LinkBearingNode = Link | Image | Definition | LinkReference | ImageReference;
|
|
1069
|
+
/**
|
|
1070
|
+
* A link entry from {@link MarkdownDocument.links}: the link-bearing node and
|
|
1071
|
+
* the URL it points at.
|
|
1072
|
+
*
|
|
1073
|
+
* @remarks
|
|
1074
|
+
* `url` is the node's own `url` field, unmodified — bundle-relative and
|
|
1075
|
+
* otherwise non-normalized hrefs pass through exactly as written. For
|
|
1076
|
+
* reference nodes it is the matching definition's `url`; when no definition
|
|
1077
|
+
* matches (possible only on trees decoded from foreign mdast — the parser
|
|
1078
|
+
* never forms an unmatched reference), the field is genuinely absent.
|
|
1079
|
+
*
|
|
1080
|
+
* @public
|
|
1081
|
+
*/
|
|
1082
|
+
interface DocumentLink {
|
|
1083
|
+
readonly node: LinkBearingNode;
|
|
1084
|
+
readonly url?: string;
|
|
1085
|
+
}
|
|
1086
|
+
declare const MarkdownDocument_base: Schema.Class<MarkdownDocument, Schema.Struct<{
|
|
1087
|
+
readonly source: Schema.String;
|
|
1088
|
+
readonly root: typeof Root;
|
|
1089
|
+
readonly diagnostics: Schema.$Array<typeof MarkdownDiagnostic>;
|
|
1090
|
+
readonly definitions: Schema.$ReadonlyMap<Schema.String, typeof Definition>;
|
|
1091
|
+
}>, {}>;
|
|
1092
|
+
/**
|
|
1093
|
+
* A parsed markdown document: the original `source`, the mdast-shaped
|
|
1094
|
+
* {@link Root} tree, the non-fatal {@link MarkdownDiagnostic}s the parse
|
|
1095
|
+
* produced, and the link-reference `definitions` index.
|
|
1096
|
+
*
|
|
1097
|
+
* @remarks
|
|
1098
|
+
* The document is the lossless unit — `source` is retained so offsets on the
|
|
1099
|
+
* tree stay meaningful and so P4's edit/format layer can splice against the
|
|
1100
|
+
* exact bytes that were parsed.
|
|
1101
|
+
*
|
|
1102
|
+
* `definitions` is an index over the {@link Definition} nodes that remain in
|
|
1103
|
+
* the tree, keyed by case-folded label with the first definition winning; it
|
|
1104
|
+
* is not a place they were moved to. References are emitted unresolved, so
|
|
1105
|
+
* resolution happens against this map.
|
|
1106
|
+
*
|
|
1107
|
+
* `diagnostics` is empty for every input the P1 parser accepts, and that is
|
|
1108
|
+
* the current state of the world rather than a missing feature: the plumbing
|
|
1109
|
+
* from the engine through to this field is real and exercised, but no P1
|
|
1110
|
+
* construct emits a non-fatal diagnostic yet. The producers arrive with the
|
|
1111
|
+
* conditions that warrant them — unresolved link references, and
|
|
1112
|
+
* present-but-unparseable frontmatter in P3. Read an empty array as "nothing
|
|
1113
|
+
* to report", not as "not implemented", and do not code against it staying
|
|
1114
|
+
* empty.
|
|
1115
|
+
*
|
|
1116
|
+
* The navigation accessors (`headings`, `sections`, `links`) are derived
|
|
1117
|
+
* getters over the tree — no stored state, no parse-time cost, and they can
|
|
1118
|
+
* never disagree with the tree they read.
|
|
1119
|
+
*
|
|
1120
|
+
* @public
|
|
1121
|
+
*/
|
|
1122
|
+
declare class MarkdownDocument extends MarkdownDocument_base {
|
|
1123
|
+
/**
|
|
1124
|
+
* The document's frontmatter capture, or `undefined` when there is none.
|
|
1125
|
+
*
|
|
1126
|
+
* @remarks
|
|
1127
|
+
* Derived from the tree rather than stored: a {@link Frontmatter} node can
|
|
1128
|
+
* only ever sit at the head of `root.children` (the capture fires at most
|
|
1129
|
+
* once, at offset 0), so the tree is the single source of truth and the
|
|
1130
|
+
* accessor can never disagree with it. `undefined` covers both a document
|
|
1131
|
+
* with no frontmatter block and one parsed with the capture toggle off.
|
|
1132
|
+
*/
|
|
1133
|
+
get frontmatter(): Frontmatter | undefined;
|
|
1134
|
+
/**
|
|
1135
|
+
* Every heading in the document, in document order, wherever it sits —
|
|
1136
|
+
* including headings nested inside blockquotes and list items.
|
|
1137
|
+
*
|
|
1138
|
+
* @remarks
|
|
1139
|
+
* Each {@link DocumentHeading} carries the node, its depth and its
|
|
1140
|
+
* plain-text content. For an outline restricted to section boundaries, use
|
|
1141
|
+
* {@link MarkdownDocument.sections}, which considers root-level headings
|
|
1142
|
+
* only.
|
|
1143
|
+
*/
|
|
1144
|
+
get headings(): ReadonlyArray<DocumentHeading>;
|
|
1145
|
+
/**
|
|
1146
|
+
* The document's heading-delimited sections, flat and in document order.
|
|
1147
|
+
*
|
|
1148
|
+
* @remarks
|
|
1149
|
+
* Only root-level headings delimit sections — a heading inside a
|
|
1150
|
+
* blockquote or list cannot mark a span of root-level source. Content
|
|
1151
|
+
* before the first heading (the preamble) and the frontmatter block belong
|
|
1152
|
+
* to no section. Each {@link DocumentSection.range} is spliceable by the
|
|
1153
|
+
* edit layer: it runs from the heading's start offset to the next
|
|
1154
|
+
* boundary heading's start, or to the end of the source.
|
|
1155
|
+
*/
|
|
1156
|
+
get sections(): ReadonlyArray<DocumentSection>;
|
|
1157
|
+
/**
|
|
1158
|
+
* Every link-bearing node in the document, in document order: links,
|
|
1159
|
+
* images, definitions, and the reference forms resolved through the
|
|
1160
|
+
* definition index.
|
|
1161
|
+
*
|
|
1162
|
+
* @remarks
|
|
1163
|
+
* See {@link DocumentLink} for the url semantics — the raw `url` string
|
|
1164
|
+
* passes through unmodified, and an unresolvable foreign reference leaves
|
|
1165
|
+
* the field genuinely absent. Autolinks and GFM autolink literals are
|
|
1166
|
+
* {@link Link} nodes, so they appear with no special casing. Footnote
|
|
1167
|
+
* references carry no URL and are not link entries.
|
|
1168
|
+
*/
|
|
1169
|
+
get links(): ReadonlyArray<DocumentLink>;
|
|
1170
|
+
/**
|
|
1171
|
+
* Find the first node matching a selector, in document pre-order — the
|
|
1172
|
+
* same order {@link MarkdownVisitor} enters nodes, starting at the root
|
|
1173
|
+
* itself.
|
|
1174
|
+
*
|
|
1175
|
+
* @remarks
|
|
1176
|
+
* A string selector matches on the node's `type` tag and narrows the
|
|
1177
|
+
* result (`find("heading")` is `Heading | undefined`); a type-guard
|
|
1178
|
+
* predicate narrows the same way, and a plain predicate returns the wide
|
|
1179
|
+
* `MarkdownNode` union. The returned node is the document's own — matched
|
|
1180
|
+
* and returnable by identity, so it feeds `MarkdownFormat.modify`
|
|
1181
|
+
* directly. Like the navigation getters, the walk is synchronous with no
|
|
1182
|
+
* error channel: a tree nested past the depth cap (reachable only via a
|
|
1183
|
+
* hand-built or foreign decoded tree) is a thrown defect.
|
|
1184
|
+
*
|
|
1185
|
+
* @param selector - A node `type` tag or a predicate over nodes.
|
|
1186
|
+
* @returns The first matching node in document order, or `undefined`.
|
|
1187
|
+
*/
|
|
1188
|
+
find<T extends MarkdownNodeType>(selector: T): MarkdownNodeOfType<T> | undefined;
|
|
1189
|
+
find<T extends MarkdownNode>(selector: (node: MarkdownNode) => node is T): T | undefined;
|
|
1190
|
+
find(selector: (node: MarkdownNode) => boolean): MarkdownNode | undefined;
|
|
1191
|
+
/**
|
|
1192
|
+
* Find every node matching a selector, in document pre-order — the same
|
|
1193
|
+
* order {@link MarkdownVisitor} enters nodes, starting at the root itself.
|
|
1194
|
+
*
|
|
1195
|
+
* @remarks
|
|
1196
|
+
* Selector and narrowing semantics are `MarkdownDocument.find`'s; so is
|
|
1197
|
+
* the guard posture — an over-deep hand-built or foreign tree is a
|
|
1198
|
+
* thrown defect. Nodes are the document's own, matched by identity, so
|
|
1199
|
+
* `findAll("heading")[1]` addresses the second heading for
|
|
1200
|
+
* `MarkdownFormat.modify` without raw child indexing.
|
|
1201
|
+
*
|
|
1202
|
+
* @param selector - A node `type` tag or a predicate over nodes.
|
|
1203
|
+
* @returns Every matching node, in document order; empty when none match.
|
|
1204
|
+
*/
|
|
1205
|
+
findAll<T extends MarkdownNodeType>(selector: T): ReadonlyArray<MarkdownNodeOfType<T>>;
|
|
1206
|
+
findAll<T extends MarkdownNode>(selector: (node: MarkdownNode) => node is T): ReadonlyArray<T>;
|
|
1207
|
+
findAll(selector: (node: MarkdownNode) => boolean): ReadonlyArray<MarkdownNode>;
|
|
1208
|
+
/**
|
|
1209
|
+
* Parse markdown into a {@link MarkdownDocument}, synchronously, as a
|
|
1210
|
+
* `Result`. The pure primitive; {@link MarkdownDocument.parse} is defined
|
|
1211
|
+
* in terms of it, so the two never diverge.
|
|
1212
|
+
*
|
|
1213
|
+
* @remarks
|
|
1214
|
+
* Carries no span: it is not an `Effect`. Effect callers should reach for
|
|
1215
|
+
* {@link MarkdownDocument.parse}, which carries the
|
|
1216
|
+
* `MarkdownDocument.parse` tracing span.
|
|
1217
|
+
*
|
|
1218
|
+
* @param text - The markdown source to parse.
|
|
1219
|
+
* @param options - Optional {@link MarkdownParseOptions}; the dialect
|
|
1220
|
+
* defaults to `"gfm"`.
|
|
1221
|
+
* @returns A `Result` succeeding with the document, or failing with
|
|
1222
|
+
* `MarkdownParseError`.
|
|
1223
|
+
*/
|
|
1224
|
+
static parseResult(text: string, options?: MarkdownParseOptions): Result.Result<MarkdownDocument, MarkdownParseError>;
|
|
1225
|
+
/**
|
|
1226
|
+
* Parse markdown into a {@link MarkdownDocument}. Defined in terms of
|
|
1227
|
+
* {@link MarkdownDocument.parseResult} — synchronous callers can use that
|
|
1228
|
+
* variant directly.
|
|
1229
|
+
*
|
|
1230
|
+
* @param text - The markdown source to parse.
|
|
1231
|
+
* @param options - Optional {@link MarkdownParseOptions}; the dialect
|
|
1232
|
+
* defaults to `"gfm"`.
|
|
1233
|
+
* @returns An `Effect` that succeeds with the document, or fails with
|
|
1234
|
+
* `MarkdownParseError`.
|
|
1235
|
+
*/
|
|
1236
|
+
static readonly parse: (text: string, options?: MarkdownParseOptions | undefined) => Effect.Effect<MarkdownDocument, MarkdownParseError, never>;
|
|
1237
|
+
}
|
|
1238
|
+
//#endregion
|
|
1239
|
+
//#region src/Frontmatter.d.ts
|
|
1240
|
+
declare const FrontmatterFormatMismatchError_base: Schema.Class<FrontmatterFormatMismatchError, Schema.TaggedStruct<"FrontmatterFormatMismatchError", {
|
|
1241
|
+
/** The format the codec decodes. */
|
|
1242
|
+
readonly expected: Schema.Literals<readonly ["yaml", "toml", "json"]>;
|
|
1243
|
+
/** The format the capture node actually carries. */
|
|
1244
|
+
readonly actual: Schema.Literals<readonly ["yaml", "toml", "json"]>;
|
|
1245
|
+
}>, import("effect/Cause").YieldableError>;
|
|
1246
|
+
/**
|
|
1247
|
+
* Indicates that a frontmatter codec was handed a capture of a different
|
|
1248
|
+
* format — a yaml codec applied to a `+++` toml capture, for example.
|
|
1249
|
+
*
|
|
1250
|
+
* @remarks
|
|
1251
|
+
* The mismatch is detected before any parsing happens, so `cause`-free: the
|
|
1252
|
+
* node's `format` marker and the codec's declared `format` simply disagree.
|
|
1253
|
+
* Route on the `"FrontmatterFormatMismatchError"` tag with `Effect.catchTag`.
|
|
1254
|
+
*
|
|
1255
|
+
* @public
|
|
1256
|
+
*/
|
|
1257
|
+
declare class FrontmatterFormatMismatchError extends FrontmatterFormatMismatchError_base {
|
|
1258
|
+
get message(): string;
|
|
1259
|
+
}
|
|
1260
|
+
declare const FrontmatterDecodeError_base: Schema.Class<FrontmatterDecodeError, Schema.TaggedStruct<"FrontmatterDecodeError", {
|
|
1261
|
+
/** The format that failed to parse. */
|
|
1262
|
+
readonly format: Schema.Literals<readonly ["yaml", "toml", "json"]>;
|
|
1263
|
+
/** The underlying format-package failure, preserved structurally. */
|
|
1264
|
+
readonly cause: Schema.Defect;
|
|
1265
|
+
}>, import("effect/Cause").YieldableError>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Indicates that a frontmatter capture's content failed to parse in its
|
|
1268
|
+
* declared format.
|
|
1269
|
+
*
|
|
1270
|
+
* @remarks
|
|
1271
|
+
* The underlying format package's failure is preserved structurally in
|
|
1272
|
+
* `cause` — never stringified — so a consumer can reach the positioned
|
|
1273
|
+
* diagnostics the format engines carry. Route on the
|
|
1274
|
+
* `"FrontmatterDecodeError"` tag with `Effect.catchTag`.
|
|
1275
|
+
*
|
|
1276
|
+
* @public
|
|
1277
|
+
*/
|
|
1278
|
+
declare class FrontmatterDecodeError extends FrontmatterDecodeError_base {
|
|
1279
|
+
get message(): string;
|
|
1280
|
+
}
|
|
1281
|
+
declare const FrontmatterEncodeError_base: Schema.Class<FrontmatterEncodeError, Schema.TaggedStruct<"FrontmatterEncodeError", {
|
|
1282
|
+
/** The format that failed to serialize. */
|
|
1283
|
+
readonly format: Schema.Literals<readonly ["yaml", "toml", "json"]>;
|
|
1284
|
+
/** The underlying format-package failure, preserved structurally. */
|
|
1285
|
+
readonly cause: Schema.Defect;
|
|
1286
|
+
}>, import("effect/Cause").YieldableError>;
|
|
1287
|
+
/**
|
|
1288
|
+
* Indicates that frontmatter data failed to serialize in a codec's format.
|
|
1289
|
+
*
|
|
1290
|
+
* @remarks
|
|
1291
|
+
* The exact mirror of {@link FrontmatterDecodeError} on the write side: the
|
|
1292
|
+
* underlying format package's failure is preserved structurally in `cause` —
|
|
1293
|
+
* never stringified — so a consumer can reach the typed stringify error the
|
|
1294
|
+
* format engines carry (a `JsoncStringifyError`'s `code`, for example). Route
|
|
1295
|
+
* on the `"FrontmatterEncodeError"` tag with `Effect.catchTag`.
|
|
1296
|
+
*
|
|
1297
|
+
* @public
|
|
1298
|
+
*/
|
|
1299
|
+
declare class FrontmatterEncodeError extends FrontmatterEncodeError_base {
|
|
1300
|
+
get message(): string;
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* A frontmatter codec: how to turn a raw `Frontmatter` capture into decoded
|
|
1304
|
+
* data, and data back into a serialized frontmatter body.
|
|
1305
|
+
*
|
|
1306
|
+
* @remarks
|
|
1307
|
+
* The three built-in codecs — `YamlFrontmatter`, `TomlFrontmatter` and
|
|
1308
|
+
* `JsonFrontmatter` — are free-standing named exports, one per module, each
|
|
1309
|
+
* peering on its format package (`@effected/yaml`, `@effected/toml`,
|
|
1310
|
+
* `@effected/jsonc`). They are deliberately never collected into a namespace
|
|
1311
|
+
* object: name the one codec you use and a bundler drops the rest, engines
|
|
1312
|
+
* included.
|
|
1313
|
+
*
|
|
1314
|
+
* A codec checks the capture's `format` marker before parsing and fails with
|
|
1315
|
+
* {@link FrontmatterFormatMismatchError} when handed the wrong format;
|
|
1316
|
+
* unparseable content fails with {@link FrontmatterDecodeError} carrying the
|
|
1317
|
+
* format package's failure structurally.
|
|
1318
|
+
*
|
|
1319
|
+
* `encode` is the mirror: it serializes data to the body text that belongs
|
|
1320
|
+
* between the fences — never the fences themselves, which are
|
|
1321
|
+
* format-determined and rendered by the write seam
|
|
1322
|
+
* ({@link MarkdownFrontmatter.set}). The engine's native output is returned
|
|
1323
|
+
* as-is; the seam normalizes the final line terminator when fencing.
|
|
1324
|
+
* Serialization failures — a circular reference, a value the format cannot
|
|
1325
|
+
* represent — fail with {@link FrontmatterEncodeError} carrying the format
|
|
1326
|
+
* package's failure structurally.
|
|
1327
|
+
*
|
|
1328
|
+
* @public
|
|
1329
|
+
*/
|
|
1330
|
+
interface FrontmatterCodec {
|
|
1331
|
+
/** The format this codec decodes and encodes. */
|
|
1332
|
+
readonly format: FrontmatterFormat;
|
|
1333
|
+
/** Decode a capture node's raw value into data. */
|
|
1334
|
+
readonly decode: (node: Frontmatter) => Effect.Effect<unknown, FrontmatterDecodeError | FrontmatterFormatMismatchError>;
|
|
1335
|
+
/** Serialize data into a frontmatter body, without fences. */
|
|
1336
|
+
readonly encode: (data: unknown) => Effect.Effect<string, FrontmatterEncodeError>;
|
|
1337
|
+
}
|
|
1338
|
+
declare const FrontmatterMissingError_base: Schema.Class<FrontmatterMissingError, Schema.TaggedStruct<"FrontmatterMissingError", {}>, import("effect/Cause").YieldableError>;
|
|
1339
|
+
/**
|
|
1340
|
+
* Indicates that a document handed to a frontmatter decoder carries no
|
|
1341
|
+
* frontmatter capture.
|
|
1342
|
+
*
|
|
1343
|
+
* @remarks
|
|
1344
|
+
* Raised when the document genuinely has no frontmatter block — including
|
|
1345
|
+
* when it has one in the source but was parsed with the capture toggle off
|
|
1346
|
+
* (`MarkdownParseOptions.frontmatter` defaults to `false`). Cause-free: there
|
|
1347
|
+
* is nothing to diagnose beyond the absence itself. Consumers wanting
|
|
1348
|
+
* optional semantics can `Effect.catchTag("FrontmatterMissingError", ...)`
|
|
1349
|
+
* to a default.
|
|
1350
|
+
*
|
|
1351
|
+
* @public
|
|
1352
|
+
*/
|
|
1353
|
+
declare class FrontmatterMissingError extends FrontmatterMissingError_base {
|
|
1354
|
+
get message(): string;
|
|
1355
|
+
}
|
|
1356
|
+
declare const FrontmatterValidationError_base: Schema.Class<FrontmatterValidationError, Schema.TaggedStruct<"FrontmatterValidationError", {
|
|
1357
|
+
/** The structured schema issue. Never a string. */
|
|
1358
|
+
readonly issue: Schema.Defect;
|
|
1359
|
+
}>, import("effect/Cause").YieldableError>;
|
|
1360
|
+
/**
|
|
1361
|
+
* Indicates that decoded frontmatter data did not satisfy the consumer's
|
|
1362
|
+
* schema.
|
|
1363
|
+
*
|
|
1364
|
+
* @remarks
|
|
1365
|
+
* `issue` carries the **structured** schema failure — at runtime a
|
|
1366
|
+
* `SchemaIssue.Issue` tree, reachable through `_tag` and nested `issues` —
|
|
1367
|
+
* never a stringified rendering (the `ConfigValidationError` precedent from
|
|
1368
|
+
* `@effected/config-file`). It is typed `unknown` because v4 exposes no
|
|
1369
|
+
* `Schema` for `Issue`; narrow it with the `SchemaIssue` module.
|
|
1370
|
+
*
|
|
1371
|
+
* @public
|
|
1372
|
+
*/
|
|
1373
|
+
declare class FrontmatterValidationError extends FrontmatterValidationError_base {
|
|
1374
|
+
get message(): string;
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* The union of everything a composed frontmatter decoder can fail with.
|
|
1378
|
+
*
|
|
1379
|
+
* @public
|
|
1380
|
+
*/
|
|
1381
|
+
type FrontmatterSchemaError = FrontmatterMissingError | FrontmatterFormatMismatchError | FrontmatterDecodeError | FrontmatterValidationError;
|
|
1382
|
+
/**
|
|
1383
|
+
* The union of everything the frontmatter write seam can fail with.
|
|
1384
|
+
*
|
|
1385
|
+
* @remarks
|
|
1386
|
+
* Deliberately without `FrontmatterMissingError`: a document with no
|
|
1387
|
+
* frontmatter capture is the **insert** path of {@link MarkdownFrontmatter.set},
|
|
1388
|
+
* not an error.
|
|
1389
|
+
*
|
|
1390
|
+
* @public
|
|
1391
|
+
*/
|
|
1392
|
+
type FrontmatterWriteError = FrontmatterFormatMismatchError | FrontmatterEncodeError | FrontmatterValidationError;
|
|
1393
|
+
/**
|
|
1394
|
+
* The frontmatter schema composition facade — typed gray-matter parity.
|
|
1395
|
+
*
|
|
1396
|
+
* @remarks
|
|
1397
|
+
* The design doc's indicative spelling was `Frontmatter.schema`, but
|
|
1398
|
+
* `Frontmatter` names the capture node class (the node classes co-locate in
|
|
1399
|
+
* `MarkdownNode.ts` and are named after their mdast types), so the facade
|
|
1400
|
+
* follows the package's Markdown-prefix convention instead.
|
|
1401
|
+
*
|
|
1402
|
+
* @public
|
|
1403
|
+
*/
|
|
1404
|
+
declare class MarkdownFrontmatter {
|
|
1405
|
+
/**
|
|
1406
|
+
* Compose a consumer schema with a {@link FrontmatterCodec} into a typed
|
|
1407
|
+
* decoder over a parsed `MarkdownDocument`.
|
|
1408
|
+
*
|
|
1409
|
+
* @remarks
|
|
1410
|
+
* The decoder reads the document's frontmatter capture (parse with
|
|
1411
|
+
* `frontmatter: true` — the toggle defaults off), decodes its raw value
|
|
1412
|
+
* through the codec, then validates the data against `schema`. Each stage
|
|
1413
|
+
* fails typed: no capture is {@link FrontmatterMissingError}, a
|
|
1414
|
+
* wrong-format codec is {@link FrontmatterFormatMismatchError}, unparseable
|
|
1415
|
+
* content is {@link FrontmatterDecodeError}, and schema-invalid data is
|
|
1416
|
+
* {@link FrontmatterValidationError} carrying the structured issue.
|
|
1417
|
+
*
|
|
1418
|
+
* The seam takes the parsed document, not raw source: parse options
|
|
1419
|
+
* (dialect, the frontmatter toggle) stay at the consumer's parse call and
|
|
1420
|
+
* are never guessed here. Node-level composition remains available through
|
|
1421
|
+
* `MarkdownDocument.frontmatter` plus the codec's own `decode`.
|
|
1422
|
+
*
|
|
1423
|
+
* Schema-producing in spirit: bind the returned decoder to a `const` when
|
|
1424
|
+
* decoding many documents.
|
|
1425
|
+
*
|
|
1426
|
+
* @param schema - The schema the decoded frontmatter data must satisfy.
|
|
1427
|
+
* @param codec - The format codec to decode the raw capture with.
|
|
1428
|
+
* @returns A function from a parsed document to an `Effect` of the typed
|
|
1429
|
+
* frontmatter data.
|
|
1430
|
+
*/
|
|
1431
|
+
static schema<T, E, RD = never, RE = never>(schema: Schema.Codec<T, E, RD, RE>, codec: FrontmatterCodec): (document: MarkdownDocument) => Effect.Effect<T, FrontmatterSchemaError, RD>;
|
|
1432
|
+
/**
|
|
1433
|
+
* Compose a consumer schema with a {@link FrontmatterCodec} into a typed
|
|
1434
|
+
* frontmatter **writer** over a parsed `MarkdownDocument` — the write
|
|
1435
|
+
* mirror of {@link MarkdownFrontmatter.schema}.
|
|
1436
|
+
*
|
|
1437
|
+
* @remarks
|
|
1438
|
+
* The writer schema-**encodes** the typed data, serializes it through the
|
|
1439
|
+
* codec and returns the offset-splice edits that put the block in place —
|
|
1440
|
+
* always exactly one:
|
|
1441
|
+
*
|
|
1442
|
+
* - A document **with** a frontmatter capture of the codec's format gets a
|
|
1443
|
+
* replacement of the entire block, both fence lines included; everything
|
|
1444
|
+
* outside the block survives byte-identical. A capture of a *different*
|
|
1445
|
+
* format fails with {@link FrontmatterFormatMismatchError} — the fences
|
|
1446
|
+
* are never switched.
|
|
1447
|
+
* - A document with **no** capture gets one insert at offset 0: the fenced
|
|
1448
|
+
* block plus a blank line separating it from the existing content. Parse
|
|
1449
|
+
* with `frontmatter: true` (the toggle defaults off) — the same
|
|
1450
|
+
* precondition `schema` has — so absence means genuinely-no-frontmatter
|
|
1451
|
+
* and the insert cannot double a block the parse ignored.
|
|
1452
|
+
*
|
|
1453
|
+
* Each stage fails typed: schema-invalid data is
|
|
1454
|
+
* {@link FrontmatterValidationError} carrying the structured issue, and a
|
|
1455
|
+
* value the format cannot serialize is {@link FrontmatterEncodeError}
|
|
1456
|
+
* carrying the format package's failure structurally.
|
|
1457
|
+
*
|
|
1458
|
+
* The block is re-serialized **whole** from the encoded data — gray-matter
|
|
1459
|
+
* parity, not surgical editing — so anything the format's data model does
|
|
1460
|
+
* not carry is not preserved: comments inside a yaml frontmatter block do
|
|
1461
|
+
* **not** survive `set`. A per-key surgical mode over the format packages'
|
|
1462
|
+
* edit layers is a documented future refinement, not current scope.
|
|
1463
|
+
*
|
|
1464
|
+
* Schema-producing in spirit: bind the returned writer to a `const` when
|
|
1465
|
+
* writing many documents.
|
|
1466
|
+
*
|
|
1467
|
+
* @param schema - The schema the frontmatter data is encoded through.
|
|
1468
|
+
* @param codec - The format codec to serialize the encoded data with.
|
|
1469
|
+
* @returns A function from a parsed document and the typed data to an
|
|
1470
|
+
* `Effect` of the edits that install the block.
|
|
1471
|
+
*/
|
|
1472
|
+
static set<T, E, RD = never, RE = never>(schema: Schema.Codec<T, E, RD, RE>, codec: FrontmatterCodec): (document: MarkdownDocument, data: T) => Effect.Effect<ReadonlyArray<MarkdownEdit>, FrontmatterWriteError, RE>;
|
|
1473
|
+
/**
|
|
1474
|
+
* Like {@link MarkdownFrontmatter.set}, but applies the edits to the
|
|
1475
|
+
* document's source and returns the updated markdown text — the
|
|
1476
|
+
* `modifyToString` parallel.
|
|
1477
|
+
*
|
|
1478
|
+
* @remarks
|
|
1479
|
+
* Everything `set` documents holds verbatim: the whole-block
|
|
1480
|
+
* re-serialization, the format-mismatch posture, the `frontmatter: true`
|
|
1481
|
+
* precondition and the typed failures.
|
|
1482
|
+
*
|
|
1483
|
+
* @param schema - The schema the frontmatter data is encoded through.
|
|
1484
|
+
* @param codec - The format codec to serialize the encoded data with.
|
|
1485
|
+
* @returns A function from a parsed document and the typed data to an
|
|
1486
|
+
* `Effect` of the updated source text.
|
|
1487
|
+
*/
|
|
1488
|
+
static setToString<T, E, RD = never, RE = never>(schema: Schema.Codec<T, E, RD, RE>, codec: FrontmatterCodec): (document: MarkdownDocument, data: T) => Effect.Effect<string, FrontmatterWriteError, RE>;
|
|
1489
|
+
}
|
|
1490
|
+
//#endregion
|
|
1491
|
+
//#region src/FrontmatterResolver.d.ts
|
|
1492
|
+
declare const SchemaDeclarationByUrl_base: Schema.Class<SchemaDeclarationByUrl, Schema.TaggedStruct<"ByUrl", {
|
|
1493
|
+
/** The URL as written in the declaration. */
|
|
1494
|
+
readonly url: Schema.String;
|
|
1495
|
+
}>, {}>;
|
|
1496
|
+
/**
|
|
1497
|
+
* A `$schema` declaration referencing a schema by URL — any string containing
|
|
1498
|
+
* `://`.
|
|
1499
|
+
*
|
|
1500
|
+
* @remarks
|
|
1501
|
+
* Carried as data, never resolved in-package: the pure tier does no IO. An
|
|
1502
|
+
* external resolver implementing {@link FrontmatterSchemaResolver} may fetch
|
|
1503
|
+
* and interpret it.
|
|
1504
|
+
*
|
|
1505
|
+
* @public
|
|
1506
|
+
*/
|
|
1507
|
+
declare class SchemaDeclarationByUrl extends SchemaDeclarationByUrl_base {}
|
|
1508
|
+
declare const SchemaDeclarationByPath_base: Schema.Class<SchemaDeclarationByPath, Schema.TaggedStruct<"ByPath", {
|
|
1509
|
+
/** The path as written in the declaration. */
|
|
1510
|
+
readonly path: Schema.String;
|
|
1511
|
+
}>, {}>;
|
|
1512
|
+
/**
|
|
1513
|
+
* A `$schema` declaration referencing a schema by path — any string starting
|
|
1514
|
+
* `./`, `../` or `/` (a bundle- or file-relative reference).
|
|
1515
|
+
*
|
|
1516
|
+
* @remarks
|
|
1517
|
+
* Carried as data, never resolved in-package: the pure tier does no IO.
|
|
1518
|
+
*
|
|
1519
|
+
* @public
|
|
1520
|
+
*/
|
|
1521
|
+
declare class SchemaDeclarationByPath extends SchemaDeclarationByPath_base {}
|
|
1522
|
+
declare const SchemaDeclarationInline_base: Schema.Class<SchemaDeclarationInline, Schema.TaggedStruct<"Inline", {
|
|
1523
|
+
/** The inline schema document, exactly as decoded from the frontmatter. */
|
|
1524
|
+
readonly document: Schema.Unknown;
|
|
1525
|
+
}>, {}>;
|
|
1526
|
+
/**
|
|
1527
|
+
* A `$schema` declaration carrying an inline JSON-Schema-like document — the
|
|
1528
|
+
* declaration value is itself a mapping.
|
|
1529
|
+
*
|
|
1530
|
+
* @remarks
|
|
1531
|
+
* Carried as data: the kit deliberately ships no JSON Schema engine
|
|
1532
|
+
* (`@effected/json-schema` is off the roadmap), so an inline document is
|
|
1533
|
+
* interpretable only through an external resolver plugged into the
|
|
1534
|
+
* {@link FrontmatterSchemaResolver} seam.
|
|
1535
|
+
*
|
|
1536
|
+
* @public
|
|
1537
|
+
*/
|
|
1538
|
+
declare class SchemaDeclarationInline extends SchemaDeclarationInline_base {}
|
|
1539
|
+
declare const SchemaDeclarationByName_base: Schema.Class<SchemaDeclarationByName, Schema.TaggedStruct<"ByName", {
|
|
1540
|
+
/** The name as written, scope included. */
|
|
1541
|
+
readonly name: Schema.String;
|
|
1542
|
+
/** The version as written, when the declaration carries one. */
|
|
1543
|
+
readonly version: Schema.optionalKey<Schema.String>;
|
|
1544
|
+
}>, {}>;
|
|
1545
|
+
/**
|
|
1546
|
+
* A `$schema` declaration referencing a registered schema by name — any other
|
|
1547
|
+
* string, with the committed `name[@version]` grammar.
|
|
1548
|
+
*
|
|
1549
|
+
* @remarks
|
|
1550
|
+
* The string splits at the **last** `@`, so a leading npm-style scope
|
|
1551
|
+
* survives: `@savvy/skill@2.1.0` is name `@savvy/skill`, version `2.1.0`.
|
|
1552
|
+
* The version grammar is `X[.Y[.Z]]` — one to three dot-separated
|
|
1553
|
+
* non-negative integers; no prerelease, no build metadata, no npm range
|
|
1554
|
+
* operators. The recorded cost: `@` in a name is reserved forever as the
|
|
1555
|
+
* version separator, except the leading scope `@`.
|
|
1556
|
+
*
|
|
1557
|
+
* @public
|
|
1558
|
+
*/
|
|
1559
|
+
declare class SchemaDeclarationByName extends SchemaDeclarationByName_base {}
|
|
1560
|
+
/**
|
|
1561
|
+
* The classified `$schema` declaration union — the full grammar contract for
|
|
1562
|
+
* how a frontmatter block may self-describe its schema.
|
|
1563
|
+
*
|
|
1564
|
+
* @public
|
|
1565
|
+
*/
|
|
1566
|
+
declare const SchemaDeclaration: Schema.Union<readonly [typeof SchemaDeclarationByUrl, typeof SchemaDeclarationByPath, typeof SchemaDeclarationInline, typeof SchemaDeclarationByName]>;
|
|
1567
|
+
/**
|
|
1568
|
+
* The union of all classified `$schema` declaration shapes.
|
|
1569
|
+
*
|
|
1570
|
+
* @public
|
|
1571
|
+
*/
|
|
1572
|
+
type SchemaDeclaration = SchemaDeclarationByUrl | SchemaDeclarationByPath | SchemaDeclarationInline | SchemaDeclarationByName;
|
|
1573
|
+
declare const SchemaDeclarationInvalidError_base: Schema.Class<SchemaDeclarationInvalidError, Schema.TaggedStruct<"SchemaDeclarationInvalidError", {
|
|
1574
|
+
/** Why the value failed to classify. */
|
|
1575
|
+
readonly reason: Schema.String;
|
|
1576
|
+
/** The offending value, preserved structurally. */
|
|
1577
|
+
readonly value: Schema.Defect;
|
|
1578
|
+
}>, import("effect/Cause").YieldableError>;
|
|
1579
|
+
/**
|
|
1580
|
+
* Indicates that a `$schema` value does not classify: not a string or a
|
|
1581
|
+
* mapping, an empty string, or a name whose version segment falls outside the
|
|
1582
|
+
* committed `X[.Y[.Z]]` grammar.
|
|
1583
|
+
*
|
|
1584
|
+
* @public
|
|
1585
|
+
*/
|
|
1586
|
+
declare class SchemaDeclarationInvalidError extends SchemaDeclarationInvalidError_base {
|
|
1587
|
+
get message(): string;
|
|
1588
|
+
}
|
|
1589
|
+
declare const SchemaDeclarationMissingError_base: Schema.Class<SchemaDeclarationMissingError, Schema.TaggedStruct<"SchemaDeclarationMissingError", {}>, import("effect/Cause").YieldableError>;
|
|
1590
|
+
/**
|
|
1591
|
+
* Indicates that frontmatter data carries no `$schema` declaration where one
|
|
1592
|
+
* is required — the `requireDeclaration` strictness knob, or a registry
|
|
1593
|
+
* resolver that has nothing to dispatch on.
|
|
1594
|
+
*
|
|
1595
|
+
* @public
|
|
1596
|
+
*/
|
|
1597
|
+
declare class SchemaDeclarationMissingError extends SchemaDeclarationMissingError_base {
|
|
1598
|
+
get message(): string;
|
|
1599
|
+
}
|
|
1600
|
+
declare const SchemaNameUnknownError_base: Schema.Class<SchemaNameUnknownError, Schema.TaggedStruct<"SchemaNameUnknownError", {
|
|
1601
|
+
/** The declaration that failed to resolve, when one exists. */
|
|
1602
|
+
readonly declaration: Schema.optionalKey<Schema.Union<readonly [typeof SchemaDeclarationByUrl, typeof SchemaDeclarationByPath, typeof SchemaDeclarationInline, typeof SchemaDeclarationByName]>>;
|
|
1603
|
+
}>, import("effect/Cause").YieldableError>;
|
|
1604
|
+
/**
|
|
1605
|
+
* Indicates that a declaration named a schema the resolver does not know —
|
|
1606
|
+
* an unregistered name, or a URL/path/inline declaration handed to the
|
|
1607
|
+
* name-keyed registry resolver.
|
|
1608
|
+
*
|
|
1609
|
+
* @public
|
|
1610
|
+
*/
|
|
1611
|
+
declare class SchemaNameUnknownError extends SchemaNameUnknownError_base {
|
|
1612
|
+
get message(): string;
|
|
1613
|
+
}
|
|
1614
|
+
declare const SchemaVersionUnresolvableError_base: Schema.Class<SchemaVersionUnresolvableError, Schema.TaggedStruct<"SchemaVersionUnresolvableError", {
|
|
1615
|
+
/** The registered name whose version could not be satisfied. */
|
|
1616
|
+
readonly name: Schema.String;
|
|
1617
|
+
/** The requested version, when the declaration carried one. */
|
|
1618
|
+
readonly version: Schema.optionalKey<Schema.String>;
|
|
1619
|
+
}>, import("effect/Cause").YieldableError>;
|
|
1620
|
+
/**
|
|
1621
|
+
* Indicates that a declaration's name is registered but its version segments
|
|
1622
|
+
* match no registration exactly — distinct from {@link SchemaNameUnknownError}
|
|
1623
|
+
* by design, so a legal-but-unsatisfied partial version (`skill@2` against a
|
|
1624
|
+
* `skill@2.1.0` registration) is diagnosable as a version problem, not an
|
|
1625
|
+
* unknown schema.
|
|
1626
|
+
*
|
|
1627
|
+
* @public
|
|
1628
|
+
*/
|
|
1629
|
+
declare class SchemaVersionUnresolvableError extends SchemaVersionUnresolvableError_base {
|
|
1630
|
+
get message(): string;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* The union of everything declaration resolution can fail with.
|
|
1634
|
+
*
|
|
1635
|
+
* @public
|
|
1636
|
+
*/
|
|
1637
|
+
type FrontmatterResolveError = SchemaDeclarationMissingError | SchemaNameUnknownError | SchemaVersionUnresolvableError;
|
|
1638
|
+
/**
|
|
1639
|
+
* The resolver seam: given a classified declaration **and** the whole decoded
|
|
1640
|
+
* frontmatter data, produce the schema to validate with, or fail typed.
|
|
1641
|
+
*
|
|
1642
|
+
* @remarks
|
|
1643
|
+
* The whole-data second argument is the dispatch seam: because a resolver
|
|
1644
|
+
* sees everything the frontmatter decoded to, it need not key on `$schema`
|
|
1645
|
+
* at all — an OKF resolver dispatches on OKF's `type` field with zero OKF
|
|
1646
|
+
* code in this package. `E` widens the error channel for custom resolvers;
|
|
1647
|
+
* the built-in registry resolver keeps it `never`.
|
|
1648
|
+
*
|
|
1649
|
+
* @public
|
|
1650
|
+
*/
|
|
1651
|
+
interface FrontmatterSchemaResolver<E = never> {
|
|
1652
|
+
/** Resolve a declaration (possibly absent) against decoded frontmatter data. */
|
|
1653
|
+
readonly resolve: (declaration: SchemaDeclaration | undefined, data: unknown) => Effect.Effect<Schema.Top, FrontmatterResolveError | E>;
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* The `$schema` declaration classifier and the package's one built-in
|
|
1657
|
+
* resolver implementation.
|
|
1658
|
+
*
|
|
1659
|
+
* @public
|
|
1660
|
+
*/
|
|
1661
|
+
declare class SchemaResolver {
|
|
1662
|
+
/**
|
|
1663
|
+
* Classify a raw `$schema` value into the declaration union.
|
|
1664
|
+
*
|
|
1665
|
+
* @remarks
|
|
1666
|
+
* Total over its legal domain and typed on junk: a string containing
|
|
1667
|
+
* `://` is {@link SchemaDeclarationByUrl}; a string starting `./`, `../`
|
|
1668
|
+
* or `/` is {@link SchemaDeclarationByPath}; a mapping is
|
|
1669
|
+
* {@link SchemaDeclarationInline}; any other non-empty string is
|
|
1670
|
+
* {@link SchemaDeclarationByName} under the `name[@version]` grammar.
|
|
1671
|
+
* Everything else — and a name whose version falls outside `X[.Y[.Z]]` —
|
|
1672
|
+
* fails with {@link SchemaDeclarationInvalidError}.
|
|
1673
|
+
*
|
|
1674
|
+
* @param value - The raw `$schema` value from decoded frontmatter data.
|
|
1675
|
+
* @returns The classified declaration, or the typed classification error.
|
|
1676
|
+
*/
|
|
1677
|
+
static classify(value: unknown): Result.Result<SchemaDeclaration, SchemaDeclarationInvalidError>;
|
|
1678
|
+
/**
|
|
1679
|
+
* Extract and classify the `$schema` declaration from decoded frontmatter
|
|
1680
|
+
* data.
|
|
1681
|
+
*
|
|
1682
|
+
* @remarks
|
|
1683
|
+
* Non-mapping data and a mapping without a `$schema` key both carry no
|
|
1684
|
+
* declaration: the result succeeds with `undefined` by default, or fails
|
|
1685
|
+
* with {@link SchemaDeclarationMissingError} under `requireDeclaration` —
|
|
1686
|
+
* the design's strictness knob, applied at extraction where the
|
|
1687
|
+
* present-or-absent branch actually lives.
|
|
1688
|
+
*
|
|
1689
|
+
* @param data - The decoded frontmatter data.
|
|
1690
|
+
* @param options - `requireDeclaration` makes a missing `$schema` a typed
|
|
1691
|
+
* error.
|
|
1692
|
+
* @returns The classified declaration, `undefined` when absent and
|
|
1693
|
+
* tolerated, or the typed error.
|
|
1694
|
+
*/
|
|
1695
|
+
static declarationOf(data: unknown, options?: {
|
|
1696
|
+
readonly requireDeclaration?: boolean;
|
|
1697
|
+
}): Result.Result<SchemaDeclaration | undefined, SchemaDeclarationInvalidError | SchemaDeclarationMissingError>;
|
|
1698
|
+
/**
|
|
1699
|
+
* The package's one built-in resolver: a name-keyed registry with day-one
|
|
1700
|
+
* exact version-segment resolution.
|
|
1701
|
+
*
|
|
1702
|
+
* @remarks
|
|
1703
|
+
* Registration keys use the same `name[@version]` grammar as declarations
|
|
1704
|
+
* — carrying a concrete version or none — and are validated eagerly: a key
|
|
1705
|
+
* outside the grammar, or two keys whose version segments collide
|
|
1706
|
+
* numerically, throws at construction (programmer error, not input).
|
|
1707
|
+
*
|
|
1708
|
+
* Resolution is exact: a declaration resolves only against an identically
|
|
1709
|
+
* written registration (version segments compared numerically), a
|
|
1710
|
+
* versionless declaration only against a versionless registration, and a
|
|
1711
|
+
* legal-but-unsatisfied version fails with the dedicated
|
|
1712
|
+
* {@link SchemaVersionUnresolvableError}, distinct from
|
|
1713
|
+
* {@link SchemaNameUnknownError}. URL, path and inline declarations are
|
|
1714
|
+
* never resolvable here — those belong to external resolvers plugged into
|
|
1715
|
+
* the same seam. A registry cannot dispatch without a declaration, so an
|
|
1716
|
+
* absent one fails with {@link SchemaDeclarationMissingError}.
|
|
1717
|
+
*
|
|
1718
|
+
* @param registrations - Schemas keyed by `name[@version]`.
|
|
1719
|
+
* @returns The registry-backed resolver.
|
|
1720
|
+
*/
|
|
1721
|
+
static fromRegistry(registrations: Readonly<Record<string, Schema.Top>>): FrontmatterSchemaResolver;
|
|
1722
|
+
}
|
|
1723
|
+
//#endregion
|
|
1724
|
+
//#region src/JsonFrontmatter.d.ts
|
|
1725
|
+
/**
|
|
1726
|
+
* The json frontmatter codec, over `@effected/jsonc`.
|
|
1727
|
+
*
|
|
1728
|
+
* @remarks
|
|
1729
|
+
* Decodes a `---json`-fenced capture's raw value with `Jsonc.parse`, so the
|
|
1730
|
+
* jsonc engine's nesting depth cap fails through the typed channel: a hostile
|
|
1731
|
+
* frontmatter block surfaces as a {@link FrontmatterDecodeError} carrying the
|
|
1732
|
+
* `JsoncParseError` structurally, never a defect. JSONC being a JSON
|
|
1733
|
+
* superset, comments and trailing commas in a json capture decode rather than
|
|
1734
|
+
* fail — deliberate leniency, matching the kit's one JSON-family engine. An
|
|
1735
|
+
* empty capture fails typed: unlike yaml and toml, JSON has no
|
|
1736
|
+
* empty-document value.
|
|
1737
|
+
*
|
|
1738
|
+
* Encodes with `Jsonc.stringify` — plain 2-space JSON emission, never
|
|
1739
|
+
* comments; a circular reference, a `bigint` or a top-level unrepresentable
|
|
1740
|
+
* value fails as a {@link FrontmatterEncodeError} carrying the
|
|
1741
|
+
* `JsoncStringifyError` structurally. An empty object encodes to `{}`.
|
|
1742
|
+
*
|
|
1743
|
+
* `@effected/jsonc` is an optional peer — importing this module is what
|
|
1744
|
+
* requires it; a consumer who never touches json frontmatter never loads the
|
|
1745
|
+
* jsonc engine.
|
|
1746
|
+
*
|
|
1747
|
+
* @public
|
|
1748
|
+
*/
|
|
1749
|
+
declare const JsonFrontmatter: FrontmatterCodec;
|
|
1750
|
+
//#endregion
|
|
1751
|
+
//#region src/MarkdownFormat.d.ts
|
|
1752
|
+
/**
|
|
1753
|
+
* A range accepted at the `format`/`formatToString` call sites: either a
|
|
1754
|
+
* {@link MarkdownRange} instance or a plain `{ offset, length }` literal (the
|
|
1755
|
+
* two are structurally interchangeable — only `offset`/`length` are read).
|
|
1756
|
+
*
|
|
1757
|
+
* @public
|
|
1758
|
+
*/
|
|
1759
|
+
type MarkdownRangeLike = MarkdownRange | {
|
|
1760
|
+
readonly offset: number;
|
|
1761
|
+
readonly length: number;
|
|
1762
|
+
};
|
|
1763
|
+
declare const MarkdownFormattingOptions_base: Schema.Class<MarkdownFormattingOptions, Schema.Struct<{
|
|
1764
|
+
readonly dialect: Schema.optionalKey<Schema.Literals<readonly ["commonmark", "gfm"]>>;
|
|
1765
|
+
readonly frontmatter: Schema.optionalKey<Schema.Boolean>;
|
|
1766
|
+
readonly headingStyle: Schema.optionalKey<Schema.Literals<readonly ["atx", "setext"]>>;
|
|
1767
|
+
readonly bulletChar: Schema.optionalKey<Schema.Literals<readonly ["-", "*", "+"]>>;
|
|
1768
|
+
readonly emphasisChar: Schema.optionalKey<Schema.Literals<readonly ["*", "_"]>>;
|
|
1769
|
+
readonly fenceChar: Schema.optionalKey<Schema.Literals<readonly ["`", "~"]>>;
|
|
1770
|
+
readonly thematicBreakChar: Schema.optionalKey<Schema.Literals<readonly ["-", "_", "*"]>>;
|
|
1771
|
+
}>, {}>;
|
|
1772
|
+
/**
|
|
1773
|
+
* Options controlling formatting: which concrete-syntax markers to normalize,
|
|
1774
|
+
* plus the parse knobs (`dialect`, `frontmatter`) the formatter parses the
|
|
1775
|
+
* source with (same defaults as `Markdown.parse`). Every marker option is
|
|
1776
|
+
* optional and independent; an absent option normalizes nothing.
|
|
1777
|
+
*
|
|
1778
|
+
* Day-one scope is marker normalization only — heading style, bullet
|
|
1779
|
+
* character, emphasis/strong marker, fence character, thematic-break
|
|
1780
|
+
* character. Content is never rewritten, rewrapped or reflowed.
|
|
1781
|
+
*
|
|
1782
|
+
* @public
|
|
1783
|
+
*/
|
|
1784
|
+
declare class MarkdownFormattingOptions extends MarkdownFormattingOptions_base {}
|
|
1785
|
+
/**
|
|
1786
|
+
* Error codes `MarkdownFormat.modify` can fail with.
|
|
1787
|
+
*
|
|
1788
|
+
* @public
|
|
1789
|
+
*/
|
|
1790
|
+
declare const MarkdownModificationErrorCode: Schema.Literals<readonly ["NodeNotInDocument", "UnsupportedTarget", "FragmentCategoryMismatch", "FragmentUnrenderable"]>;
|
|
1791
|
+
/**
|
|
1792
|
+
* The union of all modification-error code string literals.
|
|
1793
|
+
*
|
|
1794
|
+
* @public
|
|
1795
|
+
*/
|
|
1796
|
+
type MarkdownModificationErrorCode = typeof MarkdownModificationErrorCode.Type;
|
|
1797
|
+
declare const MarkdownModificationError_base: Schema.Class<MarkdownModificationError, Schema.TaggedStruct<"MarkdownModificationError", {
|
|
1798
|
+
readonly code: Schema.Literals<readonly ["NodeNotInDocument", "UnsupportedTarget", "FragmentCategoryMismatch", "FragmentUnrenderable"]>;
|
|
1799
|
+
readonly detail: Schema.String;
|
|
1800
|
+
readonly offset: Schema.Number;
|
|
1801
|
+
readonly length: Schema.Number;
|
|
1802
|
+
}>, import("effect/Cause").YieldableError>;
|
|
1803
|
+
/**
|
|
1804
|
+
* Raised when `MarkdownFormat.modify` cannot perform the requested
|
|
1805
|
+
* replacement: the target node is not in the document (`NodeNotInDocument`),
|
|
1806
|
+
* the target kind or splice context is outside the day-one scope
|
|
1807
|
+
* (`UnsupportedTarget`), the fragment's content category does not fit the
|
|
1808
|
+
* target's slot (`FragmentCategoryMismatch`), or the fragment trips the
|
|
1809
|
+
* stringifier's hardening guard (`FragmentUnrenderable`). Carries the typed
|
|
1810
|
+
* `code` plus the target's `offset`/`length` where known — never a collapsed
|
|
1811
|
+
* reason string alone.
|
|
1812
|
+
*
|
|
1813
|
+
* @public
|
|
1814
|
+
*/
|
|
1815
|
+
declare class MarkdownModificationError extends MarkdownModificationError_base {
|
|
1816
|
+
get message(): string;
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* Formatting and modification statics. Not instantiable.
|
|
1820
|
+
*
|
|
1821
|
+
* @remarks
|
|
1822
|
+
* `format`/`formatToString` are pure and total: input that trips a parse
|
|
1823
|
+
* hardening guard yields no edits rather than corrupting the document, and
|
|
1824
|
+
* every emitted edit is guarded against the re-parse hazards listed in the
|
|
1825
|
+
* module documentation — a hazardous conversion is skipped, never attempted.
|
|
1826
|
+
* `modify`/`modifyToString` carry a real error channel
|
|
1827
|
+
* ({@link MarkdownModificationError}) and render every replacement through
|
|
1828
|
+
* the canonical stringifier, so a modified document re-parses cleanly by
|
|
1829
|
+
* construction.
|
|
1830
|
+
*
|
|
1831
|
+
* @public
|
|
1832
|
+
*/
|
|
1833
|
+
declare class MarkdownFormat {
|
|
1834
|
+
private constructor();
|
|
1835
|
+
/**
|
|
1836
|
+
* Compute marker-normalization edits per the requested
|
|
1837
|
+
* {@link MarkdownFormattingOptions}: heading style, bullet character,
|
|
1838
|
+
* emphasis/strong marker, fence character and thematic-break character,
|
|
1839
|
+
* each only where the node's concrete syntax differs from the target and
|
|
1840
|
+
* the rewrite is provably safe. Content is never touched. `range`
|
|
1841
|
+
* restricts edits to the nodes intersecting it (the owning-node
|
|
1842
|
+
* intersection posture, matching toml). Non-mutating — apply with
|
|
1843
|
+
* `MarkdownEdit.applyAll` (or use {@link MarkdownFormat.formatToString}).
|
|
1844
|
+
*/
|
|
1845
|
+
static format(text: string, range?: MarkdownRangeLike, options?: MarkdownFormattingOptions): ReadonlyArray<MarkdownEdit>;
|
|
1846
|
+
/**
|
|
1847
|
+
* Format `text` and apply the resulting edits in one step
|
|
1848
|
+
* (`MarkdownEdit.applyAll ∘ format`). Pure and total.
|
|
1849
|
+
*/
|
|
1850
|
+
static formatToString(text: string, range?: MarkdownRangeLike, options?: MarkdownFormattingOptions): string;
|
|
1851
|
+
/**
|
|
1852
|
+
* Compute the edit that replaces `target` — a node from `document`'s own
|
|
1853
|
+
* tree, matched by identity — with `replacement`: a plain string (treated
|
|
1854
|
+
* as literal text and escaped; block-wrapped when the target is a flow
|
|
1855
|
+
* node) or a node fragment whose content category must fit the target's
|
|
1856
|
+
* slot (flow for flow targets, phrasing for phrasing targets and table
|
|
1857
|
+
* cells). Every replacement renders through the canonical stringifier, so
|
|
1858
|
+
* the modified document re-parses cleanly by construction. Day-one scope:
|
|
1859
|
+
* list items, table rows, frontmatter and the root refuse with
|
|
1860
|
+
* `UnsupportedTarget`, as does a multi-line replacement whose target sits
|
|
1861
|
+
* inside a container (a blockquote, list, table or heading) whose
|
|
1862
|
+
* continuation lines the splice cannot prefix.
|
|
1863
|
+
*/
|
|
1864
|
+
static readonly modify: (document: MarkdownDocument, target: MarkdownNode, replacement: string | MarkdownNode) => Effect.Effect<readonly MarkdownEdit[], MarkdownModificationError, never>;
|
|
1865
|
+
/**
|
|
1866
|
+
* Modify `document` and apply the resulting edit in one step
|
|
1867
|
+
* (`MarkdownEdit.applyAll ∘ modify`).
|
|
1868
|
+
*/
|
|
1869
|
+
static readonly modifyToString: (document: MarkdownDocument, target: MarkdownNode, replacement: string | MarkdownNode) => Effect.Effect<string, MarkdownModificationError, never>;
|
|
1870
|
+
}
|
|
1871
|
+
//#endregion
|
|
1872
|
+
//#region src/MarkdownVisitor.d.ts
|
|
1873
|
+
/**
|
|
1874
|
+
* The discriminated union of markdown visitor events, in document pre-order.
|
|
1875
|
+
* `Enter` fires when the walk reaches a node, `Exit` when it leaves — for a
|
|
1876
|
+
* leaf the two fire back to back. Every variant carries `path` (child
|
|
1877
|
+
* indexes from the root; the root's own path is empty) and `depth`
|
|
1878
|
+
* (zero-based; the root is 0). `Error` is terminal: it carries the
|
|
1879
|
+
* depth-guard diagnostic for a decoded foreign tree nested past
|
|
1880
|
+
* `MAX_NESTING_DEPTH` and nothing follows it.
|
|
1881
|
+
*
|
|
1882
|
+
* @public
|
|
1883
|
+
*/
|
|
1884
|
+
type MarkdownVisitorEvent = Data.TaggedEnum<{
|
|
1885
|
+
Enter: {
|
|
1886
|
+
readonly node: MarkdownNode;
|
|
1887
|
+
readonly path: MarkdownPath;
|
|
1888
|
+
readonly depth: number;
|
|
1889
|
+
};
|
|
1890
|
+
Exit: {
|
|
1891
|
+
readonly node: MarkdownNode;
|
|
1892
|
+
readonly path: MarkdownPath;
|
|
1893
|
+
readonly depth: number;
|
|
1894
|
+
};
|
|
1895
|
+
Error: {
|
|
1896
|
+
readonly diagnostic: MarkdownDiagnostic;
|
|
1897
|
+
readonly path: MarkdownPath;
|
|
1898
|
+
readonly depth: number;
|
|
1899
|
+
};
|
|
1900
|
+
}>;
|
|
1901
|
+
/**
|
|
1902
|
+
* Constructors and matchers for the `MarkdownVisitorEvent` union (e.g.
|
|
1903
|
+
* `MarkdownVisitorEvent.Enter({ node, path, depth })`,
|
|
1904
|
+
* `MarkdownVisitorEvent.$is("Exit")`).
|
|
1905
|
+
*
|
|
1906
|
+
* @public
|
|
1907
|
+
*/
|
|
1908
|
+
declare const MarkdownVisitorEvent: {
|
|
1909
|
+
readonly $is: <Tag extends "Enter" | "Error" | "Exit">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
1910
|
+
readonly _tag: "Enter";
|
|
1911
|
+
readonly node: MarkdownNode;
|
|
1912
|
+
readonly path: MarkdownPath;
|
|
1913
|
+
readonly depth: number;
|
|
1914
|
+
}, {
|
|
1915
|
+
readonly _tag: Tag;
|
|
1916
|
+
}> | Extract<{
|
|
1917
|
+
readonly _tag: "Error";
|
|
1918
|
+
readonly diagnostic: MarkdownDiagnostic;
|
|
1919
|
+
readonly path: MarkdownPath;
|
|
1920
|
+
readonly depth: number;
|
|
1921
|
+
}, {
|
|
1922
|
+
readonly _tag: Tag;
|
|
1923
|
+
}> | Extract<{
|
|
1924
|
+
readonly _tag: "Exit";
|
|
1925
|
+
readonly node: MarkdownNode;
|
|
1926
|
+
readonly path: MarkdownPath;
|
|
1927
|
+
readonly depth: number;
|
|
1928
|
+
}, {
|
|
1929
|
+
readonly _tag: Tag;
|
|
1930
|
+
}>;
|
|
1931
|
+
readonly $match: {
|
|
1932
|
+
<Cases extends {
|
|
1933
|
+
readonly Enter: (args: {
|
|
1934
|
+
readonly _tag: "Enter";
|
|
1935
|
+
readonly node: MarkdownNode;
|
|
1936
|
+
readonly path: MarkdownPath;
|
|
1937
|
+
readonly depth: number;
|
|
1938
|
+
}) => any;
|
|
1939
|
+
readonly Error: (args: {
|
|
1940
|
+
readonly _tag: "Error";
|
|
1941
|
+
readonly diagnostic: MarkdownDiagnostic;
|
|
1942
|
+
readonly path: MarkdownPath;
|
|
1943
|
+
readonly depth: number;
|
|
1944
|
+
}) => any;
|
|
1945
|
+
readonly Exit: (args: {
|
|
1946
|
+
readonly _tag: "Exit";
|
|
1947
|
+
readonly node: MarkdownNode;
|
|
1948
|
+
readonly path: MarkdownPath;
|
|
1949
|
+
readonly depth: number;
|
|
1950
|
+
}) => any;
|
|
1951
|
+
}>(cases: Cases): (value: {
|
|
1952
|
+
readonly _tag: "Enter";
|
|
1953
|
+
readonly node: MarkdownNode;
|
|
1954
|
+
readonly path: MarkdownPath;
|
|
1955
|
+
readonly depth: number;
|
|
1956
|
+
} | {
|
|
1957
|
+
readonly _tag: "Error";
|
|
1958
|
+
readonly diagnostic: MarkdownDiagnostic;
|
|
1959
|
+
readonly path: MarkdownPath;
|
|
1960
|
+
readonly depth: number;
|
|
1961
|
+
} | {
|
|
1962
|
+
readonly _tag: "Exit";
|
|
1963
|
+
readonly node: MarkdownNode;
|
|
1964
|
+
readonly path: MarkdownPath;
|
|
1965
|
+
readonly depth: number;
|
|
1966
|
+
}) => import("effect/Unify").Unify<ReturnType<Cases["Enter" | "Error" | "Exit"]>>;
|
|
1967
|
+
<Cases extends {
|
|
1968
|
+
readonly Enter: (args: {
|
|
1969
|
+
readonly _tag: "Enter";
|
|
1970
|
+
readonly node: MarkdownNode;
|
|
1971
|
+
readonly path: MarkdownPath;
|
|
1972
|
+
readonly depth: number;
|
|
1973
|
+
}) => any;
|
|
1974
|
+
readonly Error: (args: {
|
|
1975
|
+
readonly _tag: "Error";
|
|
1976
|
+
readonly diagnostic: MarkdownDiagnostic;
|
|
1977
|
+
readonly path: MarkdownPath;
|
|
1978
|
+
readonly depth: number;
|
|
1979
|
+
}) => any;
|
|
1980
|
+
readonly Exit: (args: {
|
|
1981
|
+
readonly _tag: "Exit";
|
|
1982
|
+
readonly node: MarkdownNode;
|
|
1983
|
+
readonly path: MarkdownPath;
|
|
1984
|
+
readonly depth: number;
|
|
1985
|
+
}) => any;
|
|
1986
|
+
}>(value: {
|
|
1987
|
+
readonly _tag: "Enter";
|
|
1988
|
+
readonly node: MarkdownNode;
|
|
1989
|
+
readonly path: MarkdownPath;
|
|
1990
|
+
readonly depth: number;
|
|
1991
|
+
} | {
|
|
1992
|
+
readonly _tag: "Error";
|
|
1993
|
+
readonly diagnostic: MarkdownDiagnostic;
|
|
1994
|
+
readonly path: MarkdownPath;
|
|
1995
|
+
readonly depth: number;
|
|
1996
|
+
} | {
|
|
1997
|
+
readonly _tag: "Exit";
|
|
1998
|
+
readonly node: MarkdownNode;
|
|
1999
|
+
readonly path: MarkdownPath;
|
|
2000
|
+
readonly depth: number;
|
|
2001
|
+
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Enter" | "Error" | "Exit"]>>;
|
|
2002
|
+
};
|
|
2003
|
+
readonly Enter: Data.TaggedEnum.ConstructorFrom<{
|
|
2004
|
+
readonly _tag: "Enter";
|
|
2005
|
+
readonly node: MarkdownNode;
|
|
2006
|
+
readonly path: MarkdownPath;
|
|
2007
|
+
readonly depth: number;
|
|
2008
|
+
}, "_tag">;
|
|
2009
|
+
readonly Error: Data.TaggedEnum.ConstructorFrom<{
|
|
2010
|
+
readonly _tag: "Error";
|
|
2011
|
+
readonly diagnostic: MarkdownDiagnostic;
|
|
2012
|
+
readonly path: MarkdownPath;
|
|
2013
|
+
readonly depth: number;
|
|
2014
|
+
}, "_tag">;
|
|
2015
|
+
readonly Exit: Data.TaggedEnum.ConstructorFrom<{
|
|
2016
|
+
readonly _tag: "Exit";
|
|
2017
|
+
readonly node: MarkdownNode;
|
|
2018
|
+
readonly path: MarkdownPath;
|
|
2019
|
+
readonly depth: number;
|
|
2020
|
+
}, "_tag">;
|
|
2021
|
+
};
|
|
2022
|
+
/**
|
|
2023
|
+
* SAX-style markdown tree visitor statics. Not instantiable.
|
|
2024
|
+
*
|
|
2025
|
+
* @public
|
|
2026
|
+
*/
|
|
2027
|
+
declare class MarkdownVisitor {
|
|
2028
|
+
private constructor();
|
|
2029
|
+
/**
|
|
2030
|
+
* Create a lazy `Stream` of `MarkdownVisitorEvent` walking `root` in
|
|
2031
|
+
* document pre-order: `Enter` and `Exit` for every node including the
|
|
2032
|
+
* root and every leaf. Events are produced on demand, so combining with
|
|
2033
|
+
* `Stream.take` allows efficient partial scans without walking the rest
|
|
2034
|
+
* of the tree.
|
|
2035
|
+
*
|
|
2036
|
+
* @remarks
|
|
2037
|
+
* Infallible at the type level. A tree produced by `Markdown.parse` can
|
|
2038
|
+
* never trip the walk's depth guard — the parser refuses deeper input —
|
|
2039
|
+
* but a decoded foreign tree (`Mdast.fromMdast`) can; the trip surfaces
|
|
2040
|
+
* as a terminal `MarkdownVisitorEvent` `Error` event carrying a
|
|
2041
|
+
* `NestingDepthExceeded` {@link MarkdownDiagnostic}, mirroring the typed
|
|
2042
|
+
* failure `Markdown.stringify` produces for the same tree.
|
|
2043
|
+
*/
|
|
2044
|
+
static visit(root: Root): Stream.Stream<MarkdownVisitorEvent>;
|
|
2045
|
+
}
|
|
2046
|
+
//#endregion
|
|
2047
|
+
//#region src/Mdast.d.ts
|
|
2048
|
+
/**
|
|
2049
|
+
* A plain mdast node: a `type` tag plus whatever fields that type carries.
|
|
2050
|
+
*
|
|
2051
|
+
* @remarks
|
|
2052
|
+
* Deliberately loose — plain-object mdast is a foreign, structurally-typed
|
|
2053
|
+
* contract; the precise shapes live in the mdast specification, and
|
|
2054
|
+
* {@link Mdast.fromMdast} is the checked way back into typed nodes.
|
|
2055
|
+
*
|
|
2056
|
+
* @public
|
|
2057
|
+
*/
|
|
2058
|
+
interface MdastNode {
|
|
2059
|
+
readonly type: string;
|
|
2060
|
+
readonly [key: string]: unknown;
|
|
2061
|
+
}
|
|
2062
|
+
declare const MdastDecodeError_base: Schema.Class<MdastDecodeError, Schema.TaggedStruct<"MdastDecodeError", {
|
|
2063
|
+
/** The structured schema issue. Never a string. */
|
|
2064
|
+
readonly issue: Schema.Defect;
|
|
2065
|
+
}>, import("effect/Cause").YieldableError>;
|
|
2066
|
+
/**
|
|
2067
|
+
* Indicates that foreign mdast input failed to decode into the package's
|
|
2068
|
+
* node classes.
|
|
2069
|
+
*
|
|
2070
|
+
* @remarks
|
|
2071
|
+
* `issue` carries the **structured** schema failure — at runtime a
|
|
2072
|
+
* `SchemaIssue.Issue` tree, reachable through `_tag` and nested `issues` —
|
|
2073
|
+
* never a stringified rendering (the `FrontmatterValidationError`
|
|
2074
|
+
* precedent). It is typed `unknown` because v4 exposes no `Schema` for
|
|
2075
|
+
* `Issue`; narrow it with the `SchemaIssue` module.
|
|
2076
|
+
*
|
|
2077
|
+
* @public
|
|
2078
|
+
*/
|
|
2079
|
+
declare class MdastDecodeError extends MdastDecodeError_base {
|
|
2080
|
+
get message(): string;
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* The mdast projection facade — the remark-ecosystem interop boundary.
|
|
2084
|
+
*
|
|
2085
|
+
* @public
|
|
2086
|
+
*/
|
|
2087
|
+
declare class Mdast {
|
|
2088
|
+
/**
|
|
2089
|
+
* Project a parsed {@link Root} to plain mdast JSON.
|
|
2090
|
+
*
|
|
2091
|
+
* @remarks
|
|
2092
|
+
* Total and pure: every tree the parser or {@link Mdast.fromMdast}
|
|
2093
|
+
* produces projects without failure. Fidelity extras are stripped;
|
|
2094
|
+
* optional mdast fields are spelled the way `mdast-util-from-markdown`
|
|
2095
|
+
* spells them, so the output deep-equals the reference utility's trees
|
|
2096
|
+
* (the vendored interop corpus pins this). The frontmatter capture
|
|
2097
|
+
* projects to a `yaml`/`toml`/`json` literal node.
|
|
2098
|
+
*
|
|
2099
|
+
* @param root - The parsed document tree.
|
|
2100
|
+
* @returns A plain mdast `root` object with unist positions.
|
|
2101
|
+
*/
|
|
2102
|
+
static toMdast(root: Root): MdastNode;
|
|
2103
|
+
/**
|
|
2104
|
+
* Decode foreign plain mdast into the package's node classes,
|
|
2105
|
+
* synchronously, as a `Result`. The pure primitive twin of
|
|
2106
|
+
* {@link Mdast.fromMdast}.
|
|
2107
|
+
*
|
|
2108
|
+
* @remarks
|
|
2109
|
+
* unist makes positions optional and this package's classes require
|
|
2110
|
+
* them, so missing or incomplete positions are synthesized as the
|
|
2111
|
+
* zero-width sentinel (line 1, column 1, offset 0) — clearly synthetic
|
|
2112
|
+
* and inert for rendering. Trees carrying sentinel positions serve
|
|
2113
|
+
* tree-level workflows (stringify, the visitor, projection back out),
|
|
2114
|
+
* not offset-splice editing, whose offsets must come from a real parse.
|
|
2115
|
+
* `null` values on optional fields normalize to absence per unist's
|
|
2116
|
+
* null-equals-absent convention; foreign `data` and other unrecognized
|
|
2117
|
+
* fields are dropped at the boundary; `yaml`/`toml`/`json` literal nodes
|
|
2118
|
+
* decode into the {@link Frontmatter} capture. Unknown node types fail
|
|
2119
|
+
* typed.
|
|
2120
|
+
*
|
|
2121
|
+
* @param input - A plain mdast tree, typically a `root`.
|
|
2122
|
+
* @returns A `Result` succeeding with the decoded {@link Root}, or
|
|
2123
|
+
* failing with {@link MdastDecodeError} carrying the structured issue.
|
|
2124
|
+
*/
|
|
2125
|
+
static fromMdastResult(input: unknown): Result.Result<Root, MdastDecodeError>;
|
|
2126
|
+
/**
|
|
2127
|
+
* Decode foreign plain mdast into the package's node classes. Defined in
|
|
2128
|
+
* terms of {@link Mdast.fromMdastResult} — synchronous callers can use
|
|
2129
|
+
* that variant directly.
|
|
2130
|
+
*
|
|
2131
|
+
* @param input - A plain mdast tree, typically a `root`.
|
|
2132
|
+
* @returns An `Effect` that succeeds with the decoded {@link Root}, or
|
|
2133
|
+
* fails with {@link MdastDecodeError}.
|
|
2134
|
+
*/
|
|
2135
|
+
static readonly fromMdast: (input: unknown) => Effect.Effect<Root, MdastDecodeError, never>;
|
|
2136
|
+
}
|
|
2137
|
+
//#endregion
|
|
2138
|
+
//#region src/TomlFrontmatter.d.ts
|
|
2139
|
+
/**
|
|
2140
|
+
* The toml frontmatter codec, over `@effected/toml`.
|
|
2141
|
+
*
|
|
2142
|
+
* @remarks
|
|
2143
|
+
* Decodes a `+++`-fenced capture's raw value with `Toml.parse`, so the toml
|
|
2144
|
+
* engine's nesting depth cap fails through the typed channel: a hostile
|
|
2145
|
+
* frontmatter block surfaces as a {@link FrontmatterDecodeError} carrying the
|
|
2146
|
+
* `TomlParseError` structurally, never a defect. An empty capture decodes to
|
|
2147
|
+
* an empty table (`{}`), toml's empty-document value.
|
|
2148
|
+
*
|
|
2149
|
+
* Encodes with `Toml.stringify`; a value toml cannot represent fails as a
|
|
2150
|
+
* {@link FrontmatterEncodeError} carrying the `TomlStringifyError`
|
|
2151
|
+
* structurally. An empty object encodes to the **empty body** — the exact
|
|
2152
|
+
* mirror of the decode ruling above, rendering as adjacent `+++` fences —
|
|
2153
|
+
* so `set`-then-decode recovers `{}` exactly.
|
|
2154
|
+
*
|
|
2155
|
+
* `@effected/toml` is an optional peer — importing this module is what
|
|
2156
|
+
* requires it; a consumer who never touches toml frontmatter never loads the
|
|
2157
|
+
* toml engine.
|
|
2158
|
+
*
|
|
2159
|
+
* @public
|
|
2160
|
+
*/
|
|
2161
|
+
declare const TomlFrontmatter: FrontmatterCodec;
|
|
2162
|
+
//#endregion
|
|
2163
|
+
//#region src/YamlFrontmatter.d.ts
|
|
2164
|
+
/**
|
|
2165
|
+
* The yaml frontmatter codec, over `@effected/yaml`.
|
|
2166
|
+
*
|
|
2167
|
+
* @remarks
|
|
2168
|
+
* Decodes a `---`-fenced capture's raw value with `Yaml.parse`, so the yaml
|
|
2169
|
+
* engine's input hardening — the alias-expansion budget and the nesting depth
|
|
2170
|
+
* cap — fails through the typed channel: a hostile frontmatter block surfaces
|
|
2171
|
+
* as a {@link FrontmatterDecodeError} carrying the `YamlParseError`
|
|
2172
|
+
* structurally, never a defect. An empty capture decodes to `null`, yaml's
|
|
2173
|
+
* empty-document value.
|
|
2174
|
+
*
|
|
2175
|
+
* Encodes with `Yaml.stringify`; an unserializable value fails as a
|
|
2176
|
+
* {@link FrontmatterEncodeError} carrying the `YamlStringifyError`
|
|
2177
|
+
* structurally. An empty object encodes to the flow mapping `{}` —
|
|
2178
|
+
* deliberately not an empty body, which would round-trip as `null` — so
|
|
2179
|
+
* `set`-then-decode recovers `{}` exactly.
|
|
2180
|
+
*
|
|
2181
|
+
* `@effected/yaml` is an optional peer — importing this module is what
|
|
2182
|
+
* requires it; a consumer who never touches yaml frontmatter never loads the
|
|
2183
|
+
* yaml engine.
|
|
2184
|
+
*
|
|
2185
|
+
* @public
|
|
2186
|
+
*/
|
|
2187
|
+
declare const YamlFrontmatter: FrontmatterCodec;
|
|
2188
|
+
//#endregion
|
|
2189
|
+
export { Blockquote, Break, BreakStyle, BulletChar, Code, Definition, Delete, type DocumentHeading, type DocumentLink, type DocumentSection, Emphasis, EmphasisChar, FenceChar, FlowContent, FootnoteDefinition, FootnoteReference, Frontmatter, type FrontmatterCodec, FrontmatterContent, FrontmatterDecodeError, FrontmatterEncodeError, FrontmatterFormat, FrontmatterFormatMismatchError, FrontmatterMissingError, type FrontmatterResolveError, type FrontmatterSchemaError, type FrontmatterSchemaResolver, FrontmatterValidationError, type FrontmatterWriteError, Heading, HeadingDepth, HeadingStyle, Html, Image, ImageReference, InlineCode, JsonFrontmatter, Link, type LinkBearingNode, LinkReference, List, ListContent, ListDelimiter, ListItem, Markdown, MarkdownDiagnostic, MarkdownDialect, MarkdownDocument, MarkdownEdit, MarkdownFormat, MarkdownFormattingOptions, MarkdownFrontmatter, MarkdownModificationError, MarkdownModificationErrorCode, MarkdownNode, type MarkdownNodeOfType, type MarkdownNodeType, MarkdownParseError, MarkdownParseErrorCode, MarkdownParseOptions, type MarkdownPath, MarkdownRange, type MarkdownRangeLike, type MarkdownSegment, MarkdownStringifyError, MarkdownVisitor, MarkdownVisitorEvent, Mdast, MdastDecodeError, type MdastNode, Paragraph, PhrasingContent, Point, Position, ReferenceType, Root, RowContent, SchemaDeclaration, SchemaDeclarationByName, SchemaDeclarationByPath, SchemaDeclarationByUrl, SchemaDeclarationInline, SchemaDeclarationInvalidError, SchemaDeclarationMissingError, SchemaNameUnknownError, SchemaResolver, SchemaVersionUnresolvableError, Strong, Table, TableAlign, TableCell, TableContent, TableRow, Text, ThematicBreak, ThematicBreakChar, TomlFrontmatter, YamlFrontmatter };
|
|
2190
|
+
//# sourceMappingURL=index.d.ts.map
|