markemental 0.3.0 → 0.5.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 +96 -28
- package/dist/index.cjs +1785 -985
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +579 -580
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +579 -580
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1773 -977
- package/dist/index.js.map +1 -1
- package/package.json +16 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,708 +1,707 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Incremental markdown
|
|
2
|
+
* Incremental modular markdown renderer.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* This barrel is the entire public API. Layout convention: `api/<name>.ts`
|
|
6
|
+
* holds one main contract (`api/target.ts` is the `HTMLTarget` contract,
|
|
7
|
+
* `api/renderer.ts` the `MarkdownRenderer` one, `api/stream.ts` the
|
|
8
|
+
* `MarkdownStream` one), while the plural directories hold what implements
|
|
9
|
+
* or composes them. Public modules sit at the top of each directory;
|
|
10
|
+
* private ones live in `internal/` and are never exported here.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
11
13
|
*/
|
|
12
|
-
interface MarkdownPipeline {
|
|
13
|
-
/**
|
|
14
|
-
* Push a chunk of markdown into the pipeline.
|
|
15
|
-
*
|
|
16
|
-
* @param chunk - Markdown text, or a promise resolving to markdown text.
|
|
17
|
-
* @returns A promise that resolves once the chunk has been consumed and any
|
|
18
|
-
* complete blocks have been rendered to the target.
|
|
19
|
-
*/
|
|
20
|
-
push(chunk: string | Promise<string>): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Render any buffered remainder and release pipeline resources.
|
|
23
|
-
*
|
|
24
|
-
* @returns A promise that resolves once all output has been flushed.
|
|
25
|
-
*/
|
|
26
|
-
flush(): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
14
|
/**
|
|
30
|
-
*
|
|
15
|
+
* Opaque handle for a node held by a target.
|
|
31
16
|
*
|
|
32
17
|
* @remarks
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* pipeline feeds it one complete line at a time; the renderer holds whatever
|
|
36
|
-
* parse state it needs and writes finished output to its target as input
|
|
37
|
-
* completes.
|
|
18
|
+
* Minted by creation calls; never construct one by hand. Consult the
|
|
19
|
+
* full documentation for more details.
|
|
38
20
|
*
|
|
39
|
-
*
|
|
40
|
-
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
type NodeId = string;
|
|
24
|
+
/**
|
|
25
|
+
* A target call referenced an id the target never minted or already
|
|
26
|
+
* retired. Carries the offending id.
|
|
41
27
|
*
|
|
42
28
|
* @public
|
|
43
29
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
writeLine(line: string): void;
|
|
52
|
-
/**
|
|
53
|
-
* Flush buffered partial state to the target and settle it.
|
|
54
|
-
*
|
|
55
|
-
* @returns A promise that resolves once all output has landed in the target.
|
|
56
|
-
*/
|
|
57
|
-
flush(): Promise<void>;
|
|
30
|
+
export declare class UnknownNodeError extends Error {
|
|
31
|
+
/** The unknown id. */
|
|
32
|
+
readonly nodeId: string;
|
|
33
|
+
/**
|
|
34
|
+
* @param nodeId - The unknown id.
|
|
35
|
+
*/
|
|
36
|
+
constructor(nodeId: string);
|
|
58
37
|
}
|
|
59
|
-
|
|
60
38
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* @remarks
|
|
64
|
-
* The pipeline feeds the renderer one line at a time from whatever chunks
|
|
65
|
-
* are pushed; the renderer owns its target, document, and parse state. Pass
|
|
66
|
-
* a built-in renderer (`GFMRenderer`, `CommonMarkRenderer`) or your own
|
|
67
|
-
* `MarkdownRenderer` implementation.
|
|
39
|
+
* A replace targeted a node that was never attached. Carries the
|
|
40
|
+
* detached id.
|
|
68
41
|
*
|
|
69
|
-
* @
|
|
70
|
-
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare class DetachedNodeError extends Error {
|
|
45
|
+
/** The detached id. */
|
|
46
|
+
readonly nodeId: string;
|
|
47
|
+
/**
|
|
48
|
+
* @param nodeId - The detached id.
|
|
49
|
+
*/
|
|
50
|
+
constructor(nodeId: string);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* An attach would have built a cycle: the node is an ancestor of the
|
|
54
|
+
* parent. Carries both ids.
|
|
71
55
|
*
|
|
72
|
-
* @
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare class HierarchyError extends Error {
|
|
59
|
+
/** The node being attached. */
|
|
60
|
+
readonly nodeId: string;
|
|
61
|
+
/** The parent it was attached to. */
|
|
62
|
+
readonly parentId: string;
|
|
63
|
+
/**
|
|
64
|
+
* @param nodeId - The node being attached.
|
|
65
|
+
* @param parentId - The parent it was attached to.
|
|
66
|
+
*/
|
|
67
|
+
constructor(nodeId: string, parentId: string);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* An element was created with attributes, but the underlying DOM does not
|
|
71
|
+
* implement `setAttribute`. Carries the tag and the rejected attribute
|
|
72
|
+
* names.
|
|
80
73
|
*
|
|
81
74
|
* @public
|
|
82
75
|
*/
|
|
83
|
-
declare
|
|
84
|
-
|
|
76
|
+
export declare class UnsupportedAttributesError extends Error {
|
|
77
|
+
/** Tag the attributes were requested on. */
|
|
78
|
+
readonly tag: string;
|
|
79
|
+
/** Names of the rejected attributes. */
|
|
80
|
+
readonly attributes: string[];
|
|
81
|
+
/**
|
|
82
|
+
* @param tag - Tag the attributes were requested on.
|
|
83
|
+
* @param attrs - Rejected attributes.
|
|
84
|
+
*/
|
|
85
|
+
constructor(tag: string, attrs: Record<string, string>);
|
|
86
|
+
}
|
|
85
87
|
/**
|
|
86
|
-
*
|
|
88
|
+
* Write-only destination for rendered output.
|
|
87
89
|
*
|
|
88
90
|
* @remarks
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
91
|
+
* An HTML-like target: renderers build nodes through these methods without
|
|
92
|
+
* ever touching a DOM. Custom targets (collectors, serializers, remote
|
|
93
|
+
* renderers) implement this same interface. Consult the full
|
|
94
|
+
* documentation for more details.
|
|
92
95
|
*
|
|
93
96
|
* @public
|
|
94
97
|
*/
|
|
95
|
-
interface
|
|
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
|
-
|
|
98
|
+
interface HTMLTarget {
|
|
99
|
+
/**
|
|
100
|
+
* Create a detached element node with attributes.
|
|
101
|
+
*
|
|
102
|
+
* @param tag - Lowercase tag name (for example `"p"`).
|
|
103
|
+
* @param attrs - Attributes to set. Fixed at creation: replace the node
|
|
104
|
+
* to change them.
|
|
105
|
+
* @returns Id addressing the new node.
|
|
106
|
+
* @throws {@link UnsupportedAttributesError} when attrs is non-empty
|
|
107
|
+
* and the DOM cannot set attributes: synchronously, or when the frame
|
|
108
|
+
* runs for batched targets.
|
|
109
|
+
*/
|
|
110
|
+
createElement(tag: string, attrs?: Record<string, string>): NodeId;
|
|
111
|
+
/**
|
|
112
|
+
* Create a detached text node.
|
|
113
|
+
*
|
|
114
|
+
* @param text - Text content.
|
|
115
|
+
* @returns Id addressing the new node.
|
|
116
|
+
*/
|
|
117
|
+
createTextNode(text: string): NodeId;
|
|
118
|
+
/**
|
|
119
|
+
* Append a child to a parent, or to the top level for a `null` parent.
|
|
120
|
+
* Appending an attached node moves it.
|
|
121
|
+
*
|
|
122
|
+
* @param parent - Receiving node, or `null` for the top level.
|
|
123
|
+
* @param child - Node to append.
|
|
124
|
+
* @throws {@link UnknownNodeError} for unknown ids.
|
|
125
|
+
* @throws {@link HierarchyError} when the child is an ancestor of the parent.
|
|
126
|
+
*/
|
|
127
|
+
appendChild(parent: NodeId | null, child: NodeId): void;
|
|
128
|
+
/**
|
|
129
|
+
* Replace an attached node with another node, which takes its position.
|
|
130
|
+
* The old id is retired. Replacing a detached node throws; replacing a
|
|
131
|
+
* node with itself is a no-op.
|
|
132
|
+
*
|
|
133
|
+
* @param oldId - Attached node to replace.
|
|
134
|
+
* @param newId - Replacement node.
|
|
135
|
+
* @throws {@link UnknownNodeError} for unknown ids.
|
|
136
|
+
* @throws {@link DetachedNodeError} when the old node was never attached.
|
|
137
|
+
* @throws {@link HierarchyError} when the new node is an ancestor of the position.
|
|
138
|
+
*/
|
|
139
|
+
replaceNode(oldId: NodeId, newId: NodeId): void;
|
|
140
|
+
/**
|
|
141
|
+
* Detach a node and retire its id.
|
|
142
|
+
*
|
|
143
|
+
* @param id - Node to remove.
|
|
144
|
+
* @throws {@link UnknownNodeError} for unknown ids.
|
|
145
|
+
*/
|
|
146
|
+
remove(id: NodeId): void;
|
|
147
|
+
/**
|
|
148
|
+
* Replace a node's children with a single text run, retiring the
|
|
149
|
+
* children's ids. On a text node, replaces its content.
|
|
150
|
+
*
|
|
151
|
+
* @param node - Node to update.
|
|
152
|
+
* @param text - Replacement text.
|
|
153
|
+
* @throws {@link UnknownNodeError} for unknown ids.
|
|
154
|
+
*/
|
|
155
|
+
setTextContent(node: NodeId, text: string): void;
|
|
156
|
+
/**
|
|
157
|
+
* Wait for all committed updates to land.
|
|
158
|
+
*
|
|
159
|
+
* @returns Nothing for synchronous targets, or a promise that resolves
|
|
160
|
+
* once every update has landed.
|
|
161
|
+
*/
|
|
162
|
+
flush(): void | Promise<void>;
|
|
147
163
|
}
|
|
148
164
|
/**
|
|
149
|
-
*
|
|
165
|
+
* Incremental markdown renderer: consumes lines, updates a target.
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* Implement this interface to plug in your own renderer, hand-written or a
|
|
169
|
+
* third-party adapter. The constructor is yours; hand the instance to
|
|
170
|
+
* {@link MarkdownStream}, which feeds it lines. Consult the full
|
|
171
|
+
* documentation for more details.
|
|
150
172
|
*
|
|
151
173
|
* @public
|
|
152
174
|
*/
|
|
153
|
-
interface
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
175
|
+
interface MarkdownRenderer<Config> {
|
|
176
|
+
/**
|
|
177
|
+
* Target receiving committed output.
|
|
178
|
+
*/
|
|
179
|
+
readonly target: HTMLTarget;
|
|
180
|
+
/**
|
|
181
|
+
* Config applying to subsequent commits.
|
|
182
|
+
*/
|
|
183
|
+
readonly config: Config;
|
|
184
|
+
/**
|
|
185
|
+
* Feed one complete line to the renderer.
|
|
186
|
+
*
|
|
187
|
+
* @param line - Next source line, without its line break. The renderer
|
|
188
|
+
* buffers what it needs and writes completed output to its target.
|
|
189
|
+
*/
|
|
190
|
+
writeLine(line: string): void;
|
|
191
|
+
/**
|
|
192
|
+
* Flush buffered partial state to the target and settle it.
|
|
193
|
+
*
|
|
194
|
+
* @returns A promise that resolves once all output has landed in the target.
|
|
195
|
+
*/
|
|
196
|
+
flush(): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Point the renderer at another target. Queued updates stay with the old
|
|
199
|
+
* target; subsequent commits go to the new one. Constructs already open
|
|
200
|
+
* (lists, tables) drain into the old target — the only split that keeps
|
|
201
|
+
* document structure intact — and only newly opened blocks bind the new
|
|
202
|
+
* one.
|
|
203
|
+
*
|
|
204
|
+
* @param target - Target receiving future output.
|
|
205
|
+
*/
|
|
206
|
+
setTarget(target: HTMLTarget): void;
|
|
207
|
+
/**
|
|
208
|
+
* Replace the renderer config. Applies to subsequent commits; output
|
|
209
|
+
* already committed is left alone.
|
|
210
|
+
*
|
|
211
|
+
* @param config - Next config.
|
|
212
|
+
*/
|
|
213
|
+
setConfig(config: Config): void;
|
|
168
214
|
}
|
|
169
215
|
/**
|
|
170
|
-
* `
|
|
171
|
-
*
|
|
172
|
-
* @param callback - Invoked with the frame timestamp.
|
|
173
|
-
* @returns A handle identifying the scheduled frame.
|
|
216
|
+
* `setTarget` or `setConfig` was called on a closed or aborted stream.
|
|
217
|
+
* Carries the rejected action.
|
|
174
218
|
*
|
|
175
219
|
* @public
|
|
176
220
|
*/
|
|
177
|
-
|
|
178
|
-
|
|
221
|
+
export declare class ClosedStreamError extends Error {
|
|
222
|
+
/** Action that was rejected. */
|
|
223
|
+
readonly action: "setTarget" | "setConfig";
|
|
224
|
+
/**
|
|
225
|
+
* @param action - Action that was rejected.
|
|
226
|
+
*/
|
|
227
|
+
constructor(action: "setTarget" | "setConfig");
|
|
228
|
+
}
|
|
179
229
|
/**
|
|
180
|
-
*
|
|
230
|
+
* Incremental markdown stream: a `WritableStream` of markdown text.
|
|
181
231
|
*
|
|
182
232
|
* @remarks
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
233
|
+
* Write unicode string chunks in any sizes; the stream splits them into
|
|
234
|
+
* lines itself and feeds them to its renderer one at a time, and complete
|
|
235
|
+
* blocks render to the target as they arrive. Consult the full
|
|
236
|
+
* documentation for more details.
|
|
237
|
+
*
|
|
238
|
+
* Pass a built-in renderer (`GFMRenderer`, `CommonMarkRenderer`) or your
|
|
239
|
+
* own `MarkdownRenderer` implementation, already pointed at a DOM target
|
|
240
|
+
* from `createDOMTarget` or a custom `HTMLTarget`.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* const target = createDOMTarget({ document, container: document.getElementById("out")! });
|
|
245
|
+
* const stream = new MarkdownStream(new GFMRenderer(target));
|
|
246
|
+
* const writer = stream.getWriter();
|
|
247
|
+
* await writer.write("# Hello\n");
|
|
248
|
+
* await writer.close();
|
|
249
|
+
* writer.releaseLock();
|
|
250
|
+
* ```
|
|
188
251
|
*
|
|
189
252
|
* @public
|
|
190
253
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
254
|
+
export declare class MarkdownStream<Config> extends WritableStream<string> {
|
|
255
|
+
private _renderer;
|
|
256
|
+
private _settled;
|
|
257
|
+
/**
|
|
258
|
+
* @param renderer - Line-consuming renderer holding its own target and
|
|
259
|
+
* parse state.
|
|
260
|
+
*/
|
|
261
|
+
constructor(renderer: MarkdownRenderer<Config>);
|
|
262
|
+
/**
|
|
263
|
+
* Renderer this stream feeds lines to.
|
|
264
|
+
*/
|
|
265
|
+
get renderer(): MarkdownRenderer<Config>;
|
|
266
|
+
/**
|
|
267
|
+
* Target the renderer commits to.
|
|
268
|
+
*/
|
|
269
|
+
get target(): HTMLTarget;
|
|
270
|
+
/**
|
|
271
|
+
* Retarget this stream for another target: subsequent commits go there.
|
|
272
|
+
*
|
|
273
|
+
* @param target - Target receiving future output.
|
|
274
|
+
* @throws {@link ClosedStreamError} when the stream is closed or
|
|
275
|
+
* aborted: mutating a dead stream would silently act on a renderer the
|
|
276
|
+
* caller has likely moved on from.
|
|
277
|
+
*/
|
|
278
|
+
setTarget(target: HTMLTarget): void;
|
|
279
|
+
/**
|
|
280
|
+
* Update the renderer config on the fly. Applies to subsequent commits.
|
|
281
|
+
*
|
|
282
|
+
* @param config - Next config.
|
|
283
|
+
* @throws {@link ClosedStreamError} when the stream is closed or aborted.
|
|
284
|
+
*/
|
|
285
|
+
setConfig(config: Config): void;
|
|
286
|
+
private _assertOpen;
|
|
205
287
|
}
|
|
206
|
-
|
|
207
288
|
/**
|
|
208
|
-
*
|
|
289
|
+
* Minimal subset of the DOM `Node` interface that the DOM targets need.
|
|
209
290
|
*
|
|
210
291
|
* @remarks
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
292
|
+
* These interfaces belong to the built-in DOM targets, not to the main
|
|
293
|
+
* contracts: they describe DOMs provided from outside the library — a real
|
|
294
|
+
* browser document, or a lightweight server-side implementation (for
|
|
295
|
+
* example linkedom). Both satisfy this interface. Custom `HTMLTarget`
|
|
296
|
+
* implementations never touch these types.
|
|
214
297
|
*
|
|
215
|
-
* @
|
|
298
|
+
* @public
|
|
216
299
|
*/
|
|
217
|
-
|
|
300
|
+
interface DOMNodeLike {
|
|
301
|
+
/** Numeric node type, mirroring `Node.nodeType`. */
|
|
302
|
+
nodeType: number;
|
|
303
|
+
/** Text content of this node, mirroring `Node.textContent`. */
|
|
304
|
+
textContent: string | null;
|
|
305
|
+
/** Child nodes, mirroring `Node.childNodes`. */
|
|
306
|
+
childNodes: ArrayLike<DOMNodeLike>;
|
|
307
|
+
/** Owning document, or `null` for detached nodes. */
|
|
308
|
+
ownerDocument: DOMDocumentLike | null;
|
|
309
|
+
/**
|
|
310
|
+
* Append a child node.
|
|
311
|
+
*
|
|
312
|
+
* @param node - Node to append.
|
|
313
|
+
* @returns The appended node.
|
|
314
|
+
*/
|
|
315
|
+
appendChild(node: DOMNodeLike): DOMNodeLike;
|
|
316
|
+
/**
|
|
317
|
+
* Insert a node before a reference child.
|
|
318
|
+
*
|
|
319
|
+
* @param newNode - Node to insert.
|
|
320
|
+
* @param referenceNode - Child to insert before, or `null` to append.
|
|
321
|
+
* @returns The inserted node.
|
|
322
|
+
*/
|
|
323
|
+
insertBefore(newNode: DOMNodeLike, referenceNode: DOMNodeLike | null): DOMNodeLike;
|
|
324
|
+
/**
|
|
325
|
+
* Remove a child node.
|
|
326
|
+
*
|
|
327
|
+
* @param child - Child to remove.
|
|
328
|
+
* @returns The removed node.
|
|
329
|
+
*/
|
|
330
|
+
removeChild(child: DOMNodeLike): DOMNodeLike;
|
|
331
|
+
/**
|
|
332
|
+
* Replace a child node.
|
|
333
|
+
*
|
|
334
|
+
* @param newChild - Replacement node.
|
|
335
|
+
* @param oldChild - Child to replace.
|
|
336
|
+
* @returns The replaced node.
|
|
337
|
+
*/
|
|
338
|
+
replaceChild(newChild: DOMNodeLike, oldChild: DOMNodeLike): DOMNodeLike;
|
|
339
|
+
/**
|
|
340
|
+
* Set an attribute on this node, when supported.
|
|
341
|
+
*
|
|
342
|
+
* @param name - Attribute name.
|
|
343
|
+
* @param value - Attribute value.
|
|
344
|
+
*/
|
|
345
|
+
setAttribute?(name: string, value: string): void;
|
|
346
|
+
/**
|
|
347
|
+
* Remove an attribute from this node, when supported.
|
|
348
|
+
*
|
|
349
|
+
* @param name - Attribute name.
|
|
350
|
+
*/
|
|
351
|
+
removeAttribute?(name: string): void;
|
|
352
|
+
}
|
|
218
353
|
/**
|
|
219
|
-
*
|
|
354
|
+
* Minimal subset of the DOM `Document` interface that markemental needs.
|
|
220
355
|
*
|
|
221
|
-
* @
|
|
356
|
+
* @public
|
|
222
357
|
*/
|
|
223
|
-
interface
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
* trailing partial block across `push` calls.
|
|
239
|
-
*/
|
|
240
|
-
sourceLineCount: number;
|
|
358
|
+
interface DOMDocumentLike {
|
|
359
|
+
/**
|
|
360
|
+
* Create an element node.
|
|
361
|
+
*
|
|
362
|
+
* @param tagName - Lowercase tag name (for example `"p"`).
|
|
363
|
+
* @returns The new element.
|
|
364
|
+
*/
|
|
365
|
+
createElement(tagName: string): DOMNodeLike;
|
|
366
|
+
/**
|
|
367
|
+
* Create a text node.
|
|
368
|
+
*
|
|
369
|
+
* @param data - Text content.
|
|
370
|
+
* @returns The new text node.
|
|
371
|
+
*/
|
|
372
|
+
createTextNode(data: string): DOMNodeLike;
|
|
241
373
|
}
|
|
242
|
-
|
|
243
374
|
/**
|
|
244
|
-
*
|
|
375
|
+
* `requestAnimationFrame` callback scheduler.
|
|
245
376
|
*
|
|
246
|
-
* @
|
|
247
|
-
*
|
|
248
|
-
* single `block` fragments once complete. Lists stream: an opening fragment
|
|
249
|
-
* commits the container, one fragment per item follows, and a closing
|
|
250
|
-
* fragment ends it. Tables stream the same way (head, rows, end), but only
|
|
251
|
-
* {@link GFMState} emits those; {@link CommonMarkState} never does.
|
|
377
|
+
* @param callback - Invoked with the frame timestamp.
|
|
378
|
+
* @returns A handle identifying the scheduled frame.
|
|
252
379
|
*
|
|
253
|
-
* @
|
|
380
|
+
* @public
|
|
254
381
|
*/
|
|
255
|
-
type
|
|
256
|
-
kind: "block";
|
|
257
|
-
block: Block;
|
|
258
|
-
} | {
|
|
259
|
-
kind: "listStart";
|
|
260
|
-
ordered: boolean;
|
|
261
|
-
} | {
|
|
262
|
-
kind: "listItem";
|
|
263
|
-
text: string;
|
|
264
|
-
} | {
|
|
265
|
-
kind: "listEnd";
|
|
266
|
-
} | {
|
|
267
|
-
kind: "tableHead";
|
|
268
|
-
headLine: string;
|
|
269
|
-
delimLine: string;
|
|
270
|
-
} | {
|
|
271
|
-
kind: "tableRow";
|
|
272
|
-
line: string;
|
|
273
|
-
} | {
|
|
274
|
-
kind: "tableEnd";
|
|
275
|
-
};
|
|
382
|
+
type RAF = (callback: (time: number) => void) => number;
|
|
276
383
|
/**
|
|
277
|
-
*
|
|
384
|
+
* Options for {@link createDOMTarget}.
|
|
278
385
|
*
|
|
279
|
-
* @
|
|
280
|
-
* Internal helper owned by a renderer. Lines arrive one at a time: leaf
|
|
281
|
-
* blocks buffer until a new block starts or the stream flushes (preserving
|
|
282
|
-
* trailing holdback), and lists commit one fragment per item with an indent
|
|
283
|
-
* stack for nesting. Tables are not recognized here, so table-looking lines
|
|
284
|
-
* stay plain paragraph text; {@link GFMState} extends this class with table
|
|
285
|
-
* support and nothing else.
|
|
286
|
-
*
|
|
287
|
-
* @internal
|
|
386
|
+
* @public
|
|
288
387
|
*/
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
* @param line - Next source line, without its line break.
|
|
303
|
-
*/
|
|
304
|
-
addLine(line: string): void;
|
|
305
|
-
/**
|
|
306
|
-
* Close every open context and emit the trailing remainder.
|
|
307
|
-
*/
|
|
308
|
-
flush(): void;
|
|
309
|
-
/**
|
|
310
|
-
* Feed a line to the open fence, if any.
|
|
311
|
-
*
|
|
312
|
-
* @param line - Next source line.
|
|
313
|
-
* @returns True when the line was consumed.
|
|
314
|
-
*/
|
|
315
|
-
protected _consumeFence(line: string): boolean;
|
|
316
|
-
/**
|
|
317
|
-
* Feed a line to the open lists, if any, closing and reprocessing when
|
|
318
|
-
* the line is not an item.
|
|
319
|
-
*
|
|
320
|
-
* @param line - Next source line.
|
|
321
|
-
* @returns True when the line was consumed or reprocessed.
|
|
322
|
-
*/
|
|
323
|
-
protected _consumeLists(line: string): boolean;
|
|
324
|
-
/**
|
|
325
|
-
* Feed a line to the open quote, if any, dumping it back to pending when
|
|
326
|
-
* the line does not continue the quote.
|
|
327
|
-
*
|
|
328
|
-
* @param line - Next source line.
|
|
329
|
-
* @returns True when the line was consumed.
|
|
330
|
-
*/
|
|
331
|
-
protected _consumeQuote(line: string): boolean;
|
|
332
|
-
/**
|
|
333
|
-
* Classify a line that continues no open context.
|
|
334
|
-
*
|
|
335
|
-
* @param line - Next source line.
|
|
336
|
-
*/
|
|
337
|
-
protected _classify(line: string): void;
|
|
338
|
-
/**
|
|
339
|
-
* Classify a line that matches no CommonMark opener. The base parser has
|
|
340
|
-
* no pipe syntax, so this never consumes; {@link GFMState} overrides it
|
|
341
|
-
* to start table candidates.
|
|
342
|
-
*
|
|
343
|
-
* @param _line - Next source line.
|
|
344
|
-
* @returns Always false here.
|
|
345
|
-
*/
|
|
346
|
-
protected _classifyPipe(_line: string): boolean;
|
|
347
|
-
private _listItem;
|
|
348
|
-
private _closeLists;
|
|
349
|
-
private _takeComplete;
|
|
350
|
-
protected _takeAll(): void;
|
|
388
|
+
interface DOMTargetOptions {
|
|
389
|
+
/**
|
|
390
|
+
* Document used to create nodes: a real browser document for live pages,
|
|
391
|
+
* or a simulated one such as linkedom for server-side rendering.
|
|
392
|
+
*/
|
|
393
|
+
document: DOMDocumentLike;
|
|
394
|
+
/** Container node receiving rendered output. */
|
|
395
|
+
container: DOMNodeLike;
|
|
396
|
+
/**
|
|
397
|
+
* Optional frame scheduler. When provided, writes are batched on
|
|
398
|
+
* animation frames; otherwise updates apply synchronously.
|
|
399
|
+
*/
|
|
400
|
+
raf?: RAF;
|
|
351
401
|
}
|
|
352
402
|
/**
|
|
353
|
-
*
|
|
403
|
+
* Create a target rendering into a DOM container.
|
|
354
404
|
*
|
|
355
|
-
* @
|
|
356
|
-
*
|
|
357
|
-
* commits at the delimiter row and streams one fragment per row. All leaf
|
|
358
|
-
* and list parsing is inherited unchanged.
|
|
405
|
+
* @param options - Document, container, and optional frame scheduler.
|
|
406
|
+
* @returns The target to hand to a renderer.
|
|
359
407
|
*
|
|
360
|
-
* @
|
|
408
|
+
* @public
|
|
361
409
|
*/
|
|
362
|
-
declare
|
|
363
|
-
private _tableOpen;
|
|
364
|
-
private _candidate;
|
|
365
|
-
/**
|
|
366
|
-
* Feed one source line; completed fragments emit to the handler.
|
|
367
|
-
*
|
|
368
|
-
* @param line - Next source line, without its line break.
|
|
369
|
-
*/
|
|
370
|
-
addLine(line: string): void;
|
|
371
|
-
/**
|
|
372
|
-
* Close every open context and emit the trailing remainder.
|
|
373
|
-
*/
|
|
374
|
-
flush(): void;
|
|
375
|
-
/**
|
|
376
|
-
* Feed a line to the open table, if any, closing and reprocessing when
|
|
377
|
-
* the line is not a row.
|
|
378
|
-
*
|
|
379
|
-
* @param line - Next source line.
|
|
380
|
-
* @returns True when the line was consumed or reprocessed.
|
|
381
|
-
*/
|
|
382
|
-
private _consumeTable;
|
|
383
|
-
/**
|
|
384
|
-
* Resolve a pending table header candidate against the next line.
|
|
385
|
-
*
|
|
386
|
-
* @param line - Next source line.
|
|
387
|
-
* @returns True when a table opened.
|
|
388
|
-
*/
|
|
389
|
-
private _consumeCandidate;
|
|
390
|
-
/**
|
|
391
|
-
* Start a table header candidate on pipe lines.
|
|
392
|
-
*
|
|
393
|
-
* @param line - Next source line.
|
|
394
|
-
* @returns True when the line starts a candidate.
|
|
395
|
-
*/
|
|
396
|
-
protected _classifyPipe(line: string): boolean;
|
|
397
|
-
}
|
|
398
|
-
|
|
410
|
+
export declare function createDOMTarget(options: DOMTargetOptions): HTMLTarget;
|
|
399
411
|
/**
|
|
400
412
|
* Renderer for CommonMark.
|
|
401
413
|
*
|
|
402
414
|
* @remarks
|
|
403
|
-
* Constructed with its target
|
|
415
|
+
* Constructed with its target and config. Feed it lines with
|
|
404
416
|
* {@link CommonMarkRenderer.writeLine}; it holds its own parse state and
|
|
405
|
-
* writes finished blocks to the target as they complete. An
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
417
|
+
* writes finished blocks to the target as they complete. An internal list
|
|
418
|
+
* stack tracks open lists so items — including nested ones — append to
|
|
419
|
+
* the right container as they arrive.
|
|
420
|
+
*
|
|
421
|
+
* The renderer never touches the DOM: it builds everything through the
|
|
422
|
+
* write-only target, so the same renderer drives live pages, simulated
|
|
423
|
+
* DOMs, and fully custom targets. It is standalone: GFM shares internal
|
|
424
|
+
* helpers with it, but neither renderer extends the other.
|
|
409
425
|
*
|
|
410
426
|
* @public
|
|
411
427
|
*/
|
|
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
|
-
* Whether GFM-only inlines are enabled. Always false here; overridden by
|
|
458
|
-
* `GFMRenderer`.
|
|
459
|
-
*
|
|
460
|
-
* @returns False.
|
|
461
|
-
*/
|
|
462
|
-
protected inlineGfm(): boolean;
|
|
463
|
-
/**
|
|
464
|
-
* Render one block to a DOM-like node.
|
|
465
|
-
*
|
|
466
|
-
* @param block - Parsed block to render.
|
|
467
|
-
* @param doc - Document used to create nodes.
|
|
468
|
-
* @returns The rendered node, or `null` to emit nothing.
|
|
469
|
-
*/
|
|
470
|
-
protected renderBlock(block: Block, doc: DOMDocumentLike): DOMNodeLike | null;
|
|
471
|
-
/**
|
|
472
|
-
* Render paragraph lines, honoring two-space hard breaks.
|
|
473
|
-
*
|
|
474
|
-
* @param lines - Raw paragraph lines.
|
|
475
|
-
* @param doc - Document used to create nodes.
|
|
476
|
-
* @returns The paragraph element.
|
|
477
|
-
*/
|
|
478
|
-
protected renderParagraph(lines: string[], doc: DOMDocumentLike): DOMNodeLike;
|
|
479
|
-
private appendLinesInline;
|
|
428
|
+
export declare class CommonMarkRenderer implements MarkdownRenderer<CommonMarkRendererConfig> {
|
|
429
|
+
private _target;
|
|
430
|
+
private _config;
|
|
431
|
+
private _state;
|
|
432
|
+
private _lists;
|
|
433
|
+
/**
|
|
434
|
+
* @param target - Destination for rendered output, from `createDOMTarget`
|
|
435
|
+
* or a custom `HTMLTarget` implementation.
|
|
436
|
+
* @param config - CommonMark rendering config.
|
|
437
|
+
*/
|
|
438
|
+
constructor(target: HTMLTarget, config?: CommonMarkRendererConfig);
|
|
439
|
+
/**
|
|
440
|
+
* Target receiving committed output.
|
|
441
|
+
*/
|
|
442
|
+
get target(): HTMLTarget;
|
|
443
|
+
/**
|
|
444
|
+
* Config applying to subsequent commits.
|
|
445
|
+
*/
|
|
446
|
+
get config(): CommonMarkRendererConfig;
|
|
447
|
+
/**
|
|
448
|
+
* Feed one source line; completed output is written to the target.
|
|
449
|
+
*
|
|
450
|
+
* @param line - Next source line, without its line break.
|
|
451
|
+
*/
|
|
452
|
+
writeLine(line: string): void;
|
|
453
|
+
/**
|
|
454
|
+
* Write the buffered remainder and settle the target.
|
|
455
|
+
*
|
|
456
|
+
* @returns A promise that resolves once all output has landed in the target.
|
|
457
|
+
*/
|
|
458
|
+
flush(): Promise<void>;
|
|
459
|
+
/**
|
|
460
|
+
* Point the renderer at another target. Open lists drain into the
|
|
461
|
+
* previous target; only newly opened blocks go to the new one.
|
|
462
|
+
*
|
|
463
|
+
* @param target - Target receiving future output.
|
|
464
|
+
*/
|
|
465
|
+
setTarget(target: HTMLTarget): void;
|
|
466
|
+
/**
|
|
467
|
+
* Replace the renderer config; applies to subsequent writes.
|
|
468
|
+
*
|
|
469
|
+
* @param config - Next config.
|
|
470
|
+
*/
|
|
471
|
+
setConfig(config: CommonMarkRendererConfig): void;
|
|
472
|
+
private _applyFragment;
|
|
480
473
|
}
|
|
481
474
|
/**
|
|
482
|
-
*
|
|
475
|
+
* Config for {@link CommonMarkRenderer}.
|
|
483
476
|
*
|
|
484
477
|
* @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.
|
|
478
|
+
* Reserved for future renderer options.
|
|
490
479
|
*
|
|
491
480
|
* @public
|
|
492
481
|
*/
|
|
493
|
-
type
|
|
494
|
-
/**
|
|
495
|
-
* Options for {@link CommonMarkRenderer}.
|
|
496
|
-
*
|
|
497
|
-
* @public
|
|
498
|
-
*/
|
|
499
|
-
type CommonMarkRenderOptions = {
|
|
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
|
-
|
|
482
|
+
type CommonMarkRendererConfig = Record<string, never>;
|
|
511
483
|
/**
|
|
512
484
|
* Renderer for GitHub Flavored Markdown.
|
|
513
485
|
*
|
|
514
486
|
* @remarks
|
|
515
487
|
* Supports CommonMark blocks and inlines plus GFM tables and strikethrough.
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
488
|
+
*
|
|
489
|
+
* Standalone: shares internal helpers with `CommonMarkRenderer`, but
|
|
490
|
+
* extends nothing flavor-specific. Consult the full documentation for
|
|
491
|
+
* more details.
|
|
519
492
|
*
|
|
520
493
|
* @public
|
|
521
494
|
*/
|
|
522
|
-
declare class GFMRenderer
|
|
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
|
-
|
|
568
|
-
|
|
569
|
-
|
|
495
|
+
export declare class GFMRenderer implements MarkdownRenderer<GFMRendererConfig> {
|
|
496
|
+
private _target;
|
|
497
|
+
private _config;
|
|
498
|
+
private _state;
|
|
499
|
+
private _lists;
|
|
500
|
+
private _table;
|
|
501
|
+
/**
|
|
502
|
+
* @param target - Destination for rendered output, from `createDOMTarget`
|
|
503
|
+
* or a custom `HTMLTarget` implementation.
|
|
504
|
+
* @param config - GFM rendering config.
|
|
505
|
+
*/
|
|
506
|
+
constructor(target: HTMLTarget, config?: GFMRendererConfig);
|
|
507
|
+
/**
|
|
508
|
+
* Target receiving committed output.
|
|
509
|
+
*/
|
|
510
|
+
get target(): HTMLTarget;
|
|
511
|
+
/**
|
|
512
|
+
* Config applying to subsequent commits.
|
|
513
|
+
*/
|
|
514
|
+
get config(): GFMRendererConfig;
|
|
515
|
+
/**
|
|
516
|
+
* Feed one source line; completed output is written to the target.
|
|
517
|
+
*
|
|
518
|
+
* @param line - Next source line, without its line break.
|
|
519
|
+
*/
|
|
520
|
+
writeLine(line: string): void;
|
|
521
|
+
/**
|
|
522
|
+
* Write the buffered remainder and settle the target.
|
|
523
|
+
*
|
|
524
|
+
* @returns A promise that resolves once all output has landed in the target.
|
|
525
|
+
*/
|
|
526
|
+
flush(): Promise<void>;
|
|
527
|
+
/**
|
|
528
|
+
* Point the renderer at another target. Open lists and tables drain
|
|
529
|
+
* into the previous target; only newly opened blocks go to the new one.
|
|
530
|
+
*
|
|
531
|
+
* @param target - Target receiving future output.
|
|
532
|
+
*/
|
|
533
|
+
setTarget(target: HTMLTarget): void;
|
|
534
|
+
/**
|
|
535
|
+
* Replace the renderer config; applies to subsequent writes.
|
|
536
|
+
*
|
|
537
|
+
* @param config - Next config.
|
|
538
|
+
*/
|
|
539
|
+
setConfig(config: GFMRendererConfig): void;
|
|
540
|
+
private _applyFragment;
|
|
541
|
+
/**
|
|
542
|
+
* Commit the table with its header; body rows stream in afterwards.
|
|
543
|
+
*
|
|
544
|
+
* @param headLine - Raw header row line.
|
|
545
|
+
* @param delimLine - Delimiter row line carrying column alignment.
|
|
546
|
+
*/
|
|
547
|
+
private _applyTableHead;
|
|
548
|
+
/**
|
|
549
|
+
* Append one body row to the open table.
|
|
550
|
+
*
|
|
551
|
+
* @param line - Raw body row line.
|
|
552
|
+
*/
|
|
553
|
+
private _applyTableRow;
|
|
554
|
+
/**
|
|
555
|
+
* Close the open table.
|
|
556
|
+
*/
|
|
557
|
+
private _applyTableEnd;
|
|
570
558
|
}
|
|
571
559
|
/**
|
|
572
|
-
*
|
|
560
|
+
* Config for {@link GFMRenderer}.
|
|
573
561
|
*
|
|
574
562
|
* @public
|
|
575
563
|
*/
|
|
576
|
-
type
|
|
577
|
-
|
|
564
|
+
type GFMRendererConfig = CommonMarkRendererConfig;
|
|
578
565
|
/**
|
|
579
|
-
*
|
|
566
|
+
* Options for {@link createGFMStream}.
|
|
567
|
+
*
|
|
568
|
+
* @public
|
|
569
|
+
*/
|
|
570
|
+
interface GFMStreamOptions {
|
|
571
|
+
/** Container node receiving rendered output. */
|
|
572
|
+
container: DOMNodeLike;
|
|
573
|
+
/**
|
|
574
|
+
* Document used to create nodes: a real browser document for live pages,
|
|
575
|
+
* or a simulated one such as linkedom for server-side rendering.
|
|
576
|
+
*/
|
|
577
|
+
document: DOMDocumentLike;
|
|
578
|
+
/** GFM rendering config. */
|
|
579
|
+
config?: GFMRendererConfig;
|
|
580
|
+
/**
|
|
581
|
+
* Optional frame scheduler. When provided, DOM writes are batched on
|
|
582
|
+
* animation frames; otherwise updates apply synchronously.
|
|
583
|
+
*/
|
|
584
|
+
raf?: RAF;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Create a GFM stream rendering into the given container.
|
|
580
588
|
*
|
|
581
589
|
* @remarks
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
590
|
+
* One-call wiring of a DOM target, a `GFMRenderer`, and a `MarkdownStream`.
|
|
591
|
+
* For a custom renderer or target, wire them yourself with
|
|
592
|
+
* `new MarkdownStream(renderer)`.
|
|
585
593
|
*
|
|
586
|
-
* @param
|
|
587
|
-
* @
|
|
588
|
-
* @param opts - GFM rendering options.
|
|
589
|
-
* @param raf - Optional frame scheduler. When provided, DOM writes are
|
|
590
|
-
* batched on animation frames for smooth streaming.
|
|
591
|
-
* @returns The configured pipeline.
|
|
594
|
+
* @param options - Container, document, config, and optional frame scheduler.
|
|
595
|
+
* @returns The configured stream.
|
|
592
596
|
*
|
|
593
597
|
* @example
|
|
594
598
|
* ```ts
|
|
595
|
-
* const
|
|
596
|
-
* document.getElementById("out")
|
|
599
|
+
* const stream = createGFMStream({
|
|
600
|
+
* container: document.getElementById("out")!,
|
|
597
601
|
* document,
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
* );
|
|
601
|
-
* await
|
|
602
|
-
* await
|
|
602
|
+
* raf: requestAnimationFrame,
|
|
603
|
+
* });
|
|
604
|
+
* const writer = stream.getWriter();
|
|
605
|
+
* await writer.write("# Hello\n");
|
|
606
|
+
* await writer.close();
|
|
603
607
|
* ```
|
|
604
608
|
*
|
|
605
609
|
* @public
|
|
606
610
|
*/
|
|
607
|
-
declare function
|
|
611
|
+
export declare function createGFMStream(options: GFMStreamOptions): MarkdownStream<GFMRendererConfig>;
|
|
608
612
|
/**
|
|
609
|
-
*
|
|
613
|
+
* Options for {@link createCommonMarkStream}.
|
|
610
614
|
*
|
|
611
615
|
* @public
|
|
612
616
|
*/
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
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>;
|
|
617
|
+
interface CommonMarkStreamOptions {
|
|
618
|
+
/** Container node receiving rendered output. */
|
|
619
|
+
container: DOMNodeLike;
|
|
620
|
+
/**
|
|
621
|
+
* Document used to create nodes: a real browser document for live pages,
|
|
622
|
+
* or a simulated one such as linkedom for server-side rendering.
|
|
623
|
+
*/
|
|
624
|
+
document: DOMDocumentLike;
|
|
625
|
+
/** CommonMark rendering config. */
|
|
626
|
+
config?: CommonMarkRendererConfig;
|
|
627
|
+
/**
|
|
628
|
+
* Optional frame scheduler. When provided, DOM writes are batched on
|
|
629
|
+
* animation frames; otherwise updates apply synchronously.
|
|
630
|
+
*/
|
|
631
|
+
raf?: RAF;
|
|
635
632
|
}
|
|
636
|
-
|
|
637
633
|
/**
|
|
638
|
-
* Create a CommonMark
|
|
634
|
+
* Create a CommonMark stream rendering into the given container.
|
|
639
635
|
*
|
|
640
636
|
* @remarks
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
637
|
+
* One-call wiring of a DOM target, a `CommonMarkRenderer`, and a
|
|
638
|
+
* `MarkdownStream`. For a custom renderer or target, wire them yourself
|
|
639
|
+
* with `new MarkdownStream(renderer)`.
|
|
644
640
|
*
|
|
645
|
-
* @param
|
|
646
|
-
* @
|
|
647
|
-
* @param opts - CommonMark rendering options.
|
|
648
|
-
* @param raf - Optional frame scheduler. When provided, DOM writes are
|
|
649
|
-
* batched on animation frames for smooth streaming.
|
|
650
|
-
* @returns The configured pipeline.
|
|
641
|
+
* @param options - Container, document, config, and optional frame scheduler.
|
|
642
|
+
* @returns The configured stream.
|
|
651
643
|
*
|
|
652
644
|
* @example
|
|
653
645
|
* ```ts
|
|
654
|
-
* const
|
|
655
|
-
* document.getElementById("out")
|
|
646
|
+
* const stream = createCommonMarkStream({
|
|
647
|
+
* container: document.getElementById("out")!,
|
|
656
648
|
* document,
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
* );
|
|
660
|
-
* await
|
|
661
|
-
* await
|
|
649
|
+
* raf: requestAnimationFrame,
|
|
650
|
+
* });
|
|
651
|
+
* const writer = stream.getWriter();
|
|
652
|
+
* await writer.write("# Hello\n");
|
|
653
|
+
* await writer.close();
|
|
662
654
|
* ```
|
|
663
655
|
*
|
|
664
656
|
* @public
|
|
665
657
|
*/
|
|
666
|
-
declare function
|
|
658
|
+
export declare function createCommonMarkStream(options: CommonMarkStreamOptions): MarkdownStream<CommonMarkRendererConfig>;
|
|
667
659
|
/**
|
|
668
|
-
*
|
|
660
|
+
* Runtime-aware utilities. Each prefers a native built-in when one is
|
|
661
|
+
* available and falls back to a bundled implementation with identical
|
|
662
|
+
* output otherwise.
|
|
663
|
+
*
|
|
664
|
+
* @remarks
|
|
665
|
+
* Kept in one file while small; split when a utility outgrows it.
|
|
666
|
+
*/
|
|
667
|
+
/**
|
|
668
|
+
* JavaScript runtime hosting this module.
|
|
669
669
|
*
|
|
670
670
|
* @public
|
|
671
671
|
*/
|
|
672
|
-
|
|
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
|
-
|
|
672
|
+
type RuntimeKind = "bun" | "deno" | "node" | "browser" | "unknown";
|
|
696
673
|
/**
|
|
697
|
-
*
|
|
674
|
+
* Detect the JavaScript runtime hosting this module.
|
|
698
675
|
*
|
|
699
|
-
* @
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
676
|
+
* @remarks
|
|
677
|
+
* Checks `Bun` first, then `Deno`, then Node's `process.versions`, then
|
|
678
|
+
* browser globals. Bun and Deno both expose Node-compatible globals, so
|
|
679
|
+
* order matters: the native brand always wins over the compatibility
|
|
680
|
+
* layer. Used by the smart utilities to prefer runtime built-ins (for
|
|
681
|
+
* example `Bun.escapeHTML`) over bundled fallbacks.
|
|
682
|
+
*
|
|
683
|
+
* @returns The detected runtime, or `"unknown"` when none matches.
|
|
684
|
+
*
|
|
685
|
+
* @public
|
|
686
|
+
*/
|
|
687
|
+
export declare function getRuntime(): RuntimeKind;
|
|
688
|
+
/**
|
|
689
|
+
* Escape text for insertion into HTML.
|
|
690
|
+
*
|
|
691
|
+
* @remarks
|
|
692
|
+
* Handy for custom `HTMLTarget` implementations that serialize collected
|
|
693
|
+
* nodes to strings. Consult the full documentation for more details.
|
|
694
|
+
*
|
|
695
|
+
* @param text - Raw text to escape.
|
|
696
|
+
* @returns The escaped text.
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* ```ts
|
|
700
|
+
* escapeHTML(`<a href="x&y">`) // "<a href="x&y">"
|
|
701
|
+
* ```
|
|
703
702
|
*
|
|
704
703
|
* @public
|
|
705
704
|
*/
|
|
706
|
-
declare function
|
|
707
|
-
|
|
708
|
-
|
|
705
|
+
export declare function escapeHTML(text: string): string;
|
|
706
|
+
export type { CommonMarkRendererConfig, CommonMarkStreamOptions, DOMDocumentLike, DOMNodeLike, DOMTargetOptions, GFMRendererConfig, GFMStreamOptions, HTMLTarget, MarkdownRenderer, NodeId, RAF, RuntimeKind };
|
|
707
|
+
//# sourceMappingURL=index.d.ts.map
|