markemental 0.3.0 → 0.4.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/README.md +62 -25
- package/dist/index.cjs +1535 -973
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +582 -519
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +582 -519
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1527 -965
- package/dist/index.js.map +1 -1
- package/package.json +16 -13
package/dist/index.d.cts
CHANGED
|
@@ -1,87 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incremental modular markdown renderer.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Opaque handle for a node held by a target.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Minted by creation calls; never construct one by hand. Valid for
|
|
11
|
+
* detached nodes too, so renderers may build a subtree detached and
|
|
12
|
+
* attach it afterwards. Replacing or removing a node retires its id —
|
|
13
|
+
* and the ids of its subtree — and reusing a retired id throws.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
type NodeId = string;
|
|
18
|
+
/**
|
|
19
|
+
* A target call referenced an id the target never minted or already
|
|
20
|
+
* retired. Carries the offending id.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare class UnknownNodeError extends Error {
|
|
25
|
+
/** The unknown id. */
|
|
26
|
+
readonly nodeId: string;
|
|
27
|
+
/**
|
|
28
|
+
* @param nodeId - The unknown id.
|
|
29
|
+
*/
|
|
30
|
+
constructor(nodeId: string);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A replace targeted a node that was never attached. Carries the
|
|
34
|
+
* detached id.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export declare class DetachedNodeError extends Error {
|
|
39
|
+
/** The detached id. */
|
|
40
|
+
readonly nodeId: string;
|
|
41
|
+
/**
|
|
42
|
+
* @param nodeId - The detached id.
|
|
43
|
+
*/
|
|
44
|
+
constructor(nodeId: string);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* An attach would have built a cycle: the node is an ancestor of the
|
|
48
|
+
* parent. Carries both ids.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export declare class HierarchyError extends Error {
|
|
53
|
+
/** The node being attached. */
|
|
54
|
+
readonly nodeId: string;
|
|
55
|
+
/** The parent it was attached to. */
|
|
56
|
+
readonly parentId: string;
|
|
57
|
+
/**
|
|
58
|
+
* @param nodeId - The node being attached.
|
|
59
|
+
* @param parentId - The parent it was attached to.
|
|
60
|
+
*/
|
|
61
|
+
constructor(nodeId: string, parentId: string);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Write-only destination for rendered output.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* An HTML-like target: renderers build nodes through these methods without
|
|
68
|
+
* ever touching a DOM. Nodes start detached; appending attaches them, and
|
|
69
|
+
* a `null` parent addresses the top level. The target returns opaque ids
|
|
70
|
+
* and owns the id-to-node mapping (in memory, or however it likes); it
|
|
71
|
+
* cannot be queried.
|
|
72
|
+
*
|
|
73
|
+
* Attributes are set once at creation so remote targets never need
|
|
74
|
+
* mutation calls; replace the node to change them. Implementations must
|
|
75
|
+
* behave like the DOM for the operations below: appending an attached
|
|
76
|
+
* node moves it, and unknown ids throw. Custom targets (collectors,
|
|
77
|
+
* serializers, remote renderers) implement this same interface.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
interface HTMLTarget {
|
|
82
|
+
/**
|
|
83
|
+
* Create a detached element node with attributes.
|
|
84
|
+
*
|
|
85
|
+
* @param tag - Lowercase tag name (for example `"p"`).
|
|
86
|
+
* @param attrs - Attributes to set. Fixed at creation: replace the node
|
|
87
|
+
* to change them. Targets whose DOM cannot set attributes throw when
|
|
88
|
+
* this is non-empty.
|
|
89
|
+
* @returns Id addressing the new node.
|
|
90
|
+
*/
|
|
91
|
+
createElement(tag: string, attrs?: Record<string, string>): NodeId;
|
|
92
|
+
/**
|
|
93
|
+
* Create a detached text node.
|
|
94
|
+
*
|
|
95
|
+
* @param text - Text content.
|
|
96
|
+
* @returns Id addressing the new node.
|
|
97
|
+
*/
|
|
98
|
+
createTextNode(text: string): NodeId;
|
|
99
|
+
/**
|
|
100
|
+
* Append a child to a parent, or to the top level for a `null` parent.
|
|
101
|
+
* Appending an attached node moves it.
|
|
102
|
+
*
|
|
103
|
+
* @param parent - Receiving node, or `null` for the top level.
|
|
104
|
+
* @param child - Node to append.
|
|
105
|
+
* @throws {@link UnknownNodeError} for unknown ids.
|
|
106
|
+
* @throws {@link HierarchyError} when the child is an ancestor of the parent.
|
|
107
|
+
*/
|
|
108
|
+
appendChild(parent: NodeId | null, child: NodeId): void;
|
|
109
|
+
/**
|
|
110
|
+
* Replace an attached node with another node, which takes its position.
|
|
111
|
+
* The old id is retired. Replacing a detached node throws; replacing a
|
|
112
|
+
* node with itself is a no-op.
|
|
113
|
+
*
|
|
114
|
+
* @param oldId - Attached node to replace.
|
|
115
|
+
* @param newId - Replacement node.
|
|
116
|
+
* @throws {@link UnknownNodeError} for unknown ids.
|
|
117
|
+
* @throws {@link DetachedNodeError} when the old node was never attached.
|
|
118
|
+
* @throws {@link HierarchyError} when the new node is an ancestor of the position.
|
|
119
|
+
*/
|
|
120
|
+
replaceNode(oldId: NodeId, newId: NodeId): void;
|
|
121
|
+
/**
|
|
122
|
+
* Detach a node and retire its id.
|
|
123
|
+
*
|
|
124
|
+
* @param id - Node to remove.
|
|
125
|
+
* @throws {@link UnknownNodeError} for unknown ids.
|
|
126
|
+
*/
|
|
127
|
+
remove(id: NodeId): void;
|
|
128
|
+
/**
|
|
129
|
+
* Replace a node's children with a single text run, retiring the
|
|
130
|
+
* children's ids. On a text node, replaces its content.
|
|
131
|
+
*
|
|
132
|
+
* @param node - Node to update.
|
|
133
|
+
* @param text - Replacement text.
|
|
134
|
+
* @throws {@link UnknownNodeError} for unknown ids.
|
|
135
|
+
*/
|
|
136
|
+
setTextContent(node: NodeId, text: string): void;
|
|
137
|
+
/**
|
|
138
|
+
* Wait for all committed updates to land.
|
|
139
|
+
*
|
|
140
|
+
* @returns Nothing for synchronous targets, or a promise that resolves
|
|
141
|
+
* once every update has landed.
|
|
142
|
+
*/
|
|
143
|
+
flush(): void | Promise<void>;
|
|
144
|
+
}
|
|
1
145
|
/**
|
|
2
146
|
* Incremental markdown rendering pipeline.
|
|
3
147
|
*
|
|
4
148
|
* @remarks
|
|
5
|
-
* A pipeline
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
149
|
+
* A pipeline is a `WritableStream` of markdown text: write unicode string
|
|
150
|
+
* chunks in any sizes and complete blocks render to the target as they
|
|
151
|
+
* arrive. Closing the stream renders the trailing remainder. The pipeline
|
|
152
|
+
* chunks writes into lines itself; writes after close reject with the
|
|
153
|
+
* platform's native closed-stream error, and non-string chunks reject with
|
|
154
|
+
* a `TypeError`. Aborting discards the buffered remainder without
|
|
155
|
+
* rendering it.
|
|
9
156
|
*
|
|
10
157
|
* @public
|
|
11
158
|
*/
|
|
12
|
-
interface MarkdownPipeline {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
flush(): Promise<void>;
|
|
159
|
+
interface MarkdownPipeline<Config = unknown> extends WritableStream<string> {
|
|
160
|
+
/**
|
|
161
|
+
* Reuse this pipeline for another target: subsequent commits go there.
|
|
162
|
+
*
|
|
163
|
+
* @param target - Target receiving future output.
|
|
164
|
+
*/
|
|
165
|
+
setTarget(target: HTMLTarget): void;
|
|
166
|
+
/**
|
|
167
|
+
* Update the renderer config on the fly. Applies to subsequent commits.
|
|
168
|
+
*
|
|
169
|
+
* @param config - Next config.
|
|
170
|
+
*/
|
|
171
|
+
setConfig(config: Config): void;
|
|
27
172
|
}
|
|
28
|
-
|
|
29
173
|
/**
|
|
30
174
|
* Incremental markdown renderer: consumes lines, updates a target.
|
|
31
175
|
*
|
|
32
176
|
* @remarks
|
|
33
|
-
* A renderer
|
|
34
|
-
* to
|
|
35
|
-
*
|
|
36
|
-
* parse state it needs and writes finished output to its target as input
|
|
37
|
-
* completes.
|
|
177
|
+
* A renderer holds whatever parse state it needs and writes finished
|
|
178
|
+
* output to its target as input completes. `Config` is the renderer's own
|
|
179
|
+
* config type (for example `GFMRendererConfig`); there is no shared base.
|
|
38
180
|
*
|
|
39
181
|
* Implement this interface to plug in your own renderer, hand-written or a
|
|
40
|
-
* third-party adapter.
|
|
182
|
+
* third-party adapter. The constructor is yours; the pipeline wires the
|
|
183
|
+
* target through {@link MarkdownRenderer.setTarget}.
|
|
184
|
+
*
|
|
185
|
+
* Sanitization is the renderer's job: the target creates exactly the tags
|
|
186
|
+
* and attributes it is told to, so a renderer that passes untrusted input
|
|
187
|
+
* through (raw HTML, link targets) must filter it before calling the
|
|
188
|
+
* target.
|
|
41
189
|
*
|
|
42
190
|
* @public
|
|
43
191
|
*/
|
|
44
|
-
interface MarkdownRenderer {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
192
|
+
interface MarkdownRenderer<Config> {
|
|
193
|
+
/**
|
|
194
|
+
* Feed one complete line to the renderer.
|
|
195
|
+
*
|
|
196
|
+
* @param line - Next source line, without its line break. The renderer
|
|
197
|
+
* buffers what it needs and writes completed output to its target.
|
|
198
|
+
*/
|
|
199
|
+
writeLine(line: string): void;
|
|
200
|
+
/**
|
|
201
|
+
* Flush buffered partial state to the target and settle it.
|
|
202
|
+
*
|
|
203
|
+
* @returns A promise that resolves once all output has landed in the target.
|
|
204
|
+
*/
|
|
205
|
+
flush(): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Point the renderer at another target. Queued updates stay with the old
|
|
208
|
+
* target; subsequent commits go to the new one.
|
|
209
|
+
*
|
|
210
|
+
* @param target - Target receiving future output.
|
|
211
|
+
*/
|
|
212
|
+
setTarget(target: HTMLTarget): void;
|
|
213
|
+
/**
|
|
214
|
+
* Replace the renderer config. Applies to subsequent commits; output
|
|
215
|
+
* already committed is left alone.
|
|
216
|
+
*
|
|
217
|
+
* @param config - Next config.
|
|
218
|
+
*/
|
|
219
|
+
setConfig(config: Config): void;
|
|
58
220
|
}
|
|
59
|
-
|
|
60
221
|
/**
|
|
61
|
-
* Create a pipeline around any renderer.
|
|
222
|
+
* Create a streaming pipeline around any renderer and target.
|
|
62
223
|
*
|
|
63
224
|
* @remarks
|
|
64
|
-
* The pipeline
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
225
|
+
* The pipeline chunks whatever strings are written into lines and feeds
|
|
226
|
+
* them to the renderer one at a time; the renderer owns its parse state
|
|
227
|
+
* and commits finished output to the target. Closing the stream renders
|
|
228
|
+
* the trailing remainder. Pass a built-in renderer (`GFMRenderer`,
|
|
229
|
+
* `CommonMarkRenderer`) or your own `MarkdownRenderer` implementation,
|
|
230
|
+
* and a DOM target from `createDOMTarget` or your own `HTMLTarget`.
|
|
231
|
+
*
|
|
232
|
+
* @param renderer - Line-consuming renderer holding its own parse state.
|
|
233
|
+
* @param target - Destination the renderer commits to.
|
|
70
234
|
* @returns A working pipeline.
|
|
71
235
|
*
|
|
72
236
|
* @example
|
|
73
237
|
* ```ts
|
|
74
|
-
* const
|
|
75
|
-
*
|
|
76
|
-
* );
|
|
77
|
-
* await
|
|
78
|
-
* await
|
|
238
|
+
* const target = createDOMTarget(document, document.getElementById("out")!);
|
|
239
|
+
* const stream = createMarkdownStream(new GFMRenderer(target, {}), target);
|
|
240
|
+
* const writer = stream.getWriter();
|
|
241
|
+
* await writer.write("# Hello\n");
|
|
242
|
+
* await writer.close();
|
|
243
|
+
* writer.releaseLock();
|
|
79
244
|
* ```
|
|
80
245
|
*
|
|
81
246
|
* @public
|
|
82
247
|
*/
|
|
83
|
-
declare function
|
|
84
|
-
|
|
248
|
+
export declare function createMarkdownStream<Config>(renderer: MarkdownRenderer<Config>, target: HTMLTarget): MarkdownPipeline<Config>;
|
|
85
249
|
/**
|
|
86
250
|
* Minimal subset of the DOM `Node` interface that markemental needs.
|
|
87
251
|
*
|
|
@@ -93,57 +257,57 @@ declare function createMarkdownPipeline(renderer: MarkdownRenderer): MarkdownPip
|
|
|
93
257
|
* @public
|
|
94
258
|
*/
|
|
95
259
|
interface DOMNodeLike {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
260
|
+
/** Numeric node type, mirroring `Node.nodeType`. */
|
|
261
|
+
nodeType: number;
|
|
262
|
+
/** Text content of this node, mirroring `Node.textContent`. */
|
|
263
|
+
textContent: string | null;
|
|
264
|
+
/** Child nodes, mirroring `Node.childNodes`. */
|
|
265
|
+
childNodes: ArrayLike<DOMNodeLike>;
|
|
266
|
+
/** Owning document, or `null` for detached nodes. */
|
|
267
|
+
ownerDocument: DOMDocumentLike | null;
|
|
268
|
+
/**
|
|
269
|
+
* Append a child node.
|
|
270
|
+
*
|
|
271
|
+
* @param node - Node to append.
|
|
272
|
+
* @returns The appended node.
|
|
273
|
+
*/
|
|
274
|
+
appendChild(node: DOMNodeLike): DOMNodeLike;
|
|
275
|
+
/**
|
|
276
|
+
* Insert a node before a reference child.
|
|
277
|
+
*
|
|
278
|
+
* @param newNode - Node to insert.
|
|
279
|
+
* @param referenceNode - Child to insert before, or `null` to append.
|
|
280
|
+
* @returns The inserted node.
|
|
281
|
+
*/
|
|
282
|
+
insertBefore(newNode: DOMNodeLike, referenceNode: DOMNodeLike | null): DOMNodeLike;
|
|
283
|
+
/**
|
|
284
|
+
* Remove a child node.
|
|
285
|
+
*
|
|
286
|
+
* @param child - Child to remove.
|
|
287
|
+
* @returns The removed node.
|
|
288
|
+
*/
|
|
289
|
+
removeChild(child: DOMNodeLike): DOMNodeLike;
|
|
290
|
+
/**
|
|
291
|
+
* Replace a child node.
|
|
292
|
+
*
|
|
293
|
+
* @param newChild - Replacement node.
|
|
294
|
+
* @param oldChild - Child to replace.
|
|
295
|
+
* @returns The replaced node.
|
|
296
|
+
*/
|
|
297
|
+
replaceChild(newChild: DOMNodeLike, oldChild: DOMNodeLike): DOMNodeLike;
|
|
298
|
+
/**
|
|
299
|
+
* Set an attribute on this node, when supported.
|
|
300
|
+
*
|
|
301
|
+
* @param name - Attribute name.
|
|
302
|
+
* @param value - Attribute value.
|
|
303
|
+
*/
|
|
304
|
+
setAttribute?(name: string, value: string): void;
|
|
305
|
+
/**
|
|
306
|
+
* Remove an attribute from this node, when supported.
|
|
307
|
+
*
|
|
308
|
+
* @param name - Attribute name.
|
|
309
|
+
*/
|
|
310
|
+
removeAttribute?(name: string): void;
|
|
147
311
|
}
|
|
148
312
|
/**
|
|
149
313
|
* Minimal subset of the DOM `Document` interface that markemental needs.
|
|
@@ -151,20 +315,20 @@ interface DOMNodeLike {
|
|
|
151
315
|
* @public
|
|
152
316
|
*/
|
|
153
317
|
interface DOMDocumentLike {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
318
|
+
/**
|
|
319
|
+
* Create an element node.
|
|
320
|
+
*
|
|
321
|
+
* @param tagName - Lowercase tag name (for example `"p"`).
|
|
322
|
+
* @returns The new element.
|
|
323
|
+
*/
|
|
324
|
+
createElement(tagName: string): DOMNodeLike;
|
|
325
|
+
/**
|
|
326
|
+
* Create a text node.
|
|
327
|
+
*
|
|
328
|
+
* @param data - Text content.
|
|
329
|
+
* @returns The new text node.
|
|
330
|
+
*/
|
|
331
|
+
createTextNode(data: string): DOMNodeLike;
|
|
168
332
|
}
|
|
169
333
|
/**
|
|
170
334
|
* `requestAnimationFrame` callback scheduler.
|
|
@@ -175,35 +339,6 @@ interface DOMDocumentLike {
|
|
|
175
339
|
* @public
|
|
176
340
|
*/
|
|
177
341
|
type RAF = (callback: (time: number) => void) => number;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Destination for rendered output.
|
|
181
|
-
*
|
|
182
|
-
* @remarks
|
|
183
|
-
* A target receives rendered nodes from a renderer and attaches them to an
|
|
184
|
-
* external DOM: either a real browser document or a simulated one such as
|
|
185
|
-
* linkedom. The caller provides that DOM; the target only decides when
|
|
186
|
-
* attachment happens: immediately, or batched on animation frames for
|
|
187
|
-
* smooth streaming into a live page.
|
|
188
|
-
*
|
|
189
|
-
* @public
|
|
190
|
-
*/
|
|
191
|
-
interface RenderTarget {
|
|
192
|
-
/**
|
|
193
|
-
* Attach a rendered node to the target.
|
|
194
|
-
*
|
|
195
|
-
* @param node - Node to attach. Attachment may be deferred (for example to
|
|
196
|
-
* the next animation frame); use {@link RenderTarget.flush} to wait for it.
|
|
197
|
-
*/
|
|
198
|
-
append(node: DOMNodeLike): void;
|
|
199
|
-
/**
|
|
200
|
-
* Wait for all appended nodes to be attached.
|
|
201
|
-
*
|
|
202
|
-
* @returns A promise that resolves once the target holds every node.
|
|
203
|
-
*/
|
|
204
|
-
flush(): Promise<void>;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
342
|
/**
|
|
208
343
|
* Leaf block constructs recognized by the MVP parser.
|
|
209
344
|
*
|
|
@@ -221,25 +356,24 @@ type BlockKind = "heading" | "paragraph" | "fence" | "quote" | "rule";
|
|
|
221
356
|
* @internal
|
|
222
357
|
*/
|
|
223
358
|
interface Block {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
359
|
+
/** What kind of block this is. */
|
|
360
|
+
kind: BlockKind;
|
|
361
|
+
/**
|
|
362
|
+
* Block content lines. Markers are stripped: `#` prefixes for headings,
|
|
363
|
+
* `>` prefixes for quotes, and fence lines for fenced code. Paragraph
|
|
364
|
+
* lines are raw.
|
|
365
|
+
*/
|
|
366
|
+
lines: string[];
|
|
367
|
+
/** Heading level (1-6) for `"heading"` blocks. */
|
|
368
|
+
level?: number;
|
|
369
|
+
/** Fence info string for `"fence"` blocks, when present. */
|
|
370
|
+
language?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Number of source lines this block was parsed from, used to hold back a
|
|
373
|
+
* trailing partial block across writes.
|
|
374
|
+
*/
|
|
375
|
+
sourceLineCount: number;
|
|
241
376
|
}
|
|
242
|
-
|
|
243
377
|
/**
|
|
244
378
|
* Structural piece of a document emitted as lines are parsed.
|
|
245
379
|
*
|
|
@@ -253,25 +387,25 @@ interface Block {
|
|
|
253
387
|
* @internal
|
|
254
388
|
*/
|
|
255
389
|
type ParseFragment = {
|
|
256
|
-
|
|
257
|
-
|
|
390
|
+
kind: "block";
|
|
391
|
+
block: Block;
|
|
258
392
|
} | {
|
|
259
|
-
|
|
260
|
-
|
|
393
|
+
kind: "listStart";
|
|
394
|
+
ordered: boolean;
|
|
261
395
|
} | {
|
|
262
|
-
|
|
263
|
-
|
|
396
|
+
kind: "listItem";
|
|
397
|
+
text: string;
|
|
264
398
|
} | {
|
|
265
|
-
|
|
399
|
+
kind: "listEnd";
|
|
266
400
|
} | {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
401
|
+
kind: "tableHead";
|
|
402
|
+
headLine: string;
|
|
403
|
+
delimLine: string;
|
|
270
404
|
} | {
|
|
271
|
-
|
|
272
|
-
|
|
405
|
+
kind: "tableRow";
|
|
406
|
+
line: string;
|
|
273
407
|
} | {
|
|
274
|
-
|
|
408
|
+
kind: "tableEnd";
|
|
275
409
|
};
|
|
276
410
|
/**
|
|
277
411
|
* Incremental line-driven parser for CommonMark structure.
|
|
@@ -287,67 +421,67 @@ type ParseFragment = {
|
|
|
287
421
|
* @internal
|
|
288
422
|
*/
|
|
289
423
|
declare class CommonMarkState {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
424
|
+
protected _emit: (fragment: ParseFragment) => void;
|
|
425
|
+
protected _pending: string[];
|
|
426
|
+
private _fence;
|
|
427
|
+
private _quote;
|
|
428
|
+
private _lists;
|
|
429
|
+
/**
|
|
430
|
+
* @param emit - Receives parse fragments in document order.
|
|
431
|
+
*/
|
|
432
|
+
constructor(_emit: (fragment: ParseFragment) => void);
|
|
433
|
+
/**
|
|
434
|
+
* Feed one source line; completed fragments emit to the handler.
|
|
435
|
+
*
|
|
436
|
+
* @param line - Next source line, without its line break.
|
|
437
|
+
*/
|
|
438
|
+
addLine(line: string): void;
|
|
439
|
+
/**
|
|
440
|
+
* Close every open context and emit the trailing remainder.
|
|
441
|
+
*/
|
|
442
|
+
flush(): void;
|
|
443
|
+
/**
|
|
444
|
+
* Feed a line to the open fence, if any.
|
|
445
|
+
*
|
|
446
|
+
* @param line - Next source line.
|
|
447
|
+
* @returns True when the line was consumed.
|
|
448
|
+
*/
|
|
449
|
+
protected _consumeFence(line: string): boolean;
|
|
450
|
+
/**
|
|
451
|
+
* Feed a line to the open lists, if any, closing and reprocessing when
|
|
452
|
+
* the line is not an item.
|
|
453
|
+
*
|
|
454
|
+
* @param line - Next source line.
|
|
455
|
+
* @returns True when the line was consumed or reprocessed.
|
|
456
|
+
*/
|
|
457
|
+
protected _consumeLists(line: string): boolean;
|
|
458
|
+
/**
|
|
459
|
+
* Feed a line to the open quote, if any, dumping it back to pending when
|
|
460
|
+
* the line does not continue the quote.
|
|
461
|
+
*
|
|
462
|
+
* @param line - Next source line.
|
|
463
|
+
* @returns True when the line was consumed.
|
|
464
|
+
*/
|
|
465
|
+
protected _consumeQuote(line: string): boolean;
|
|
466
|
+
/**
|
|
467
|
+
* Classify a line that continues no open context.
|
|
468
|
+
*
|
|
469
|
+
* @param line - Next source line.
|
|
470
|
+
*/
|
|
471
|
+
protected _classify(line: string): void;
|
|
472
|
+
/**
|
|
473
|
+
* Classify a line that matches no CommonMark opener. The base parser has
|
|
474
|
+
* no pipe syntax, so this never consumes; {@link GFMState} overrides it
|
|
475
|
+
* to start table candidates.
|
|
476
|
+
*
|
|
477
|
+
* @param _line - Next source line.
|
|
478
|
+
* @returns Always false here.
|
|
479
|
+
*/
|
|
480
|
+
protected _classifyPipe(_line: string): boolean;
|
|
481
|
+
private _listItem;
|
|
482
|
+
private _closeLists;
|
|
483
|
+
private _takeComplete;
|
|
484
|
+
protected _takeAll(): void;
|
|
351
485
|
}
|
|
352
486
|
/**
|
|
353
487
|
* Incremental line-driven parser for GFM structure.
|
|
@@ -360,154 +494,132 @@ declare class CommonMarkState {
|
|
|
360
494
|
* @internal
|
|
361
495
|
*/
|
|
362
496
|
declare class GFMState extends CommonMarkState {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
497
|
+
private _tableOpen;
|
|
498
|
+
private _candidate;
|
|
499
|
+
/**
|
|
500
|
+
* Feed one source line; completed fragments emit to the handler.
|
|
501
|
+
*
|
|
502
|
+
* @param line - Next source line, without its line break.
|
|
503
|
+
*/
|
|
504
|
+
addLine(line: string): void;
|
|
505
|
+
/**
|
|
506
|
+
* Close every open context and emit the trailing remainder.
|
|
507
|
+
*/
|
|
508
|
+
flush(): void;
|
|
509
|
+
/**
|
|
510
|
+
* Feed a line to the open table, if any, closing and reprocessing when
|
|
511
|
+
* the line is not a row.
|
|
512
|
+
*
|
|
513
|
+
* @param line - Next source line.
|
|
514
|
+
* @returns True when the line was consumed or reprocessed.
|
|
515
|
+
*/
|
|
516
|
+
private _consumeTable;
|
|
517
|
+
/**
|
|
518
|
+
* Resolve a pending table header candidate against the next line.
|
|
519
|
+
*
|
|
520
|
+
* @param line - Next source line.
|
|
521
|
+
* @returns True when a table opened.
|
|
522
|
+
*/
|
|
523
|
+
private _consumeCandidate;
|
|
524
|
+
/**
|
|
525
|
+
* Start a table header candidate on pipe lines.
|
|
526
|
+
*
|
|
527
|
+
* @param line - Next source line.
|
|
528
|
+
* @returns True when the line starts a candidate.
|
|
529
|
+
*/
|
|
530
|
+
protected _classifyPipe(line: string): boolean;
|
|
397
531
|
}
|
|
398
|
-
|
|
399
532
|
/**
|
|
400
533
|
* Renderer for CommonMark.
|
|
401
534
|
*
|
|
402
535
|
* @remarks
|
|
403
|
-
* Constructed with its target
|
|
536
|
+
* Constructed with its target and config. Feed it lines with
|
|
404
537
|
* {@link CommonMarkRenderer.writeLine}; it holds its own parse state and
|
|
405
|
-
* writes finished blocks to the target as they complete.
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
538
|
+
* writes finished blocks to the target as they complete. Open lists are
|
|
539
|
+
* tracked on a stack so items — including nested ones — append to the
|
|
540
|
+
* right container as they arrive.
|
|
541
|
+
*
|
|
542
|
+
* The renderer never touches the DOM: it builds everything through the
|
|
543
|
+
* write-only target, so the same renderer drives live pages, simulated
|
|
544
|
+
* DOMs, and fully custom targets.
|
|
409
545
|
*
|
|
410
546
|
* @public
|
|
411
547
|
*/
|
|
412
|
-
declare class CommonMarkRenderer implements MarkdownRenderer {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
*/
|
|
478
|
-
protected renderParagraph(lines: string[], doc: DOMDocumentLike): DOMNodeLike;
|
|
479
|
-
private appendLinesInline;
|
|
548
|
+
export declare class CommonMarkRenderer implements MarkdownRenderer<CommonMarkRendererConfig> {
|
|
549
|
+
protected _target: HTMLTarget;
|
|
550
|
+
private _config;
|
|
551
|
+
private _state;
|
|
552
|
+
private _open;
|
|
553
|
+
/**
|
|
554
|
+
* @param target - Destination for rendered output, from `createDOMTarget`
|
|
555
|
+
* or a custom `HTMLTarget` implementation.
|
|
556
|
+
* @param config - CommonMark rendering config.
|
|
557
|
+
*/
|
|
558
|
+
constructor(target: HTMLTarget, config: CommonMarkRendererConfig);
|
|
559
|
+
/**
|
|
560
|
+
* Feed one source line; completed output is written to the target.
|
|
561
|
+
*
|
|
562
|
+
* @param line - Next source line, without its line break.
|
|
563
|
+
*/
|
|
564
|
+
writeLine(line: string): void;
|
|
565
|
+
/**
|
|
566
|
+
* Write the buffered remainder and settle the target.
|
|
567
|
+
*
|
|
568
|
+
* @returns A promise that resolves once all output has landed in the target.
|
|
569
|
+
*/
|
|
570
|
+
flush(): Promise<void>;
|
|
571
|
+
/**
|
|
572
|
+
* Point the renderer at another target; subsequent writes go there.
|
|
573
|
+
*
|
|
574
|
+
* @param target - Target receiving future output.
|
|
575
|
+
*/
|
|
576
|
+
setTarget(target: HTMLTarget): void;
|
|
577
|
+
/**
|
|
578
|
+
* Replace the renderer config; applies to subsequent writes.
|
|
579
|
+
*
|
|
580
|
+
* @param config - Next config.
|
|
581
|
+
*/
|
|
582
|
+
setConfig(config: CommonMarkRendererConfig): void;
|
|
583
|
+
/**
|
|
584
|
+
* Create the parser state. Overridden by `GFMRenderer` to parse
|
|
585
|
+
* tables.
|
|
586
|
+
*
|
|
587
|
+
* @param emit - Receives parse fragments in document order.
|
|
588
|
+
* @returns The state for this renderer.
|
|
589
|
+
*/
|
|
590
|
+
protected _createState(emit: (fragment: ParseFragment) => void): CommonMarkState;
|
|
591
|
+
protected _applyFragment(fragment: ParseFragment): void;
|
|
592
|
+
/**
|
|
593
|
+
* Whether GFM-only inlines are enabled. Always false here; overridden by
|
|
594
|
+
* `GFMRenderer`.
|
|
595
|
+
*
|
|
596
|
+
* @returns False.
|
|
597
|
+
*/
|
|
598
|
+
protected inlineGfm(): boolean;
|
|
599
|
+
/**
|
|
600
|
+
* Write one parsed block to the target.
|
|
601
|
+
*
|
|
602
|
+
* @param block - Parsed block to write.
|
|
603
|
+
*/
|
|
604
|
+
protected renderBlock(block: Block): void;
|
|
605
|
+
/**
|
|
606
|
+
* Write paragraph lines into a parent, honoring two-space hard breaks.
|
|
607
|
+
*
|
|
608
|
+
* @param parentId - Node the lines append to.
|
|
609
|
+
* @param lines - Raw paragraph lines.
|
|
610
|
+
*/
|
|
611
|
+
protected appendParagraphLines(parentId: NodeId, lines: string[]): void;
|
|
612
|
+
private appendJoinedLines;
|
|
480
613
|
}
|
|
481
614
|
/**
|
|
482
|
-
*
|
|
615
|
+
* Config for {@link CommonMarkRenderer}.
|
|
483
616
|
*
|
|
484
617
|
* @remarks
|
|
485
|
-
*
|
|
486
|
-
* piece by piece (container first, then rows and items).
|
|
487
|
-
*
|
|
488
|
-
* @param node - Node being committed.
|
|
489
|
-
* @returns The node to append to the target.
|
|
490
|
-
*
|
|
491
|
-
* @public
|
|
492
|
-
*/
|
|
493
|
-
type BlockSanitizer = (node: DOMNodeLike) => DOMNodeLike;
|
|
494
|
-
/**
|
|
495
|
-
* Options for {@link CommonMarkRenderer}.
|
|
618
|
+
* Reserved for future renderer options.
|
|
496
619
|
*
|
|
497
620
|
* @public
|
|
498
621
|
*/
|
|
499
|
-
type
|
|
500
|
-
/**
|
|
501
|
-
* Optional post-render sanitizer applied to every node committed to the
|
|
502
|
-
* target.
|
|
503
|
-
*
|
|
504
|
-
* @remarks
|
|
505
|
-
* Intended for HTML safety once raw HTML detection and parsing lands
|
|
506
|
-
* (see the TODO in `parser/inline`).
|
|
507
|
-
*/
|
|
508
|
-
sanitizer?: BlockSanitizer;
|
|
509
|
-
};
|
|
510
|
-
|
|
622
|
+
type CommonMarkRendererConfig = Record<string, never>;
|
|
511
623
|
/**
|
|
512
624
|
* Renderer for GitHub Flavored Markdown.
|
|
513
625
|
*
|
|
@@ -519,190 +631,141 @@ type CommonMarkRenderOptions = {
|
|
|
519
631
|
*
|
|
520
632
|
* @public
|
|
521
633
|
*/
|
|
522
|
-
declare class GFMRenderer extends CommonMarkRenderer implements MarkdownRenderer {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* Close the open table.
|
|
568
|
-
*/
|
|
569
|
-
protected _applyTableEnd(): void;
|
|
634
|
+
export declare class GFMRenderer extends CommonMarkRenderer implements MarkdownRenderer<GFMRendererConfig> {
|
|
635
|
+
private _table;
|
|
636
|
+
/**
|
|
637
|
+
* @param target - Destination for rendered output, from `createDOMTarget`
|
|
638
|
+
* or a custom `HTMLTarget` implementation.
|
|
639
|
+
* @param config - GFM rendering config.
|
|
640
|
+
*/
|
|
641
|
+
constructor(target: HTMLTarget, config: GFMRendererConfig);
|
|
642
|
+
/**
|
|
643
|
+
* GFM-only inlines are enabled.
|
|
644
|
+
*
|
|
645
|
+
* @returns True.
|
|
646
|
+
*/
|
|
647
|
+
protected inlineGfm(): boolean;
|
|
648
|
+
/**
|
|
649
|
+
* Create the GFM parser state.
|
|
650
|
+
*
|
|
651
|
+
* @param emit - Receives parse fragments in document order.
|
|
652
|
+
* @returns The state for this renderer.
|
|
653
|
+
*/
|
|
654
|
+
protected _createState(emit: (fragment: ParseFragment) => void): GFMState;
|
|
655
|
+
/**
|
|
656
|
+
* Apply a fragment, handling tables here and delegating the rest.
|
|
657
|
+
*
|
|
658
|
+
* @param fragment - Fragment to apply.
|
|
659
|
+
*/
|
|
660
|
+
protected _applyFragment(fragment: ParseFragment): void;
|
|
661
|
+
/**
|
|
662
|
+
* Commit the table with its header; body rows stream in afterwards.
|
|
663
|
+
*
|
|
664
|
+
* @param headLine - Raw header row line.
|
|
665
|
+
* @param delimLine - Delimiter row line carrying column alignment.
|
|
666
|
+
*/
|
|
667
|
+
protected _applyTableHead(headLine: string, delimLine: string): void;
|
|
668
|
+
/**
|
|
669
|
+
* Append one body row to the open table.
|
|
670
|
+
*
|
|
671
|
+
* @param line - Raw body row line.
|
|
672
|
+
*/
|
|
673
|
+
protected _applyTableRow(line: string): void;
|
|
674
|
+
/**
|
|
675
|
+
* Close the open table.
|
|
676
|
+
*/
|
|
677
|
+
protected _applyTableEnd(): void;
|
|
570
678
|
}
|
|
571
679
|
/**
|
|
572
|
-
*
|
|
680
|
+
* Config for {@link GFMRenderer}.
|
|
681
|
+
*
|
|
682
|
+
* @public
|
|
683
|
+
*/
|
|
684
|
+
type GFMRendererConfig = CommonMarkRendererConfig;
|
|
685
|
+
/**
|
|
686
|
+
* Options for {@link createDOMTarget}.
|
|
687
|
+
*
|
|
688
|
+
* @public
|
|
689
|
+
*/
|
|
690
|
+
type DOMTargetOptions = {
|
|
691
|
+
/**
|
|
692
|
+
* Optional frame scheduler. When provided, writes are batched on
|
|
693
|
+
* animation frames; otherwise updates apply synchronously.
|
|
694
|
+
*/
|
|
695
|
+
raf?: RAF;
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* Create a target rendering into a DOM container.
|
|
699
|
+
*
|
|
700
|
+
* @param document - Document used to create nodes: a real browser document
|
|
701
|
+
* for live pages, or a simulated one such as linkedom for server-side
|
|
702
|
+
* rendering.
|
|
703
|
+
* @param targetNode - Container node receiving rendered output.
|
|
704
|
+
* @param options - Frame scheduler.
|
|
705
|
+
* @returns The target to hand to a renderer.
|
|
573
706
|
*
|
|
574
707
|
* @public
|
|
575
708
|
*/
|
|
576
|
-
|
|
577
|
-
|
|
709
|
+
export declare function createDOMTarget(document: DOMDocumentLike, targetNode: DOMNodeLike, options?: DOMTargetOptions): HTMLTarget;
|
|
578
710
|
/**
|
|
579
|
-
* Create a GFM
|
|
711
|
+
* Create a GFM stream rendering into the given container.
|
|
580
712
|
*
|
|
581
713
|
* @remarks
|
|
582
714
|
* The environment is implicit: pass a real browser document for live pages
|
|
583
|
-
* or a simulated one such as linkedom for server-side rendering. Pass
|
|
584
|
-
*
|
|
715
|
+
* or a simulated one such as linkedom for server-side rendering. Pass
|
|
716
|
+
* target options to batch DOM writes on animation frames.
|
|
585
717
|
*
|
|
586
718
|
* @param target - Container node receiving rendered output.
|
|
587
719
|
* @param dom - Document used to create nodes.
|
|
588
|
-
* @param
|
|
589
|
-
* @param
|
|
590
|
-
* batched on animation frames for smooth streaming.
|
|
720
|
+
* @param config - GFM rendering config.
|
|
721
|
+
* @param targetOptions - Frame scheduler for the DOM target.
|
|
591
722
|
* @returns The configured pipeline.
|
|
592
723
|
*
|
|
593
724
|
* @example
|
|
594
725
|
* ```ts
|
|
595
|
-
* const
|
|
596
|
-
* document.getElementById("out")
|
|
726
|
+
* const stream = createGFMStream(
|
|
727
|
+
* document.getElementById("out")!,
|
|
597
728
|
* document,
|
|
598
729
|
* {},
|
|
599
|
-
* requestAnimationFrame,
|
|
730
|
+
* { raf: requestAnimationFrame },
|
|
600
731
|
* );
|
|
601
|
-
*
|
|
602
|
-
* await
|
|
732
|
+
* const writer = stream.getWriter();
|
|
733
|
+
* await writer.write("# Hello\n");
|
|
734
|
+
* await writer.close();
|
|
603
735
|
* ```
|
|
604
736
|
*
|
|
605
737
|
* @public
|
|
606
738
|
*/
|
|
607
|
-
declare function
|
|
608
|
-
/**
|
|
609
|
-
* Incremental GFM pipeline.
|
|
610
|
-
*
|
|
611
|
-
* @public
|
|
612
|
-
*/
|
|
613
|
-
declare class GFMPipeline implements MarkdownPipeline {
|
|
614
|
-
private _engine;
|
|
615
|
-
/**
|
|
616
|
-
* @param target - Container node receiving rendered output.
|
|
617
|
-
* @param dom - Document used to create nodes.
|
|
618
|
-
* @param opts - GFM rendering options.
|
|
619
|
-
* @param raf - Optional frame scheduler for batched DOM writes.
|
|
620
|
-
*/
|
|
621
|
-
constructor(target: DOMNodeLike, dom: DOMDocumentLike, opts: GFMRenderOptions, raf?: RAF);
|
|
622
|
-
/**
|
|
623
|
-
* Push a chunk of markdown into the pipeline.
|
|
624
|
-
*
|
|
625
|
-
* @param chunk - Markdown text, or a promise resolving to markdown text.
|
|
626
|
-
* @returns A promise that resolves once the chunk has been consumed.
|
|
627
|
-
*/
|
|
628
|
-
push(chunk: string | Promise<string>): Promise<void>;
|
|
629
|
-
/**
|
|
630
|
-
* Render any buffered remainder.
|
|
631
|
-
*
|
|
632
|
-
* @returns A promise that resolves once all output has been flushed.
|
|
633
|
-
*/
|
|
634
|
-
flush(): Promise<void>;
|
|
635
|
-
}
|
|
636
|
-
|
|
739
|
+
export declare function createGFMStream(target: DOMNodeLike, dom: DOMDocumentLike, config: GFMRendererConfig, targetOptions?: DOMTargetOptions): MarkdownPipeline<GFMRendererConfig>;
|
|
637
740
|
/**
|
|
638
|
-
* Create a CommonMark
|
|
741
|
+
* Create a CommonMark stream rendering into the given container.
|
|
639
742
|
*
|
|
640
743
|
* @remarks
|
|
641
744
|
* The environment is implicit: pass a real browser document for live pages
|
|
642
|
-
* or a simulated one such as linkedom for server-side rendering. Pass
|
|
643
|
-
*
|
|
745
|
+
* or a simulated one such as linkedom for server-side rendering. Pass
|
|
746
|
+
* target options to batch DOM writes on animation frames.
|
|
644
747
|
*
|
|
645
748
|
* @param target - Container node receiving rendered output.
|
|
646
749
|
* @param dom - Document used to create nodes.
|
|
647
|
-
* @param
|
|
648
|
-
* @param
|
|
649
|
-
* batched on animation frames for smooth streaming.
|
|
750
|
+
* @param config - CommonMark rendering config.
|
|
751
|
+
* @param targetOptions - Frame scheduler for the DOM target.
|
|
650
752
|
* @returns The configured pipeline.
|
|
651
753
|
*
|
|
652
754
|
* @example
|
|
653
755
|
* ```ts
|
|
654
|
-
* const
|
|
655
|
-
* document.getElementById("out")
|
|
756
|
+
* const stream = createCommonMarkStream(
|
|
757
|
+
* document.getElementById("out")!,
|
|
656
758
|
* document,
|
|
657
759
|
* {},
|
|
658
|
-
* requestAnimationFrame,
|
|
760
|
+
* { raf: requestAnimationFrame },
|
|
659
761
|
* );
|
|
660
|
-
*
|
|
661
|
-
* await
|
|
762
|
+
* const writer = stream.getWriter();
|
|
763
|
+
* await writer.write("# Hello\n");
|
|
764
|
+
* await writer.close();
|
|
662
765
|
* ```
|
|
663
766
|
*
|
|
664
767
|
* @public
|
|
665
768
|
*/
|
|
666
|
-
declare function
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
*
|
|
670
|
-
* @public
|
|
671
|
-
*/
|
|
672
|
-
declare class CommonMarkPipeline implements MarkdownPipeline {
|
|
673
|
-
private _engine;
|
|
674
|
-
/**
|
|
675
|
-
* @param target - Container node receiving rendered output.
|
|
676
|
-
* @param dom - Document used to create nodes.
|
|
677
|
-
* @param opts - CommonMark rendering options.
|
|
678
|
-
* @param raf - Optional frame scheduler for batched DOM writes.
|
|
679
|
-
*/
|
|
680
|
-
constructor(target: DOMNodeLike, dom: DOMDocumentLike, opts: CommonMarkRenderOptions, raf?: RAF);
|
|
681
|
-
/**
|
|
682
|
-
* Push a chunk of markdown into the pipeline.
|
|
683
|
-
*
|
|
684
|
-
* @param chunk - Markdown text, or a promise resolving to markdown text.
|
|
685
|
-
* @returns A promise that resolves once the chunk has been consumed.
|
|
686
|
-
*/
|
|
687
|
-
push(chunk: string | Promise<string>): Promise<void>;
|
|
688
|
-
/**
|
|
689
|
-
* Render any buffered remainder.
|
|
690
|
-
*
|
|
691
|
-
* @returns A promise that resolves once all output has been flushed.
|
|
692
|
-
*/
|
|
693
|
-
flush(): Promise<void>;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* Create the render target for a container node.
|
|
698
|
-
*
|
|
699
|
-
* @param targetNode - Container node receiving rendered output.
|
|
700
|
-
* @param raf - Optional frame scheduler. When provided, writes are batched
|
|
701
|
-
* on animation frames; otherwise nodes are attached synchronously.
|
|
702
|
-
* @returns The target to hand to a renderer.
|
|
703
|
-
*
|
|
704
|
-
* @public
|
|
705
|
-
*/
|
|
706
|
-
declare function createRenderTarget(targetNode: DOMNodeLike, raf?: RAF): RenderTarget;
|
|
707
|
-
|
|
708
|
-
export { type BlockSanitizer, CommonMarkPipeline, type CommonMarkRenderOptions, CommonMarkRenderer, type DOMDocumentLike, type DOMNodeLike, GFMPipeline, type GFMRenderOptions, GFMRenderer, type MarkdownPipeline, type MarkdownRenderer, type RAF, type RenderTarget, createCommonMarkPipeline, createGFMPipeline, createMarkdownPipeline, createRenderTarget };
|
|
769
|
+
export declare function createCommonMarkStream(target: DOMNodeLike, dom: DOMDocumentLike, config: CommonMarkRendererConfig, targetOptions?: DOMTargetOptions): MarkdownPipeline<CommonMarkRendererConfig>;
|
|
770
|
+
export type { CommonMarkRendererConfig, DOMDocumentLike, DOMNodeLike, DOMTargetOptions, GFMRendererConfig, HTMLTarget, MarkdownPipeline, MarkdownRenderer, NodeId, RAF };
|
|
771
|
+
//# sourceMappingURL=index.d.cts.map
|