@mdsvex/parse 1.0.0-next.2 → 1.0.0-next.4
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/PLUGINS.md +45 -3
- package/WIRE_FORMAT.md +23 -8
- package/dist/cursor.d.ts +18 -12
- package/dist/cursor.js +5 -5
- package/dist/main.d.ts +1 -1
- package/dist/main.js +2354 -2113
- package/dist/opcodes.d.ts +9 -5
- package/dist/plugin_dispatch.d.ts +18 -0
- package/dist/plugin_tasks.d.ts +4 -0
- package/dist/plugin_types.d.ts +7 -1
- package/dist/types.d.ts +5 -2
- package/dist/utils.d.ts +64 -0
- package/dist/utils.js +272 -187
- package/package.json +1 -1
package/dist/opcodes.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export interface IdSource {
|
|
|
7
7
|
/**
|
|
8
8
|
* emitter interface for pfm parser opcodes.
|
|
9
9
|
*
|
|
10
|
+
* offsets are utf-16 code unit indices, not utf-8 bytes, into the source after
|
|
11
|
+
* normalize_newlines, so a crlf source is shorter than the file and RawOffsets
|
|
12
|
+
* maps them back to it
|
|
13
|
+
*
|
|
10
14
|
* the parser calls these methods as it processes input. implementations
|
|
11
15
|
* decide what to do with each opcode:
|
|
12
16
|
* - treebuilder: reconstructs a NodeBuffer (backward compat)
|
|
@@ -20,7 +24,7 @@ export interface Emitter {
|
|
|
20
24
|
* node takes the next id, so a builder can use ids as slot indices
|
|
21
25
|
* @param id monotonic node id (unique within this parse).
|
|
22
26
|
* @param kind node kind (heading, paragraph, emphasis, etc.).
|
|
23
|
-
* @param start source
|
|
27
|
+
* @param start source offset where this node starts
|
|
24
28
|
* @param parent id of the parent node (-1 for root's parent).
|
|
25
29
|
* @param extra kind-specific extra value (e.g. heading depth).
|
|
26
30
|
* @param pending true if this node is speculative (may be revoked).
|
|
@@ -30,7 +34,7 @@ export interface Emitter {
|
|
|
30
34
|
* close a previously opened node, a pending node is final from here on
|
|
31
35
|
* unless it is a paragraph, which a commit or a revoke settles later
|
|
32
36
|
* @param id id of the node to close.
|
|
33
|
-
* @param end source
|
|
37
|
+
* @param end source offset where this node ends
|
|
34
38
|
* @param kind kind at open, a revoke may have rewritten it since, omitting
|
|
35
39
|
* it makes the builder track revokes
|
|
36
40
|
*/
|
|
@@ -48,8 +52,8 @@ export interface Emitter {
|
|
|
48
52
|
* headings, code fences, code spans and html comments get a value range and
|
|
49
53
|
* take no id
|
|
50
54
|
* @param parent id of the parent node.
|
|
51
|
-
* @param start source
|
|
52
|
-
* @param end source
|
|
55
|
+
* @param start source offset of text start
|
|
56
|
+
* @param end source offset of text end
|
|
53
57
|
* @param parent_kind parent kind at open, as for close
|
|
54
58
|
*/
|
|
55
59
|
text(parent: number, start: number, end: number, parent_kind?: NodeKind): void;
|
|
@@ -112,7 +116,7 @@ export interface Emitter {
|
|
|
112
116
|
* report the parser's current cursor position. called at the end of
|
|
113
117
|
* each feed() and finish(). emitters can use this as the boundary
|
|
114
118
|
* for eager text emission during streaming.
|
|
115
|
-
* @param pos current
|
|
119
|
+
* @param pos current offset in the source
|
|
116
120
|
*/
|
|
117
121
|
cursor(pos: number): void;
|
|
118
122
|
/** the incremental finish emitted the last opcode, reserved storage can go */
|
|
@@ -5,6 +5,13 @@ import { NodeView, type StructureHost, type TextSource } from './node_view.js';
|
|
|
5
5
|
import type { ParsePlugin, PluginData, PluginDocument, PluginWarning, DirectiveTable, TaskContext as PublicTaskContext } from './plugin_types.js';
|
|
6
6
|
import { HeadingIds } from './heading_ids.js';
|
|
7
7
|
import { Task, type TaskHost } from './plugin_tasks.js';
|
|
8
|
+
/** two tables have an entry for one directive name, which has one owner */
|
|
9
|
+
export declare class DirectiveOwnerError extends Error {
|
|
10
|
+
directive: string;
|
|
11
|
+
/** the names of the two plugins, the earlier first, undefined for a table without one */
|
|
12
|
+
plugins: [string | undefined, string | undefined];
|
|
13
|
+
constructor(directive: string, plugins: [string | undefined, string | undefined]);
|
|
14
|
+
}
|
|
8
15
|
/** true when a table binds a handler, without one a parse needs no dispatcher for them */
|
|
9
16
|
export declare function has_directive_handlers(tables: DirectiveTable[] | undefined): boolean;
|
|
10
17
|
/**
|
|
@@ -97,6 +104,8 @@ export declare class PluginDispatcher implements StructureHost, RedirectHost, Da
|
|
|
97
104
|
private close_with;
|
|
98
105
|
/** the node whose handler or close callback is running */
|
|
99
106
|
private running;
|
|
107
|
+
/** the observer whose handler or close callback is running, it changes no node */
|
|
108
|
+
private observing;
|
|
100
109
|
/** the callbacks of a close that is final are running, their node is settled */
|
|
101
110
|
private final_close;
|
|
102
111
|
/** close callbacks are running, not open handlers */
|
|
@@ -369,6 +378,13 @@ export declare class PluginDispatcher implements StructureHost, RedirectHost, Da
|
|
|
369
378
|
* the parse handler of the name runs for any directive
|
|
370
379
|
*/
|
|
371
380
|
dispatch_name(buf_idx: number, name: unknown, buf: NodeBuffer): void;
|
|
381
|
+
/**
|
|
382
|
+
* observers run after the owner at the open and after every other callback
|
|
383
|
+
* at the close, each with a scope of its own below that of the owner
|
|
384
|
+
*/
|
|
385
|
+
private observe;
|
|
386
|
+
/** a close callback of an observer, which changes no node either */
|
|
387
|
+
private observed;
|
|
372
388
|
/** a scope opened or ended, the kinds an open needs the dispatcher for follow */
|
|
373
389
|
private scopes_changed;
|
|
374
390
|
private drop_narrow;
|
|
@@ -398,6 +414,8 @@ export declare class PluginDispatcher implements StructureHost, RedirectHost, Da
|
|
|
398
414
|
* they opened under the paragraph, so the children handlers of the directive have not seen them
|
|
399
415
|
*/
|
|
400
416
|
lifted(buf_idx: number, buf: NodeBuffer): number[] | null;
|
|
417
|
+
/** a children handler on the innermost directive, of the owner or of an observer */
|
|
418
|
+
private takes_lifted;
|
|
401
419
|
/** the children handlers of the innermost scope for each node the repair made its child */
|
|
402
420
|
dispatch_lifted(nodes: number[], buf: NodeBuffer): void;
|
|
403
421
|
/**
|
package/dist/plugin_tasks.d.ts
CHANGED
|
@@ -84,6 +84,8 @@ export interface TaskHost {
|
|
|
84
84
|
/** the view of a node for a task to read */
|
|
85
85
|
real(task: Task, index: number): NodeView;
|
|
86
86
|
}
|
|
87
|
+
/** the message of a write to a node by an observer, which changes no node */
|
|
88
|
+
export declare function observer_write(what: string, observing: string): string;
|
|
87
89
|
/** async work deferred on a node, its changes wait until it settled and the node is committed */
|
|
88
90
|
export declare class Task {
|
|
89
91
|
/** the node it was deferred on, the owner of what it writes */
|
|
@@ -100,6 +102,8 @@ export declare class Task {
|
|
|
100
102
|
/** the node went, or the document did, the task is forgotten */
|
|
101
103
|
dropped: boolean;
|
|
102
104
|
applied: boolean;
|
|
105
|
+
/** for the task of an observer, who observes what, a write to a node then throws */
|
|
106
|
+
observing: string | null;
|
|
103
107
|
ops: Op[];
|
|
104
108
|
/** resolves once the task settled, never rejects */
|
|
105
109
|
done: Promise<void>;
|
package/dist/plugin_types.d.ts
CHANGED
|
@@ -172,9 +172,15 @@ export interface ParsePlugin {
|
|
|
172
172
|
* the text of an element that holds code, such as code or kbd
|
|
173
173
|
*/
|
|
174
174
|
all_text?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* directives the plugin observes by name, whoever owns them, entries as
|
|
177
|
+
* those of a table of bound handlers, they run in the fused pass after the
|
|
178
|
+
* handlers of the owner and change no node, a write to one is a TypeError
|
|
179
|
+
*/
|
|
180
|
+
observe?: DirectiveHandlers;
|
|
175
181
|
[nodeType: string]: {
|
|
176
182
|
parse: NodeHandler['parse'];
|
|
177
|
-
} | TextHandler | ((root: NodeView, ctx: PluginContext) => void | Promise<void>) | boolean | string | undefined;
|
|
183
|
+
} | TextHandler | ((root: NodeView, ctx: PluginContext) => void | Promise<void>) | DirectiveHandlers | boolean | string | undefined;
|
|
178
184
|
}
|
|
179
185
|
/** what a handler bound to a directive gets in place of the plugin context */
|
|
180
186
|
export interface DirectiveContext extends DocumentContext {
|
package/dist/types.d.ts
CHANGED
|
@@ -30,9 +30,12 @@ export interface ParseOptions extends SyntaxOptions {
|
|
|
30
30
|
filename?: string;
|
|
31
31
|
/**
|
|
32
32
|
* parses the frontmatter for plugin handlers, called once with the text
|
|
33
|
-
* between the fences when a handler first reads
|
|
33
|
+
* between the fences and the filename when a handler first reads
|
|
34
|
+
* ctx.frontmatter
|
|
34
35
|
*/
|
|
35
|
-
frontmatter?: (text: string
|
|
36
|
+
frontmatter?: (text: string, file: {
|
|
37
|
+
filename: string | undefined;
|
|
38
|
+
}) => Record<string, unknown> | undefined;
|
|
36
39
|
}
|
|
37
40
|
/** structured output produced by the markdown parser. */
|
|
38
41
|
export interface ParseResult {
|
package/dist/utils.d.ts
CHANGED
|
@@ -102,6 +102,69 @@ export declare function take_math(): boolean;
|
|
|
102
102
|
* between documents as the note of take_src is
|
|
103
103
|
*/
|
|
104
104
|
export declare function take_info(source: string, text: string, other?: string): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* @internal the attributes of an open tag as the scan found them, five words
|
|
107
|
+
* per attribute in rec from at, kind then name and value ranges
|
|
108
|
+
*/
|
|
109
|
+
export declare class AttrSpans {
|
|
110
|
+
readonly source: string;
|
|
111
|
+
readonly base: number;
|
|
112
|
+
readonly rec: Int32Array;
|
|
113
|
+
readonly at: number;
|
|
114
|
+
readonly n: number;
|
|
115
|
+
/** where the tag name starts, one past the < */
|
|
116
|
+
readonly name_start: number;
|
|
117
|
+
/** past the last attribute, before the space ahead of > or /> */
|
|
118
|
+
readonly attrs_end: number;
|
|
119
|
+
/** past the > */
|
|
120
|
+
readonly open_end: number;
|
|
121
|
+
/** past the tag name, where the attributes start */
|
|
122
|
+
readonly attrs_start: number;
|
|
123
|
+
/** the source from attrs_start to attrs_end is what fold writes for the record */
|
|
124
|
+
readonly canonical: boolean;
|
|
125
|
+
constructor(source: string, base: number, rec: Int32Array, at: number, n: number,
|
|
126
|
+
/** where the tag name starts, one past the < */
|
|
127
|
+
name_start: number,
|
|
128
|
+
/** past the last attribute, before the space ahead of > or /> */
|
|
129
|
+
attrs_end: number,
|
|
130
|
+
/** past the > */
|
|
131
|
+
open_end: number,
|
|
132
|
+
/** past the tag name, where the attributes start */
|
|
133
|
+
attrs_start: number,
|
|
134
|
+
/** the source from attrs_start to attrs_end is what fold writes for the record */
|
|
135
|
+
canonical: boolean);
|
|
136
|
+
/** the canonical attribute text, sliced once */
|
|
137
|
+
text: string | undefined;
|
|
138
|
+
}
|
|
139
|
+
/** @internal the attributes of a canonical tag as written */
|
|
140
|
+
export declare function spans_text(s: AttrSpans): string;
|
|
141
|
+
/** @internal copies n words of a scan record into the shared store, attr_at says where */
|
|
142
|
+
export declare function store_attr_rec(rec: Int32Array, n: number): Int32Array;
|
|
143
|
+
/** @internal where the last store_attr_rec put its words */
|
|
144
|
+
export declare function stored_attr_at(): number;
|
|
145
|
+
/** the record the eager path builds, for a tag with no repeated names and no framed values */
|
|
146
|
+
export declare function build_attrs(s: AttrSpans): Record<string, unknown>;
|
|
147
|
+
/** @internal whether a lazy tag writes an attribute named name, without building the record */
|
|
148
|
+
export declare function spans_have(s: AttrSpans, name: string): boolean;
|
|
149
|
+
declare const ATTRS: unique symbol;
|
|
150
|
+
/**
|
|
151
|
+
* the metadata of a tagged node, attributes is built from its spans on first
|
|
152
|
+
* read, a symbol key keeps the store out of keys, for in and json
|
|
153
|
+
*/
|
|
154
|
+
export declare class HtmlMeta {
|
|
155
|
+
tag: unknown;
|
|
156
|
+
[ATTRS]: AttrSpans | Record<string, unknown> | undefined;
|
|
157
|
+
constructor(tag: unknown);
|
|
158
|
+
get attributes(): Record<string, unknown> | undefined;
|
|
159
|
+
set attributes(value: AttrSpans | Record<string, unknown> | undefined);
|
|
160
|
+
}
|
|
161
|
+
/** metadata as own string keys, a spread leaves out the getter and keeps the symbol */
|
|
162
|
+
export declare function plain_meta(meta: any): any;
|
|
163
|
+
/**
|
|
164
|
+
* @internal the spans of a typed tag whose attributes nobody has read, they
|
|
165
|
+
* spell the source as written, undefined otherwise
|
|
166
|
+
*/
|
|
167
|
+
export declare function unread_spans(meta: unknown): AttrSpans | undefined;
|
|
105
168
|
/**
|
|
106
169
|
* a computed key literal takes a slow generic define, so known keys get
|
|
107
170
|
* constant key literals and other keys a store into an empty literal
|
|
@@ -344,3 +407,4 @@ export declare class ErrorCollector {
|
|
|
344
407
|
/** double the backing storage when capacity is exhausted. */
|
|
345
408
|
private grow;
|
|
346
409
|
}
|
|
410
|
+
export {};
|