@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/MarkdownNode.js
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/MarkdownNode.ts
|
|
4
|
+
/**
|
|
5
|
+
* A single point in a source document: 1-based `line` and `column`, 0-based
|
|
6
|
+
* `offset`.
|
|
7
|
+
*
|
|
8
|
+
* `offset` is the index into the source string, which is what the edit layer
|
|
9
|
+
* splices against; `line`/`column` are the human-facing coordinates unist
|
|
10
|
+
* specifies.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
var Point = class extends Schema.Class("Point")({
|
|
15
|
+
line: Schema.Number,
|
|
16
|
+
column: Schema.Number,
|
|
17
|
+
offset: Schema.Number
|
|
18
|
+
}) {};
|
|
19
|
+
/**
|
|
20
|
+
* The source span of a node: `start` inclusive, `end` exclusive.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
var Position = class Position extends Schema.Class("Position")({
|
|
25
|
+
start: Point,
|
|
26
|
+
end: Point
|
|
27
|
+
}) {
|
|
28
|
+
/**
|
|
29
|
+
* The zero-width synthetic position: line 1, column 1, offset 0 at both
|
|
30
|
+
* ends — the span every node class's `make` fills in when `position` is
|
|
31
|
+
* omitted, and the same sentinel `Mdast.fromMdast` synthesizes for foreign
|
|
32
|
+
* nodes that carry none.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Clearly synthetic and inert for rendering: trees carrying it serve
|
|
36
|
+
* tree-level workflows (stringify, the visitor, `MarkdownFormat.modify`
|
|
37
|
+
* replacement fragments, projection out), not offset-splice editing, whose
|
|
38
|
+
* offsets must come from a real parse.
|
|
39
|
+
*/
|
|
40
|
+
static synthetic = Position.make({
|
|
41
|
+
start: Point.make({
|
|
42
|
+
line: 1,
|
|
43
|
+
column: 1,
|
|
44
|
+
offset: 0
|
|
45
|
+
}),
|
|
46
|
+
end: Point.make({
|
|
47
|
+
line: 1,
|
|
48
|
+
column: 1,
|
|
49
|
+
offset: 0
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const NodePosition = Position.pipe(Schema.withConstructorDefault(Effect.succeed(Position.synthetic)));
|
|
54
|
+
/**
|
|
55
|
+
* The explicitness of a reference, per mdast's `referenceType` enum.
|
|
56
|
+
*
|
|
57
|
+
* - `shortcut` — implicit, identifier inferred from the content (`[foo]`).
|
|
58
|
+
* - `collapsed` — explicit, identifier inferred from the content (`[foo][]`).
|
|
59
|
+
* - `full` — explicit, identifier explicitly set (`[foo][bar]`).
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
const ReferenceType = Schema.Literals([
|
|
64
|
+
"shortcut",
|
|
65
|
+
"collapsed",
|
|
66
|
+
"full"
|
|
67
|
+
]);
|
|
68
|
+
/**
|
|
69
|
+
* The two ways CommonMark spells a heading: `atx` (`# Title`) and `setext`
|
|
70
|
+
* (a title underlined with `=` or `-`).
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
const HeadingStyle = Schema.Literals(["atx", "setext"]);
|
|
75
|
+
/**
|
|
76
|
+
* The two ways CommonMark spells a hard line break: a trailing backslash or
|
|
77
|
+
* two-or-more trailing spaces.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
const BreakStyle = Schema.Literals(["backslash", "spaces"]);
|
|
82
|
+
/**
|
|
83
|
+
* The two fence characters a fenced code block may use.
|
|
84
|
+
*
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
const FenceChar = Schema.Literals(["`", "~"]);
|
|
88
|
+
/**
|
|
89
|
+
* The three bullet characters an unordered list may use.
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
const BulletChar = Schema.Literals([
|
|
94
|
+
"-",
|
|
95
|
+
"*",
|
|
96
|
+
"+"
|
|
97
|
+
]);
|
|
98
|
+
/**
|
|
99
|
+
* The two delimiters an ordered list marker may use (`1.` or `1)`).
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
const ListDelimiter = Schema.Literals([".", ")"]);
|
|
104
|
+
/**
|
|
105
|
+
* The three characters a thematic break may be drawn with.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
const ThematicBreakChar = Schema.Literals([
|
|
110
|
+
"-",
|
|
111
|
+
"_",
|
|
112
|
+
"*"
|
|
113
|
+
]);
|
|
114
|
+
/**
|
|
115
|
+
* The two characters emphasis and strong emphasis may be marked with.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
const EmphasisChar = Schema.Literals(["*", "_"]);
|
|
120
|
+
/**
|
|
121
|
+
* The six legal ATX/setext heading depths.
|
|
122
|
+
*
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
const HeadingDepth = Schema.Literals([
|
|
126
|
+
1,
|
|
127
|
+
2,
|
|
128
|
+
3,
|
|
129
|
+
4,
|
|
130
|
+
5,
|
|
131
|
+
6
|
|
132
|
+
]);
|
|
133
|
+
/**
|
|
134
|
+
* The three alignments a GFM table column may declare. A `null` entry in a
|
|
135
|
+
* {@link Table}'s `align` array means the column carries no alignment.
|
|
136
|
+
*
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
const TableAlign = Schema.Literals([
|
|
140
|
+
"left",
|
|
141
|
+
"right",
|
|
142
|
+
"center"
|
|
143
|
+
]);
|
|
144
|
+
/**
|
|
145
|
+
* Text — a run of literal characters, with entity references and backslash
|
|
146
|
+
* escapes already resolved into `value`.
|
|
147
|
+
*
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
var Text = class extends Schema.Class("Text")({
|
|
151
|
+
type: Schema.tag("text"),
|
|
152
|
+
value: Schema.String,
|
|
153
|
+
position: NodePosition
|
|
154
|
+
}) {};
|
|
155
|
+
/**
|
|
156
|
+
* InlineCode — a code span: `foo` written between backtick fences in the
|
|
157
|
+
* source. `value` holds the span's content with the backtick fence stripped
|
|
158
|
+
* and the spec's space-stripping applied.
|
|
159
|
+
*
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
var InlineCode = class extends Schema.Class("InlineCode")({
|
|
163
|
+
type: Schema.tag("inlineCode"),
|
|
164
|
+
value: Schema.String,
|
|
165
|
+
position: NodePosition
|
|
166
|
+
}) {};
|
|
167
|
+
/**
|
|
168
|
+
* Html — a fragment of raw HTML, kept verbatim. Used for both HTML blocks
|
|
169
|
+
* (flow) and inline raw HTML (phrasing); the same node type serves both, as
|
|
170
|
+
* mdast specifies.
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
var Html = class extends Schema.Class("Html")({
|
|
175
|
+
type: Schema.tag("html"),
|
|
176
|
+
value: Schema.String,
|
|
177
|
+
position: NodePosition
|
|
178
|
+
}) {};
|
|
179
|
+
/**
|
|
180
|
+
* Break — a hard line break.
|
|
181
|
+
*
|
|
182
|
+
* `breakStyle` is a fidelity extra recording which of the two CommonMark
|
|
183
|
+
* spellings produced it.
|
|
184
|
+
*
|
|
185
|
+
* @public
|
|
186
|
+
*/
|
|
187
|
+
var Break = class extends Schema.Class("Break")({
|
|
188
|
+
type: Schema.tag("break"),
|
|
189
|
+
position: NodePosition,
|
|
190
|
+
breakStyle: Schema.optionalKey(BreakStyle)
|
|
191
|
+
}) {};
|
|
192
|
+
/**
|
|
193
|
+
* Image — an inline image (``).
|
|
194
|
+
*
|
|
195
|
+
* @public
|
|
196
|
+
*/
|
|
197
|
+
var Image = class extends Schema.Class("Image")({
|
|
198
|
+
type: Schema.tag("image"),
|
|
199
|
+
url: Schema.String,
|
|
200
|
+
title: Schema.optionalKey(Schema.String),
|
|
201
|
+
alt: Schema.optionalKey(Schema.String),
|
|
202
|
+
position: NodePosition
|
|
203
|
+
}) {};
|
|
204
|
+
/**
|
|
205
|
+
* ImageReference — an image referring to a {@link Definition} by identifier
|
|
206
|
+
* (`![alt][ref]`).
|
|
207
|
+
*
|
|
208
|
+
* The parser emits these unresolved, whether or not a matching definition
|
|
209
|
+
* exists in the tree — resolution is the consumer's business.
|
|
210
|
+
*
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
var ImageReference = class extends Schema.Class("ImageReference")({
|
|
214
|
+
type: Schema.tag("imageReference"),
|
|
215
|
+
identifier: Schema.String,
|
|
216
|
+
label: Schema.optionalKey(Schema.String),
|
|
217
|
+
referenceType: ReferenceType,
|
|
218
|
+
alt: Schema.optionalKey(Schema.String),
|
|
219
|
+
position: NodePosition
|
|
220
|
+
}) {};
|
|
221
|
+
/**
|
|
222
|
+
* Emphasis — `*foo*` or `_foo_`.
|
|
223
|
+
*
|
|
224
|
+
* `markerChar` is a fidelity extra recording which marker produced it.
|
|
225
|
+
*
|
|
226
|
+
* @public
|
|
227
|
+
*/
|
|
228
|
+
var Emphasis = class extends Schema.Class("Emphasis")({
|
|
229
|
+
type: Schema.tag("emphasis"),
|
|
230
|
+
children: Schema.Array(Schema.suspend(() => PhrasingContent)),
|
|
231
|
+
position: NodePosition,
|
|
232
|
+
markerChar: Schema.optionalKey(EmphasisChar)
|
|
233
|
+
}) {};
|
|
234
|
+
/**
|
|
235
|
+
* Strong — `**foo**` or `__foo__`.
|
|
236
|
+
*
|
|
237
|
+
* `markerChar` is a fidelity extra recording which marker produced it.
|
|
238
|
+
*
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
var Strong = class extends Schema.Class("Strong")({
|
|
242
|
+
type: Schema.tag("strong"),
|
|
243
|
+
children: Schema.Array(Schema.suspend(() => PhrasingContent)),
|
|
244
|
+
position: NodePosition,
|
|
245
|
+
markerChar: Schema.optionalKey(EmphasisChar)
|
|
246
|
+
}) {};
|
|
247
|
+
/**
|
|
248
|
+
* Delete — GFM strikethrough (`~~foo~~`). Content that is no longer accurate
|
|
249
|
+
* or relevant.
|
|
250
|
+
*
|
|
251
|
+
* `~~` is the only marker `~~foo~~` renders through, so unlike
|
|
252
|
+
* {@link Emphasis} and {@link Strong} there is no marker-character fidelity
|
|
253
|
+
* extra to carry.
|
|
254
|
+
*
|
|
255
|
+
* @public
|
|
256
|
+
*/
|
|
257
|
+
var Delete = class extends Schema.Class("Delete")({
|
|
258
|
+
type: Schema.tag("delete"),
|
|
259
|
+
children: Schema.Array(Schema.suspend(() => PhrasingContent)),
|
|
260
|
+
position: NodePosition
|
|
261
|
+
}) {};
|
|
262
|
+
/**
|
|
263
|
+
* Link — an inline link (`[text](url "title")`), including autolinks.
|
|
264
|
+
*
|
|
265
|
+
* @public
|
|
266
|
+
*/
|
|
267
|
+
var Link = class extends Schema.Class("Link")({
|
|
268
|
+
type: Schema.tag("link"),
|
|
269
|
+
url: Schema.String,
|
|
270
|
+
title: Schema.optionalKey(Schema.String),
|
|
271
|
+
children: Schema.Array(Schema.suspend(() => PhrasingContent)),
|
|
272
|
+
position: NodePosition
|
|
273
|
+
}) {};
|
|
274
|
+
/**
|
|
275
|
+
* LinkReference — a link referring to a {@link Definition} by identifier
|
|
276
|
+
* (`[text][ref]`).
|
|
277
|
+
*
|
|
278
|
+
* Emitted unresolved, on the same terms as {@link ImageReference}.
|
|
279
|
+
*
|
|
280
|
+
* @public
|
|
281
|
+
*/
|
|
282
|
+
var LinkReference = class extends Schema.Class("LinkReference")({
|
|
283
|
+
type: Schema.tag("linkReference"),
|
|
284
|
+
identifier: Schema.String,
|
|
285
|
+
label: Schema.optionalKey(Schema.String),
|
|
286
|
+
referenceType: ReferenceType,
|
|
287
|
+
children: Schema.Array(Schema.suspend(() => PhrasingContent)),
|
|
288
|
+
position: NodePosition
|
|
289
|
+
}) {};
|
|
290
|
+
/**
|
|
291
|
+
* FootnoteReference — a GFM footnote marker (`[^alpha]`), associating this
|
|
292
|
+
* point in the text with a {@link FootnoteDefinition} by identifier.
|
|
293
|
+
*
|
|
294
|
+
* Has no content model of its own — the marker carries no children, only the
|
|
295
|
+
* mdast Association pair `identifier`/`label`. Like {@link LinkReference},
|
|
296
|
+
* the parser emits these unresolved: resolution against a matching
|
|
297
|
+
* `FootnoteDefinition` is the consumer's business.
|
|
298
|
+
*
|
|
299
|
+
* @public
|
|
300
|
+
*/
|
|
301
|
+
var FootnoteReference = class extends Schema.Class("FootnoteReference")({
|
|
302
|
+
type: Schema.tag("footnoteReference"),
|
|
303
|
+
identifier: Schema.String,
|
|
304
|
+
label: Schema.optionalKey(Schema.String),
|
|
305
|
+
position: NodePosition
|
|
306
|
+
}) {};
|
|
307
|
+
/**
|
|
308
|
+
* The union of every node that may appear where mdast expects **phrasing**
|
|
309
|
+
* content — the text of a document and its markup.
|
|
310
|
+
*
|
|
311
|
+
* Defined lazily via `Schema.suspend` to break the recursive reference chain
|
|
312
|
+
* `PhrasingContent -> Emphasis/Strong/Link/LinkReference -> PhrasingContent`.
|
|
313
|
+
*
|
|
314
|
+
* @public
|
|
315
|
+
*/
|
|
316
|
+
const PhrasingContent = Schema.suspend(() => Schema.Union([
|
|
317
|
+
Break,
|
|
318
|
+
Delete,
|
|
319
|
+
Emphasis,
|
|
320
|
+
FootnoteReference,
|
|
321
|
+
Html,
|
|
322
|
+
Image,
|
|
323
|
+
ImageReference,
|
|
324
|
+
InlineCode,
|
|
325
|
+
Link,
|
|
326
|
+
LinkReference,
|
|
327
|
+
Strong,
|
|
328
|
+
Text
|
|
329
|
+
]));
|
|
330
|
+
/**
|
|
331
|
+
* ThematicBreak — a horizontal rule (`---`, `***`, `___`).
|
|
332
|
+
*
|
|
333
|
+
* `markerChar` is a fidelity extra recording which character drew it.
|
|
334
|
+
*
|
|
335
|
+
* @public
|
|
336
|
+
*/
|
|
337
|
+
var ThematicBreak = class extends Schema.Class("ThematicBreak")({
|
|
338
|
+
type: Schema.tag("thematicBreak"),
|
|
339
|
+
position: NodePosition,
|
|
340
|
+
markerChar: Schema.optionalKey(ThematicBreakChar)
|
|
341
|
+
}) {};
|
|
342
|
+
/**
|
|
343
|
+
* Code — a code block, fenced or indented.
|
|
344
|
+
*
|
|
345
|
+
* `lang` and `meta` split the fence's info string at the first run of
|
|
346
|
+
* whitespace. The fidelity extras `fenceChar` and `fenceLength` are present
|
|
347
|
+
* for fenced blocks and **absent for indented blocks** — their absence is how
|
|
348
|
+
* the two are told apart on the way back out.
|
|
349
|
+
*
|
|
350
|
+
* @public
|
|
351
|
+
*/
|
|
352
|
+
var Code = class extends Schema.Class("Code")({
|
|
353
|
+
type: Schema.tag("code"),
|
|
354
|
+
value: Schema.String,
|
|
355
|
+
lang: Schema.optionalKey(Schema.String),
|
|
356
|
+
meta: Schema.optionalKey(Schema.String),
|
|
357
|
+
position: NodePosition,
|
|
358
|
+
fenceChar: Schema.optionalKey(FenceChar),
|
|
359
|
+
fenceLength: Schema.optionalKey(Schema.Number)
|
|
360
|
+
}) {};
|
|
361
|
+
/**
|
|
362
|
+
* Definition — a link reference definition (`[ref]: /url "title"`).
|
|
363
|
+
*
|
|
364
|
+
* Kept in the tree at its source position rather than stripped, which is the
|
|
365
|
+
* deliberate departure from commonmark.js and the reason references can stay
|
|
366
|
+
* unresolved.
|
|
367
|
+
*
|
|
368
|
+
* @public
|
|
369
|
+
*/
|
|
370
|
+
var Definition = class extends Schema.Class("Definition")({
|
|
371
|
+
type: Schema.tag("definition"),
|
|
372
|
+
identifier: Schema.String,
|
|
373
|
+
label: Schema.optionalKey(Schema.String),
|
|
374
|
+
url: Schema.String,
|
|
375
|
+
title: Schema.optionalKey(Schema.String),
|
|
376
|
+
position: NodePosition
|
|
377
|
+
}) {};
|
|
378
|
+
/**
|
|
379
|
+
* FootnoteDefinition — a GFM footnote definition (`[^alpha]: bravo.`), the
|
|
380
|
+
* content a {@link FootnoteReference} points at.
|
|
381
|
+
*
|
|
382
|
+
* Kept in the tree at its source position, on the same terms as
|
|
383
|
+
* {@link Definition} — the parser never relocates it; a consumer that wants
|
|
384
|
+
* cmark-gfm's end-of-document footnote section renders it there instead.
|
|
385
|
+
*
|
|
386
|
+
* @public
|
|
387
|
+
*/
|
|
388
|
+
var FootnoteDefinition = class extends Schema.Class("FootnoteDefinition")({
|
|
389
|
+
type: Schema.tag("footnoteDefinition"),
|
|
390
|
+
identifier: Schema.String,
|
|
391
|
+
label: Schema.optionalKey(Schema.String),
|
|
392
|
+
children: Schema.Array(Schema.suspend(() => FlowContent)),
|
|
393
|
+
position: NodePosition
|
|
394
|
+
}) {};
|
|
395
|
+
/**
|
|
396
|
+
* Paragraph — a run of phrasing content.
|
|
397
|
+
*
|
|
398
|
+
* @public
|
|
399
|
+
*/
|
|
400
|
+
var Paragraph = class extends Schema.Class("Paragraph")({
|
|
401
|
+
type: Schema.tag("paragraph"),
|
|
402
|
+
children: Schema.Array(Schema.suspend(() => PhrasingContent)),
|
|
403
|
+
position: NodePosition
|
|
404
|
+
}) {};
|
|
405
|
+
/**
|
|
406
|
+
* Heading — an ATX or setext heading of depth 1 to 6.
|
|
407
|
+
*
|
|
408
|
+
* `headingStyle` is a fidelity extra recording which spelling produced it;
|
|
409
|
+
* setext headings can only be depth 1 or 2.
|
|
410
|
+
*
|
|
411
|
+
* @public
|
|
412
|
+
*/
|
|
413
|
+
var Heading = class extends Schema.Class("Heading")({
|
|
414
|
+
type: Schema.tag("heading"),
|
|
415
|
+
depth: HeadingDepth,
|
|
416
|
+
children: Schema.Array(Schema.suspend(() => PhrasingContent)),
|
|
417
|
+
position: NodePosition,
|
|
418
|
+
headingStyle: Schema.optionalKey(HeadingStyle)
|
|
419
|
+
}) {};
|
|
420
|
+
/**
|
|
421
|
+
* ListItem — one item of a {@link List}.
|
|
422
|
+
*
|
|
423
|
+
* `spread` follows mdast in being optional: absent means "not known", which a
|
|
424
|
+
* hand-built tree may legitimately be. The parser always sets it.
|
|
425
|
+
*
|
|
426
|
+
* `checked` is a GFM extra (task-list items, `- [ ] foo` / `- [x] foo`):
|
|
427
|
+
* `true` for done, `false` for not done, and **absent** — never `null` — for
|
|
428
|
+
* an item that is not a task-list item at all. The parser only ever sets it
|
|
429
|
+
* on items it recognized as task-list markers.
|
|
430
|
+
*
|
|
431
|
+
* @public
|
|
432
|
+
*/
|
|
433
|
+
var ListItem = class extends Schema.Class("ListItem")({
|
|
434
|
+
type: Schema.tag("listItem"),
|
|
435
|
+
spread: Schema.optionalKey(Schema.Boolean),
|
|
436
|
+
children: Schema.Array(Schema.suspend(() => FlowContent)),
|
|
437
|
+
position: NodePosition,
|
|
438
|
+
checked: Schema.optionalKey(Schema.Boolean)
|
|
439
|
+
}) {};
|
|
440
|
+
/**
|
|
441
|
+
* List — an ordered or unordered list.
|
|
442
|
+
*
|
|
443
|
+
* `ordered`, `start` and `spread` are all optional per mdast (absent meaning
|
|
444
|
+
* "not known"); the parser always sets `ordered` and `spread`, and sets
|
|
445
|
+
* `start` only for ordered lists.
|
|
446
|
+
*
|
|
447
|
+
* The fidelity extras record the marker actually used: `bulletChar` for
|
|
448
|
+
* unordered lists, `delimiter` for ordered ones.
|
|
449
|
+
*
|
|
450
|
+
* @public
|
|
451
|
+
*/
|
|
452
|
+
var List = class extends Schema.Class("List")({
|
|
453
|
+
type: Schema.tag("list"),
|
|
454
|
+
ordered: Schema.optionalKey(Schema.Boolean),
|
|
455
|
+
start: Schema.optionalKey(Schema.Number),
|
|
456
|
+
spread: Schema.optionalKey(Schema.Boolean),
|
|
457
|
+
children: Schema.Array(Schema.suspend(() => ListItem)),
|
|
458
|
+
position: NodePosition,
|
|
459
|
+
bulletChar: Schema.optionalKey(BulletChar),
|
|
460
|
+
delimiter: Schema.optionalKey(ListDelimiter)
|
|
461
|
+
}) {};
|
|
462
|
+
/**
|
|
463
|
+
* Blockquote — a section quoted from somewhere else.
|
|
464
|
+
*
|
|
465
|
+
* @public
|
|
466
|
+
*/
|
|
467
|
+
var Blockquote = class extends Schema.Class("Blockquote")({
|
|
468
|
+
type: Schema.tag("blockquote"),
|
|
469
|
+
children: Schema.Array(Schema.suspend(() => FlowContent)),
|
|
470
|
+
position: NodePosition
|
|
471
|
+
}) {};
|
|
472
|
+
/**
|
|
473
|
+
* TableCell — one cell of a {@link TableRow}: a header cell if its
|
|
474
|
+
* grandparent {@link Table}'s first row, a data cell otherwise.
|
|
475
|
+
*
|
|
476
|
+
* mdast's content model for `TableCell` is phrasing content **excluding**
|
|
477
|
+
* `Break` nodes — GFM tables are single-line source, so a hard break cannot
|
|
478
|
+
* occur inside one. This schema does not carve that exclusion out of
|
|
479
|
+
* `PhrasingContent`: a second phrasing union just for table cells would
|
|
480
|
+
* duplicate the whole recursive-suspend machinery above for one excluded
|
|
481
|
+
* member, and a parser that never emits `Break` inside a cell satisfies the
|
|
482
|
+
* exclusion in practice without it.
|
|
483
|
+
*
|
|
484
|
+
* @public
|
|
485
|
+
*/
|
|
486
|
+
var TableCell = class extends Schema.Class("TableCell")({
|
|
487
|
+
type: Schema.tag("tableCell"),
|
|
488
|
+
children: Schema.Array(Schema.suspend(() => PhrasingContent)),
|
|
489
|
+
position: NodePosition
|
|
490
|
+
}) {};
|
|
491
|
+
/**
|
|
492
|
+
* The union of every node that may appear where mdast expects **row**
|
|
493
|
+
* content — the cells in a {@link TableRow}. A one-member union, kept because
|
|
494
|
+
* mdast names the category.
|
|
495
|
+
*
|
|
496
|
+
* @public
|
|
497
|
+
*/
|
|
498
|
+
const RowContent = Schema.suspend(() => TableCell);
|
|
499
|
+
/**
|
|
500
|
+
* TableRow — one row of a {@link Table}: the labels of the columns if it is
|
|
501
|
+
* the table's first row, a data row otherwise.
|
|
502
|
+
*
|
|
503
|
+
* @public
|
|
504
|
+
*/
|
|
505
|
+
var TableRow = class extends Schema.Class("TableRow")({
|
|
506
|
+
type: Schema.tag("tableRow"),
|
|
507
|
+
children: Schema.Array(Schema.suspend(() => TableCell)),
|
|
508
|
+
position: NodePosition
|
|
509
|
+
}) {};
|
|
510
|
+
/**
|
|
511
|
+
* The union of every node that may appear where mdast expects **table**
|
|
512
|
+
* content — the rows in a {@link Table}. A one-member union, kept because
|
|
513
|
+
* mdast names the category.
|
|
514
|
+
*
|
|
515
|
+
* @public
|
|
516
|
+
*/
|
|
517
|
+
const TableContent = Schema.suspend(() => TableRow);
|
|
518
|
+
/**
|
|
519
|
+
* Table — GFM two-dimensional data.
|
|
520
|
+
*
|
|
521
|
+
* `align` is optional per mdast: absent means "not known" — which the parser
|
|
522
|
+
* never produces, since a GFM table's delimiter row always yields one
|
|
523
|
+
* `TableAlign | null` entry per column, but a hand-built tree may omit it.
|
|
524
|
+
* When present, each entry is `null` for a column with no declared alignment.
|
|
525
|
+
*
|
|
526
|
+
* @public
|
|
527
|
+
*/
|
|
528
|
+
var Table = class extends Schema.Class("Table")({
|
|
529
|
+
type: Schema.tag("table"),
|
|
530
|
+
align: Schema.optionalKey(Schema.Array(Schema.NullOr(TableAlign))),
|
|
531
|
+
children: Schema.Array(Schema.suspend(() => TableRow)),
|
|
532
|
+
position: NodePosition
|
|
533
|
+
}) {};
|
|
534
|
+
/**
|
|
535
|
+
* The union of every node that may appear where mdast expects **flow**
|
|
536
|
+
* content — the sections of a document.
|
|
537
|
+
*
|
|
538
|
+
* Defined lazily via `Schema.suspend` to break the recursive reference chain
|
|
539
|
+
* `FlowContent -> Blockquote/List -> FlowContent`. Widened for GFM with
|
|
540
|
+
* {@link FootnoteDefinition} and {@link Table}, per mdast's `FlowContent`
|
|
541
|
+
* (GFM) category.
|
|
542
|
+
*
|
|
543
|
+
* @public
|
|
544
|
+
*/
|
|
545
|
+
const FlowContent = Schema.suspend(() => Schema.Union([
|
|
546
|
+
Blockquote,
|
|
547
|
+
Code,
|
|
548
|
+
Definition,
|
|
549
|
+
FootnoteDefinition,
|
|
550
|
+
Heading,
|
|
551
|
+
Html,
|
|
552
|
+
List,
|
|
553
|
+
Paragraph,
|
|
554
|
+
Table,
|
|
555
|
+
ThematicBreak
|
|
556
|
+
]));
|
|
557
|
+
/**
|
|
558
|
+
* The union of every node that may appear where mdast expects **list**
|
|
559
|
+
* content. A one-member union, kept because mdast names the category and
|
|
560
|
+
* later dialects widen it.
|
|
561
|
+
*
|
|
562
|
+
* @public
|
|
563
|
+
*/
|
|
564
|
+
const ListContent = Schema.suspend(() => ListItem);
|
|
565
|
+
/**
|
|
566
|
+
* The frontmatter formats the capture recognizes, keyed by their opening
|
|
567
|
+
* fence: `---` is yaml, `+++` is toml and `---json` is json.
|
|
568
|
+
*
|
|
569
|
+
* @public
|
|
570
|
+
*/
|
|
571
|
+
const FrontmatterFormat = Schema.Literals([
|
|
572
|
+
"yaml",
|
|
573
|
+
"toml",
|
|
574
|
+
"json"
|
|
575
|
+
]);
|
|
576
|
+
/**
|
|
577
|
+
* Frontmatter — the raw, fidelity-preserving capture of a document's metadata
|
|
578
|
+
* block. `value` is the source text between the fences, exactly as written
|
|
579
|
+
* (never inline-parsed, never decoded); `format` records which fence captured
|
|
580
|
+
* it. The position spans the whole block including both fence lines.
|
|
581
|
+
*
|
|
582
|
+
* mdast has no single frontmatter node: it names `yaml` in the readme and
|
|
583
|
+
* `toml` through the frontmatter extension, and json has no mdast name at
|
|
584
|
+
* all. This package captures all three through ONE node — the design doc's
|
|
585
|
+
* "text plus a format marker" — and the `Mdast` projection (P5) maps
|
|
586
|
+
* `format` onto the mdast type names where they exist. Decoding the value is
|
|
587
|
+
* the codec modules' job (`YamlFrontmatter`/`TomlFrontmatter`/
|
|
588
|
+
* `JsonFrontmatter`, P3 Task 2); the engine never looks inside it.
|
|
589
|
+
*
|
|
590
|
+
* Only ever the first child of {@link Root}, and only when parsing opted in
|
|
591
|
+
* via `MarkdownParseOptions.frontmatter` — mdast's "limited to one node, only
|
|
592
|
+
* as head" constraint is structural here, not validated.
|
|
593
|
+
*
|
|
594
|
+
* @public
|
|
595
|
+
*/
|
|
596
|
+
var Frontmatter = class extends Schema.Class("Frontmatter")({
|
|
597
|
+
type: Schema.tag("frontmatter"),
|
|
598
|
+
format: FrontmatterFormat,
|
|
599
|
+
value: Schema.String,
|
|
600
|
+
position: NodePosition
|
|
601
|
+
}) {};
|
|
602
|
+
/**
|
|
603
|
+
* The union of every node that may appear where mdast expects
|
|
604
|
+
* **frontmatter** content — a one-member union, kept because mdast names the
|
|
605
|
+
* category (its member there is `Yaml`; ours is the format-agnostic capture).
|
|
606
|
+
*
|
|
607
|
+
* @public
|
|
608
|
+
*/
|
|
609
|
+
const FrontmatterContent = Schema.suspend(() => Frontmatter);
|
|
610
|
+
/**
|
|
611
|
+
* Root — a whole document, and the only node that is never a child.
|
|
612
|
+
*
|
|
613
|
+
* mdast leaves a root's content model open; a parsed markdown document is
|
|
614
|
+
* flow content, optionally headed by one {@link Frontmatter} node — mdast's
|
|
615
|
+
* `FlowContentFrontmatter` merge, which admits frontmatter at the root and
|
|
616
|
+
* nowhere else.
|
|
617
|
+
*
|
|
618
|
+
* @public
|
|
619
|
+
*/
|
|
620
|
+
var Root = class extends Schema.Class("Root")({
|
|
621
|
+
type: Schema.tag("root"),
|
|
622
|
+
children: Schema.Array(Schema.suspend(() => Schema.Union([Frontmatter, FlowContent]))),
|
|
623
|
+
position: NodePosition
|
|
624
|
+
}) {};
|
|
625
|
+
/**
|
|
626
|
+
* A schema matching any node in the tree.
|
|
627
|
+
*
|
|
628
|
+
* @public
|
|
629
|
+
*/
|
|
630
|
+
const MarkdownNode = Schema.suspend(() => Schema.Union([
|
|
631
|
+
Root,
|
|
632
|
+
FrontmatterContent,
|
|
633
|
+
FlowContent,
|
|
634
|
+
ListContent,
|
|
635
|
+
PhrasingContent,
|
|
636
|
+
RowContent,
|
|
637
|
+
TableContent
|
|
638
|
+
]));
|
|
639
|
+
|
|
640
|
+
//#endregion
|
|
641
|
+
export { Blockquote, Break, BreakStyle, BulletChar, Code, Definition, Delete, Emphasis, EmphasisChar, FenceChar, FlowContent, FootnoteDefinition, FootnoteReference, Frontmatter, FrontmatterContent, FrontmatterFormat, Heading, HeadingDepth, HeadingStyle, Html, Image, ImageReference, InlineCode, Link, LinkReference, List, ListContent, ListDelimiter, ListItem, MarkdownNode, Paragraph, PhrasingContent, Point, Position, ReferenceType, Root, RowContent, Strong, Table, TableAlign, TableCell, TableContent, TableRow, Text, ThematicBreak, ThematicBreakChar };
|