satteri 0.9.4 → 0.10.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 +11 -1
- package/dist/binding.browser.d.ts +1 -1
- package/dist/binding.browser.js +1 -1
- package/dist/binding.d.ts +1 -1
- package/dist/binding.js +1 -1
- package/dist/byte-writer.d.ts +4 -0
- package/dist/byte-writer.js +13 -4
- package/dist/child-stub.d.ts +7 -3
- package/dist/child-stub.js +18 -7
- package/dist/command-buffer.d.ts +36 -50
- package/dist/command-buffer.js +102 -49
- package/dist/compile.d.ts +80 -32
- package/dist/compile.js +295 -70
- package/dist/freeze.d.ts +2 -0
- package/dist/freeze.js +10 -0
- package/dist/generated/wire-constants.d.ts +3 -2
- package/dist/generated/wire-constants.js +4 -2
- package/dist/hast/child-stub.d.ts +2 -3
- package/dist/hast/child-stub.js +18 -11
- package/dist/hast/element-props.d.ts +1 -1
- package/dist/hast/element-props.js +14 -6
- package/dist/hast/hast-materializer.d.ts +6 -2
- package/dist/hast/hast-materializer.js +48 -134
- package/dist/hast/hast-reader.d.ts +7 -13
- package/dist/hast/hast-reader.js +76 -21
- package/dist/hast/hast-visitor.d.ts +55 -5
- package/dist/hast/hast-visitor.js +320 -154
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/lazy-child-resolver.d.ts +20 -13
- package/dist/lazy-child-resolver.js +66 -38
- package/dist/materializer-cache.d.ts +42 -0
- package/dist/materializer-cache.js +192 -0
- package/dist/mdast/child-stub.d.ts +6 -3
- package/dist/mdast/child-stub.js +71 -8
- package/dist/mdast/generated/layout.d.ts +2 -3
- package/dist/mdast/generated/layout.js +24 -28
- package/dist/mdast/generated/node-types.d.ts +4 -0
- package/dist/mdast/generated/node-types.js +25 -0
- package/dist/mdast/mdast-materializer.d.ts +12 -3
- package/dist/mdast/mdast-materializer.js +83 -78
- package/dist/mdast/mdast-reader.d.ts +15 -0
- package/dist/mdast/mdast-reader.js +55 -10
- package/dist/mdast/mdast-visitor.d.ts +79 -32
- package/dist/mdast/mdast-visitor.js +305 -122
- package/dist/op-stream.d.ts +5 -12
- package/dist/op-stream.js +6 -21
- package/dist/plugin.d.ts +36 -10
- package/dist/plugin.js +50 -2
- package/dist/string-pool.d.ts +13 -0
- package/dist/string-pool.js +91 -0
- package/dist/types.d.ts +44 -1
- package/dist/visitor-shared.d.ts +27 -4
- package/dist/visitor-shared.js +36 -10
- package/dist/wire-read.js +3 -1
- package/index.d.ts +130 -7
- package/index.js +89 -68
- package/package.json +24 -19
- package/dist/lazy-props.d.ts +0 -10
- package/dist/lazy-props.js +0 -50
- package/satteri_napi.wasi-browser.js +0 -83
- package/satteri_napi.wasi.cjs +0 -134
- package/wasi-worker-browser.mjs +0 -36
- package/wasi-worker.mjs +0 -63
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MdastReader } from "./mdast-reader.js";
|
|
2
2
|
import { CommandBuffer } from "../command-buffer.js";
|
|
3
|
-
import type { MdastNode, Toml, MathNode, InlineMath, Superscript, Subscript, Data } from "../types.js";
|
|
3
|
+
import type { MdastNode, Toml, MathNode, InlineMath, Superscript, Subscript, DescriptionList, DescriptionTerm, DescriptionDetails, Custom, Data, SourceFormat } from "../types.js";
|
|
4
|
+
import { type PluginOptions } from "../visitor-shared.js";
|
|
4
5
|
import { LazyChildResolver } from "../lazy-child-resolver.js";
|
|
5
6
|
import type { MdastHandle } from "../handles.js";
|
|
6
7
|
import type { Blockquote, Break, Code, Definition, Delete, Emphasis, FootnoteDefinition, FootnoteReference, Heading, Html, Image, ImageReference, InlineCode, Link, LinkReference, List, ListItem, Paragraph, Strong, Table, TableRow, TableCell, Text, ThematicBreak, Yaml, Parents as MdastParents, Root as MdastRoot } from "mdast";
|
|
@@ -8,14 +9,31 @@ import type { MdxJsxFlowElement, MdxJsxTextElement } from "../mdx-types.js";
|
|
|
8
9
|
import type { MdxFlowExpression, MdxTextExpression } from "../mdx-types.js";
|
|
9
10
|
import type { MdxjsEsm } from "../mdx-types.js";
|
|
10
11
|
import type { ContainerDirective, LeafDirective, TextDirective } from "../directive-types.js";
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
export
|
|
12
|
+
/** A string spliced into the tree, re-parsed as Markdown. Set `mdxExpressions:
|
|
13
|
+
* false` to keep MDX `{…}` literal, needed when injecting generated HTML
|
|
14
|
+
* (KaTeX, highlighters, diagrams) whose braces aren't expressions. Default true. */
|
|
15
|
+
export interface RawMdastContent {
|
|
15
16
|
raw: string;
|
|
16
|
-
|
|
17
|
+
mdxExpressions?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface RawHtmlMdastContent {
|
|
20
|
+
/** @deprecated Use the equivalent `{ raw, mdxExpressions: false }`. */
|
|
17
21
|
rawHtml: string;
|
|
18
|
-
}
|
|
22
|
+
}
|
|
23
|
+
/** New content for a structural mutation: a declarative node, or a raw string
|
|
24
|
+
* escape hatch ({@link RawMdastContent}). Declarative nodes compile to the
|
|
25
|
+
* op-stream; a type the op-stream can't encode is a hard error. */
|
|
26
|
+
export type MdastContent = MdastNode | Custom | RawMdastContent | RawHtmlMdastContent;
|
|
27
|
+
/** An existing node a mutation targets. Includes {@link Custom} so a node
|
|
28
|
+
* reached through the `custom` visitor can be passed straight back in. */
|
|
29
|
+
export type MdastTarget = MdastNode | Custom;
|
|
30
|
+
/** A `wrapNode` wrapper: a built-in parent, or a user-defined node declaring
|
|
31
|
+
* a children array. */
|
|
32
|
+
export type MdastParentContent = Exclude<Extract<MdastNode, {
|
|
33
|
+
children: unknown[];
|
|
34
|
+
}>, MdastRoot> | (Custom & {
|
|
35
|
+
children: NonNullable<Custom["children"]>;
|
|
36
|
+
});
|
|
19
37
|
export interface MdastDiagnostic {
|
|
20
38
|
message: string;
|
|
21
39
|
nodeId?: number | undefined;
|
|
@@ -38,33 +56,49 @@ export declare class MdastVisitorContext {
|
|
|
38
56
|
* instances. Returned to the caller as `result.data`.
|
|
39
57
|
*/
|
|
40
58
|
readonly data: Data;
|
|
41
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The source format this compile is processing: `"markdown"` for a plain
|
|
61
|
+
* Markdown compile, `"mdx"` for an MDX one. Lets a plugin shared between both
|
|
62
|
+
* pipelines branch on which it is handling.
|
|
63
|
+
*/
|
|
64
|
+
readonly sourceFormat: SourceFormat;
|
|
65
|
+
constructor(handle: MdastHandle, getSource: () => string, fileURL: URL | undefined, resolver: LazyChildResolver<MdastReader, MdastNode>, data: Data, sourceFormat: SourceFormat, diagnostics: MdastDiagnostic[]);
|
|
42
66
|
get source(): string;
|
|
43
|
-
removeNode(node: Readonly<
|
|
44
|
-
insertBefore(node: Readonly<
|
|
45
|
-
insertAfter(node: Readonly<
|
|
67
|
+
removeNode(node: Readonly<MdastTarget>): void;
|
|
68
|
+
insertBefore(node: Readonly<MdastTarget>, newNode: MdastContent | MdastContent[]): void;
|
|
69
|
+
insertAfter(node: Readonly<MdastTarget>, newNode: MdastContent | MdastContent[]): void;
|
|
46
70
|
/**
|
|
47
71
|
* Wrap `node` in `parentNode`, making it `parentNode`'s first child. Any
|
|
48
|
-
* children `parentNode` declares are kept after it.
|
|
72
|
+
* children `parentNode` declares are kept after it. `parentNode` must be a
|
|
73
|
+
* node type that can hold children, or a raw string parsing to exactly one
|
|
74
|
+
* such block (`{ raw: "> " }` wraps in a blockquote); to surround a node
|
|
75
|
+
* with raw HTML tags, use `replaceNode(node, [openTag, node, closeTag])`
|
|
76
|
+
* instead.
|
|
49
77
|
*/
|
|
50
|
-
wrapNode(node: Readonly<
|
|
51
|
-
prependChild(node: Readonly<
|
|
52
|
-
appendChild(node: Readonly<
|
|
78
|
+
wrapNode(node: Readonly<MdastTarget>, parentNode: MdastParentContent | RawMdastContent | RawHtmlMdastContent): void;
|
|
79
|
+
prependChild(node: Readonly<MdastTarget>, childNode: MdastContent | MdastContent[]): void;
|
|
80
|
+
appendChild(node: Readonly<MdastTarget>, childNode: MdastContent | MdastContent[]): void;
|
|
53
81
|
/** Insert one node or an array at `index`; clamps (`0` or less prepends, past the end appends). */
|
|
54
|
-
insertChildAt(node: Readonly<
|
|
82
|
+
insertChildAt(node: Readonly<MdastTarget>, index: number, childNode: MdastContent | MdastContent[]): void;
|
|
55
83
|
/** Remove the `index`-th child of `node`; a no-op when there is no such child. */
|
|
56
|
-
removeChildAt(node: Readonly<
|
|
57
|
-
|
|
58
|
-
|
|
84
|
+
removeChildAt(node: Readonly<MdastTarget>, index: number): void;
|
|
85
|
+
/**
|
|
86
|
+
* Swap `node` for one node, or for an array of nodes placed in order at its
|
|
87
|
+
* position. An empty array drops the node, the same as `removeNode`.
|
|
88
|
+
* The document root takes a `root`, the one place a `root` is accepted as
|
|
89
|
+
* content, or a raw string, which parses to a root of its own.
|
|
90
|
+
*/
|
|
91
|
+
replaceNode(node: Readonly<MdastTarget>, newNode: MdastContent | MdastContent[]): void;
|
|
92
|
+
setProperty<N extends MdastTarget, K extends keyof N & string>(node: Readonly<N>, key: K, value: N[K]): void;
|
|
59
93
|
/** `children` is structural and every parent accepts it, so the key also
|
|
60
94
|
* works on node-type unions (e.g. a node returned by `parent()`). */
|
|
61
|
-
setProperty(node: Readonly<
|
|
95
|
+
setProperty(node: Readonly<MdastTarget>, key: "children", value: readonly MdastTarget[]): void;
|
|
62
96
|
/** `data` is an open per-node bag serialized to JSON on the wire, so it
|
|
63
97
|
* accepts any record (hName/hProperties/custom fields), not just the node's
|
|
64
98
|
* declared `data` shape. `null` clears it. */
|
|
65
|
-
setProperty(node: Readonly<
|
|
99
|
+
setProperty(node: Readonly<MdastTarget>, key: "data", value: Record<string, unknown> | null): void;
|
|
66
100
|
/** Collect the concatenated text of all descendant text nodes (like mdast-util-to-string). */
|
|
67
|
-
textContent(node: Readonly<
|
|
101
|
+
textContent(node: Readonly<MdastTarget>, options?: {
|
|
68
102
|
includeImageAlt?: boolean;
|
|
69
103
|
includeHtml?: boolean;
|
|
70
104
|
}): string;
|
|
@@ -74,28 +108,32 @@ export declare class MdastVisitorContext {
|
|
|
74
108
|
* by identity.
|
|
75
109
|
*/
|
|
76
110
|
parent<N extends Exclude<MdastNode, MdastRoot>>(node: Readonly<N>): Readonly<MdastParents>;
|
|
77
|
-
parent(node: Readonly<
|
|
111
|
+
parent(node: Readonly<MdastTarget>): Readonly<MdastParents> | undefined;
|
|
78
112
|
/**
|
|
79
113
|
* Index of `node` within its parent's children, or `undefined` at the root.
|
|
80
114
|
* Use this rather than `parent.children.indexOf(node)`, which won't find it.
|
|
81
115
|
*/
|
|
82
|
-
indexOf(node: Readonly<
|
|
116
|
+
indexOf(node: Readonly<MdastTarget>): number | undefined;
|
|
83
117
|
report({ message, node, severity, }: {
|
|
84
118
|
message: string;
|
|
85
|
-
node?: Readonly<
|
|
119
|
+
node?: Readonly<MdastTarget>;
|
|
86
120
|
severity?: "error" | "warning" | "info";
|
|
87
121
|
}): void;
|
|
88
122
|
/** Get the binary command buffer for all mutations recorded via context methods. */
|
|
89
123
|
getCommandBuffer(): CommandBuffer;
|
|
90
124
|
getDiagnostics(): MdastDiagnostic[];
|
|
91
125
|
}
|
|
92
|
-
type MdastVisitorResult = MdastNode |
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
rawHtml: string;
|
|
96
|
-
} | undefined | null | void;
|
|
97
|
-
type MdastVisitorFn<N extends MdastNode = MdastNode> = (node: Readonly<N>, context: MdastVisitorContext) => MdastVisitorResult | Promise<MdastVisitorResult>;
|
|
126
|
+
type MdastVisitorResult = MdastNode | RawMdastContent | RawHtmlMdastContent | undefined | null | void;
|
|
127
|
+
type MdastVisitorFn<N extends MdastNode | Custom = MdastNode> = (node: Readonly<N>, context: MdastVisitorContext) => MdastVisitorResult | Promise<MdastVisitorResult>;
|
|
128
|
+
export type MdastHookFn = (root: Readonly<MdastRoot>, context: MdastVisitorContext) => void | Promise<void>;
|
|
98
129
|
export interface MdastPluginInstance {
|
|
130
|
+
/** Plugin-level configuration (e.g. `{ position: true }` to read positions). */
|
|
131
|
+
options?: PluginOptions;
|
|
132
|
+
/** Runs once per document, before the plugin's visitors. Awaited when async. */
|
|
133
|
+
before?: MdastHookFn;
|
|
134
|
+
/** Runs once per document, after the plugin's visitors have settled. Awaited
|
|
135
|
+
* when async. */
|
|
136
|
+
after?: MdastHookFn;
|
|
99
137
|
paragraph?: MdastVisitorFn<Paragraph>;
|
|
100
138
|
heading?: MdastVisitorFn<Heading>;
|
|
101
139
|
thematicBreak?: MdastVisitorFn<ThematicBreak>;
|
|
@@ -129,11 +167,17 @@ export interface MdastPluginInstance {
|
|
|
129
167
|
textDirective?: MdastVisitorFn<TextDirective>;
|
|
130
168
|
superscript?: MdastVisitorFn<Superscript>;
|
|
131
169
|
subscript?: MdastVisitorFn<Subscript>;
|
|
170
|
+
descriptionList?: MdastVisitorFn<DescriptionList>;
|
|
171
|
+
descriptionTerm?: MdastVisitorFn<DescriptionTerm>;
|
|
172
|
+
descriptionDetails?: MdastVisitorFn<DescriptionDetails>;
|
|
132
173
|
mdxJsxFlowElement?: MdastVisitorFn<MdxJsxFlowElement>;
|
|
133
174
|
mdxJsxTextElement?: MdastVisitorFn<MdxJsxTextElement>;
|
|
134
175
|
mdxFlowExpression?: MdastVisitorFn<MdxFlowExpression>;
|
|
135
176
|
mdxTextExpression?: MdastVisitorFn<MdxTextExpression>;
|
|
136
177
|
mdxjsEsm?: MdastVisitorFn<MdxjsEsm>;
|
|
178
|
+
/** Fires for every user-defined node (any node created with a `type` outside
|
|
179
|
+
* the built-in set). Discriminate with `node.type`. */
|
|
180
|
+
custom?: MdastVisitorFn<Custom>;
|
|
137
181
|
}
|
|
138
182
|
interface MdastVisitResult {
|
|
139
183
|
/** Binary command buffer containing all mutations. */
|
|
@@ -154,4 +198,7 @@ export declare function resolveMdastSubscriptions(plugin: MdastPluginInstance):
|
|
|
154
198
|
* Returns MdastVisitResult synchronously if all visitors are sync,
|
|
155
199
|
* or Promise<MdastVisitResult> if any visitor is async.
|
|
156
200
|
*/
|
|
157
|
-
export declare function visitMdastHandle(handle: MdastHandle, plugin: MdastPluginInstance, subs: MdastSubscription[], source: string | (() => string), fileURL: URL | undefined, data?: Data): MdastVisitResult | Promise<MdastVisitResult>;
|
|
201
|
+
export declare function visitMdastHandle(handle: MdastHandle, plugin: MdastPluginInstance, subs: MdastSubscription[], source: string | (() => string), fileURL: URL | undefined, data?: Data, sourceFormat?: SourceFormat, diagnostics?: MdastDiagnostic[]): MdastVisitResult | Promise<MdastVisitResult>;
|
|
202
|
+
/** Its own pass so the caller can apply what `before` queued before the
|
|
203
|
+
* visitors walk, and the visitors' mutations before `after` reads the tree. */
|
|
204
|
+
export declare function visitMdastHook(handle: MdastHandle, plugin: MdastPluginInstance, hook: MdastHookFn, source: string | (() => string), fileURL: URL | undefined, data?: Data, sourceFormat?: SourceFormat, diagnostics?: MdastDiagnostic[]): MdastVisitResult | Promise<MdastVisitResult>;
|