@minjun0219/mdwire 0.1.10 → 0.1.11
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 +20 -6
- package/bundler/mdwire.d.ts +42 -39
- package/bundler/mdwire_bg.js +51 -48
- package/bundler/mdwire_bg.wasm +0 -0
- package/js/events.d.ts +5 -5
- package/js/events.js +2 -2
- package/js/react.d.ts +10 -10
- package/js/react.js +15 -14
- package/node/mdwire.d.ts +42 -39
- package/node/mdwire.js +51 -48
- package/node/mdwire_bg.wasm +0 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ escaping rules, and its own length limit. Existing converters assume the input i
|
|
|
10
10
|
well-formed CommonMark and target one channel at a time. Neither assumption holds for
|
|
11
11
|
agent output.
|
|
12
12
|
|
|
13
|
-
**Status: v0.1.
|
|
13
|
+
**Status: v0.1.11.** Normalizing, rendering, splitting and streaming work for six
|
|
14
14
|
targets — Telegram HTML, Slack `markdown_text`, GitHub comments (GFM), Notion pages, plain text,
|
|
15
15
|
and HTML for the browser — from a Rust core, a CLI,
|
|
16
16
|
an npm package (WASM), and a Go port. See `SPEC.md` for what is in v0.1 and what was
|
|
@@ -171,13 +171,13 @@ Every release also carries its own artifacts, if you would rather not go through
|
|
|
171
171
|
|
|
172
172
|
```sh
|
|
173
173
|
# npm package (works under a bundler and in plain Node)
|
|
174
|
-
npm install https://github.com/minjun0219/mdwire/releases/download/v0.1.
|
|
174
|
+
npm install https://github.com/minjun0219/mdwire/releases/download/v0.1.11/mdwire-0.1.11.tgz
|
|
175
175
|
|
|
176
176
|
# CLI binary — pick your platform
|
|
177
|
-
curl -L https://github.com/minjun0219/mdwire/releases/download/v0.1.
|
|
178
|
-
curl -L https://github.com/minjun0219/mdwire/releases/download/v0.1.
|
|
179
|
-
curl -L https://github.com/minjun0219/mdwire/releases/download/v0.1.
|
|
180
|
-
curl -LO https://github.com/minjun0219/mdwire/releases/download/v0.1.
|
|
177
|
+
curl -L https://github.com/minjun0219/mdwire/releases/download/v0.1.11/mdwire-v0.1.11-aarch64-apple-darwin.tar.gz | tar xz # macOS, Apple silicon
|
|
178
|
+
curl -L https://github.com/minjun0219/mdwire/releases/download/v0.1.11/mdwire-v0.1.11-x86_64-unknown-linux-gnu.tar.gz | tar xz # Linux x86_64 (glibc)
|
|
179
|
+
curl -L https://github.com/minjun0219/mdwire/releases/download/v0.1.11/mdwire-v0.1.11-aarch64-unknown-linux-gnu.tar.gz | tar xz # Linux arm64 (glibc)
|
|
180
|
+
curl -LO https://github.com/minjun0219/mdwire/releases/download/v0.1.11/mdwire-v0.1.11-x86_64-pc-windows-msvc.zip # Windows x86_64
|
|
181
181
|
```
|
|
182
182
|
|
|
183
183
|
The release notes list a SHA-256 for every artifact — verify the download against it when installing by URL.
|
|
@@ -202,6 +202,20 @@ out := mdwire.RenderWith(input, mdwire.SlackMarkdown, mdwire.Options{})
|
|
|
202
202
|
log.Printf("%+v", out.Repairs)
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
+
## For coding agents
|
|
206
|
+
|
|
207
|
+
mdwire ships an [agent skill](skills/mdwire/SKILL.md) that tells a coding agent when to reach for it,
|
|
208
|
+
which channel and entry point to pick, and how to stream. It follows the Agent Skills format, so agents
|
|
209
|
+
that read `SKILL.md` can use it directly. In Claude Code it installs as a plugin:
|
|
210
|
+
|
|
211
|
+
```sh
|
|
212
|
+
/plugin marketplace add minjun0219/mdwire
|
|
213
|
+
/plugin install mdwire@mdwire
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The site also serves [`llms.txt`](https://mdwire.minjun.dev/llms.txt), and its pages register a WebMCP
|
|
217
|
+
tool, `mdwire_render`, so a browser agent on the site can run mdwire in the page.
|
|
218
|
+
|
|
205
219
|
## Building
|
|
206
220
|
|
|
207
221
|
```sh
|
package/bundler/mdwire.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/** Conversion options. Anything omitted uses the channel's default. */
|
|
5
5
|
export interface RenderOptions {
|
|
6
|
-
/**
|
|
6
|
+
/** Part size limit (in characters). Defaults to the channel's limit; for example, 4096 when sending plain to Telegram. Streaming does not split. */
|
|
7
7
|
limit?: number;
|
|
8
|
-
/**
|
|
8
|
+
/** Policy for the browser channel ("html"). The defaults are the most conservative. */
|
|
9
9
|
html?: {
|
|
10
|
-
/**
|
|
10
|
+
/** Line breaks inside a block. "br" (default) emits `<br>`; "space" lets the browser collapse them into spaces. */
|
|
11
11
|
lineBreaks?: "br" | "space";
|
|
12
|
-
/**
|
|
12
|
+
/** Images. "link" (default) loads nothing until clicked; "load" emits `<img>`. */
|
|
13
13
|
images?: "link" | "load";
|
|
14
|
-
/**
|
|
14
|
+
/** Schemes allowed in link and image URLs (without the colon). If given, only these are allowed. Default ["http","https","mailto"]. */
|
|
15
15
|
schemes?: string[];
|
|
16
16
|
};
|
|
17
17
|
}
|
|
@@ -19,133 +19,136 @@ export interface RenderOptions {
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* `renderWithReport
|
|
22
|
+
* The result of `renderWithReport`.
|
|
23
23
|
*/
|
|
24
24
|
export class Rendered {
|
|
25
25
|
private constructor();
|
|
26
26
|
free(): void;
|
|
27
27
|
[Symbol.dispose](): void;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* The parts. Just one if the text fit within the limit.
|
|
30
30
|
*/
|
|
31
31
|
readonly parts: string[];
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* What normalization repaired.
|
|
34
34
|
*/
|
|
35
35
|
readonly repairs: Repairs;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Counts of what normalization repaired and what was changed to fit the channel.
|
|
40
40
|
*/
|
|
41
41
|
export class Repairs {
|
|
42
42
|
private constructor();
|
|
43
43
|
free(): void;
|
|
44
44
|
[Symbol.dispose](): void;
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Emphasis left open at the end of a block, closed for you.
|
|
47
47
|
*/
|
|
48
48
|
closedEmphasis: number;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Code fences left open at the end of the document, closed for you.
|
|
51
51
|
*/
|
|
52
52
|
closedFence: number;
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Emphasis markers and `<url|text>` links rewritten in a different notation.
|
|
55
55
|
*/
|
|
56
56
|
convertedMarker: number;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Unmatched `**` markers that were dropped.
|
|
59
59
|
*/
|
|
60
60
|
droppedMarker: number;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Characters escaped because the channel would read them as syntax (GitHub's `\~`, `\<`, `\*`).
|
|
63
63
|
*/
|
|
64
64
|
escapedChar: number;
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
66
|
+
* Unmatched backtick runs, turned back into literal text.
|
|
67
67
|
*/
|
|
68
68
|
revertedCodeSpan: number;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* List bullets rewritten with a different symbol.
|
|
71
71
|
*/
|
|
72
72
|
rewrittenBullet: number;
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* Tables rewritten in a different shape from the source.
|
|
75
75
|
*/
|
|
76
76
|
rewrittenTable: number;
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
78
|
+
* Raw HTML stripped from the source (tags, comments, and `<br>` turned into line breaks).
|
|
79
79
|
*/
|
|
80
80
|
strippedHtml: number;
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
82
|
+
* Emphasis emitted differently because the channel would not read the marker in that position (GitHub's `<strong>`, Slack's U+2060).
|
|
83
83
|
*/
|
|
84
84
|
tagEmphasis: number;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
*
|
|
88
|
+
* Streaming converter.
|
|
89
89
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
90
|
+
* Push a chunk and it returns only what is safe to emit now. Markup cut off at the
|
|
91
|
+
* chunk boundary stays inside. This is what you want when appending tokens to the
|
|
92
|
+
* screen as they arrive.
|
|
92
93
|
*/
|
|
93
94
|
export class Streamer {
|
|
94
95
|
free(): void;
|
|
95
96
|
[Symbol.dispose](): void;
|
|
96
97
|
/**
|
|
97
|
-
*
|
|
98
|
+
* **To send what you have received so far as is, append this after it.**
|
|
98
99
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
100
|
+
* It does not touch the state, so streaming continues afterwards. Do not add it
|
|
101
|
+
* to the accumulated output itself; append it only right before sending. Use it
|
|
102
|
+
* when editing a message as tokens arrive.
|
|
101
103
|
*
|
|
102
104
|
* ```js
|
|
103
105
|
* acc += s.push(chunk);
|
|
104
|
-
* await edit(acc + s.closeOpen()); //
|
|
106
|
+
* await edit(acc + s.closeOpen()); // leave acc unchanged
|
|
105
107
|
* ```
|
|
106
108
|
*/
|
|
107
109
|
closeOpen(): string;
|
|
108
110
|
/**
|
|
109
|
-
*
|
|
111
|
+
* Input has ended. Emits what is left and closes open markup.
|
|
110
112
|
*/
|
|
111
113
|
finish(): string;
|
|
112
114
|
constructor(channel: string, options?: RenderOptions | null);
|
|
113
115
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
116
|
+
* **The tail that would follow the final output if input ended now.** It goes in the
|
|
117
|
+
* same place as `closeOpen`, but also draws what is being held back (open emphasis,
|
|
118
|
+
* table rows, code spans). This is the default when you redraw the whole message.
|
|
119
|
+
* It is a guess, so later chunks may change the shape. Check `revised()` after the end.
|
|
117
120
|
*
|
|
118
121
|
* ```js
|
|
119
122
|
* acc += s.push(chunk);
|
|
120
|
-
* await edit(acc + s.preview()); //
|
|
123
|
+
* await edit(acc + s.preview()); // call only when drawing (costs as much as the open block)
|
|
121
124
|
* acc += s.finish();
|
|
122
|
-
* if (s.revised()) await edit(acc); //
|
|
125
|
+
* if (s.revised()) await edit(acc); // skip if the last screen already is the final output
|
|
123
126
|
* ```
|
|
124
127
|
*/
|
|
125
128
|
preview(): string;
|
|
126
129
|
push(chunk: string): string;
|
|
127
130
|
/**
|
|
128
|
-
*
|
|
131
|
+
* What normalization has repaired so far. After `finish`, this covers the whole document.
|
|
129
132
|
*/
|
|
130
133
|
repairs(): Repairs;
|
|
131
134
|
/**
|
|
132
|
-
*
|
|
135
|
+
* Whether the final output differs from the last `preview()`. Check it after `finish`.
|
|
133
136
|
*/
|
|
134
137
|
revised(): boolean;
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
/**
|
|
138
|
-
*
|
|
141
|
+
* The channel's length limit (in characters). Exposed for callers that handle parts themselves.
|
|
139
142
|
*/
|
|
140
143
|
export function limit(channel: string): number;
|
|
141
144
|
|
|
142
145
|
/**
|
|
143
|
-
*
|
|
146
|
+
* Converts a complete document. Returns an array of parts; it has more than one when the text exceeds the limit.
|
|
144
147
|
*/
|
|
145
148
|
export function render(input: string, channel: string, options?: RenderOptions | null): string[];
|
|
146
149
|
|
|
147
150
|
/**
|
|
148
|
-
* [`render`]
|
|
149
|
-
*
|
|
151
|
+
* Like [`render`], but also returns **what normalization repaired**. Use it to log
|
|
152
|
+
* how often the model breaks formatting.
|
|
150
153
|
*/
|
|
151
154
|
export function renderWithReport(input: string, channel: string, options?: RenderOptions | null): Rendered;
|
package/bundler/mdwire_bg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `renderWithReport
|
|
2
|
+
* The result of `renderWithReport`.
|
|
3
3
|
*/
|
|
4
4
|
export class Rendered {
|
|
5
5
|
static __wrap(ptr) {
|
|
@@ -19,7 +19,7 @@ export class Rendered {
|
|
|
19
19
|
wasm.__wbg_rendered_free(ptr, 0);
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* The parts. Just one if the text fit within the limit.
|
|
23
23
|
* @returns {string[]}
|
|
24
24
|
*/
|
|
25
25
|
get parts() {
|
|
@@ -36,7 +36,7 @@ export class Rendered {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* What normalization repaired.
|
|
40
40
|
* @returns {Repairs}
|
|
41
41
|
*/
|
|
42
42
|
get repairs() {
|
|
@@ -47,7 +47,7 @@ export class Rendered {
|
|
|
47
47
|
if (Symbol.dispose) Rendered.prototype[Symbol.dispose] = Rendered.prototype.free;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Counts of what normalization repaired and what was changed to fit the channel.
|
|
51
51
|
*/
|
|
52
52
|
export class Repairs {
|
|
53
53
|
static __wrap(ptr) {
|
|
@@ -67,7 +67,7 @@ export class Repairs {
|
|
|
67
67
|
wasm.__wbg_repairs_free(ptr, 0);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Emphasis left open at the end of a block, closed for you.
|
|
71
71
|
* @returns {number}
|
|
72
72
|
*/
|
|
73
73
|
get closedEmphasis() {
|
|
@@ -75,7 +75,7 @@ export class Repairs {
|
|
|
75
75
|
return ret >>> 0;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
78
|
+
* Code fences left open at the end of the document, closed for you.
|
|
79
79
|
* @returns {number}
|
|
80
80
|
*/
|
|
81
81
|
get closedFence() {
|
|
@@ -83,7 +83,7 @@ export class Repairs {
|
|
|
83
83
|
return ret >>> 0;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
86
|
+
* Emphasis markers and `<url|text>` links rewritten in a different notation.
|
|
87
87
|
* @returns {number}
|
|
88
88
|
*/
|
|
89
89
|
get convertedMarker() {
|
|
@@ -91,7 +91,7 @@ export class Repairs {
|
|
|
91
91
|
return ret >>> 0;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
*
|
|
94
|
+
* Unmatched `**` markers that were dropped.
|
|
95
95
|
* @returns {number}
|
|
96
96
|
*/
|
|
97
97
|
get droppedMarker() {
|
|
@@ -99,7 +99,7 @@ export class Repairs {
|
|
|
99
99
|
return ret >>> 0;
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
102
|
+
* Characters escaped because the channel would read them as syntax (GitHub's `\~`, `\<`, `\*`).
|
|
103
103
|
* @returns {number}
|
|
104
104
|
*/
|
|
105
105
|
get escapedChar() {
|
|
@@ -107,7 +107,7 @@ export class Repairs {
|
|
|
107
107
|
return ret >>> 0;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
110
|
+
* Unmatched backtick runs, turned back into literal text.
|
|
111
111
|
* @returns {number}
|
|
112
112
|
*/
|
|
113
113
|
get revertedCodeSpan() {
|
|
@@ -115,7 +115,7 @@ export class Repairs {
|
|
|
115
115
|
return ret >>> 0;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
|
-
*
|
|
118
|
+
* List bullets rewritten with a different symbol.
|
|
119
119
|
* @returns {number}
|
|
120
120
|
*/
|
|
121
121
|
get rewrittenBullet() {
|
|
@@ -123,7 +123,7 @@ export class Repairs {
|
|
|
123
123
|
return ret >>> 0;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
126
|
+
* Tables rewritten in a different shape from the source.
|
|
127
127
|
* @returns {number}
|
|
128
128
|
*/
|
|
129
129
|
get rewrittenTable() {
|
|
@@ -131,7 +131,7 @@ export class Repairs {
|
|
|
131
131
|
return ret >>> 0;
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
|
-
*
|
|
134
|
+
* Raw HTML stripped from the source (tags, comments, and `<br>` turned into line breaks).
|
|
135
135
|
* @returns {number}
|
|
136
136
|
*/
|
|
137
137
|
get strippedHtml() {
|
|
@@ -139,7 +139,7 @@ export class Repairs {
|
|
|
139
139
|
return ret >>> 0;
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
142
|
+
* Emphasis emitted differently because the channel would not read the marker in that position (GitHub's `<strong>`, Slack's U+2060).
|
|
143
143
|
* @returns {number}
|
|
144
144
|
*/
|
|
145
145
|
get tagEmphasis() {
|
|
@@ -147,70 +147,70 @@ export class Repairs {
|
|
|
147
147
|
return ret >>> 0;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
150
|
+
* Emphasis left open at the end of a block, closed for you.
|
|
151
151
|
* @param {number} arg0
|
|
152
152
|
*/
|
|
153
153
|
set closedEmphasis(arg0) {
|
|
154
154
|
wasm.__wbg_set_repairs_closedEmphasis(this.__wbg_ptr, arg0);
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* Code fences left open at the end of the document, closed for you.
|
|
158
158
|
* @param {number} arg0
|
|
159
159
|
*/
|
|
160
160
|
set closedFence(arg0) {
|
|
161
161
|
wasm.__wbg_set_repairs_closedFence(this.__wbg_ptr, arg0);
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
164
|
+
* Emphasis markers and `<url|text>` links rewritten in a different notation.
|
|
165
165
|
* @param {number} arg0
|
|
166
166
|
*/
|
|
167
167
|
set convertedMarker(arg0) {
|
|
168
168
|
wasm.__wbg_set_repairs_convertedMarker(this.__wbg_ptr, arg0);
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
|
-
*
|
|
171
|
+
* Unmatched `**` markers that were dropped.
|
|
172
172
|
* @param {number} arg0
|
|
173
173
|
*/
|
|
174
174
|
set droppedMarker(arg0) {
|
|
175
175
|
wasm.__wbg_set_repairs_droppedMarker(this.__wbg_ptr, arg0);
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
|
-
*
|
|
178
|
+
* Characters escaped because the channel would read them as syntax (GitHub's `\~`, `\<`, `\*`).
|
|
179
179
|
* @param {number} arg0
|
|
180
180
|
*/
|
|
181
181
|
set escapedChar(arg0) {
|
|
182
182
|
wasm.__wbg_set_repairs_escapedChar(this.__wbg_ptr, arg0);
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
|
-
*
|
|
185
|
+
* Unmatched backtick runs, turned back into literal text.
|
|
186
186
|
* @param {number} arg0
|
|
187
187
|
*/
|
|
188
188
|
set revertedCodeSpan(arg0) {
|
|
189
189
|
wasm.__wbg_set_repairs_revertedCodeSpan(this.__wbg_ptr, arg0);
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
|
-
*
|
|
192
|
+
* List bullets rewritten with a different symbol.
|
|
193
193
|
* @param {number} arg0
|
|
194
194
|
*/
|
|
195
195
|
set rewrittenBullet(arg0) {
|
|
196
196
|
wasm.__wbg_set_repairs_rewrittenBullet(this.__wbg_ptr, arg0);
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
199
|
-
*
|
|
199
|
+
* Tables rewritten in a different shape from the source.
|
|
200
200
|
* @param {number} arg0
|
|
201
201
|
*/
|
|
202
202
|
set rewrittenTable(arg0) {
|
|
203
203
|
wasm.__wbg_set_repairs_rewrittenTable(this.__wbg_ptr, arg0);
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
|
-
*
|
|
206
|
+
* Raw HTML stripped from the source (tags, comments, and `<br>` turned into line breaks).
|
|
207
207
|
* @param {number} arg0
|
|
208
208
|
*/
|
|
209
209
|
set strippedHtml(arg0) {
|
|
210
210
|
wasm.__wbg_set_repairs_strippedHtml(this.__wbg_ptr, arg0);
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
|
-
*
|
|
213
|
+
* Emphasis emitted differently because the channel would not read the marker in that position (GitHub's `<strong>`, Slack's U+2060).
|
|
214
214
|
* @param {number} arg0
|
|
215
215
|
*/
|
|
216
216
|
set tagEmphasis(arg0) {
|
|
@@ -220,10 +220,11 @@ export class Repairs {
|
|
|
220
220
|
if (Symbol.dispose) Repairs.prototype[Symbol.dispose] = Repairs.prototype.free;
|
|
221
221
|
|
|
222
222
|
/**
|
|
223
|
-
*
|
|
223
|
+
* Streaming converter.
|
|
224
224
|
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
225
|
+
* Push a chunk and it returns only what is safe to emit now. Markup cut off at the
|
|
226
|
+
* chunk boundary stays inside. This is what you want when appending tokens to the
|
|
227
|
+
* screen as they arrive.
|
|
227
228
|
*/
|
|
228
229
|
export class Streamer {
|
|
229
230
|
__destroy_into_raw() {
|
|
@@ -237,14 +238,15 @@ export class Streamer {
|
|
|
237
238
|
wasm.__wbg_streamer_free(ptr, 0);
|
|
238
239
|
}
|
|
239
240
|
/**
|
|
240
|
-
*
|
|
241
|
+
* **To send what you have received so far as is, append this after it.**
|
|
241
242
|
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
243
|
+
* It does not touch the state, so streaming continues afterwards. Do not add it
|
|
244
|
+
* to the accumulated output itself; append it only right before sending. Use it
|
|
245
|
+
* when editing a message as tokens arrive.
|
|
244
246
|
*
|
|
245
247
|
* ```js
|
|
246
248
|
* acc += s.push(chunk);
|
|
247
|
-
* await edit(acc + s.closeOpen()); //
|
|
249
|
+
* await edit(acc + s.closeOpen()); // leave acc unchanged
|
|
248
250
|
* ```
|
|
249
251
|
* @returns {string}
|
|
250
252
|
*/
|
|
@@ -265,7 +267,7 @@ export class Streamer {
|
|
|
265
267
|
}
|
|
266
268
|
}
|
|
267
269
|
/**
|
|
268
|
-
*
|
|
270
|
+
* Input has ended. Emits what is left and closes open markup.
|
|
269
271
|
* @returns {string}
|
|
270
272
|
*/
|
|
271
273
|
finish() {
|
|
@@ -308,15 +310,16 @@ export class Streamer {
|
|
|
308
310
|
}
|
|
309
311
|
}
|
|
310
312
|
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
313
|
+
* **The tail that would follow the final output if input ended now.** It goes in the
|
|
314
|
+
* same place as `closeOpen`, but also draws what is being held back (open emphasis,
|
|
315
|
+
* table rows, code spans). This is the default when you redraw the whole message.
|
|
316
|
+
* It is a guess, so later chunks may change the shape. Check `revised()` after the end.
|
|
314
317
|
*
|
|
315
318
|
* ```js
|
|
316
319
|
* acc += s.push(chunk);
|
|
317
|
-
* await edit(acc + s.preview()); //
|
|
320
|
+
* await edit(acc + s.preview()); // call only when drawing (costs as much as the open block)
|
|
318
321
|
* acc += s.finish();
|
|
319
|
-
* if (s.revised()) await edit(acc); //
|
|
322
|
+
* if (s.revised()) await edit(acc); // skip if the last screen already is the final output
|
|
320
323
|
* ```
|
|
321
324
|
* @returns {string}
|
|
322
325
|
*/
|
|
@@ -359,7 +362,7 @@ export class Streamer {
|
|
|
359
362
|
}
|
|
360
363
|
}
|
|
361
364
|
/**
|
|
362
|
-
*
|
|
365
|
+
* What normalization has repaired so far. After `finish`, this covers the whole document.
|
|
363
366
|
* @returns {Repairs}
|
|
364
367
|
*/
|
|
365
368
|
repairs() {
|
|
@@ -367,7 +370,7 @@ export class Streamer {
|
|
|
367
370
|
return Repairs.__wrap(ret);
|
|
368
371
|
}
|
|
369
372
|
/**
|
|
370
|
-
*
|
|
373
|
+
* Whether the final output differs from the last `preview()`. Check it after `finish`.
|
|
371
374
|
* @returns {boolean}
|
|
372
375
|
*/
|
|
373
376
|
revised() {
|
|
@@ -378,7 +381,7 @@ export class Streamer {
|
|
|
378
381
|
if (Symbol.dispose) Streamer.prototype[Symbol.dispose] = Streamer.prototype.free;
|
|
379
382
|
|
|
380
383
|
/**
|
|
381
|
-
*
|
|
384
|
+
* The channel's length limit (in characters). Exposed for callers that handle parts themselves.
|
|
382
385
|
* @param {string} channel
|
|
383
386
|
* @returns {number}
|
|
384
387
|
*/
|
|
@@ -401,7 +404,7 @@ export function limit(channel) {
|
|
|
401
404
|
}
|
|
402
405
|
|
|
403
406
|
/**
|
|
404
|
-
*
|
|
407
|
+
* Converts a complete document. Returns an array of parts; it has more than one when the text exceeds the limit.
|
|
405
408
|
* @param {string} input
|
|
406
409
|
* @param {string} channel
|
|
407
410
|
* @param {RenderOptions | null} [options]
|
|
@@ -431,8 +434,8 @@ export function render(input, channel, options) {
|
|
|
431
434
|
}
|
|
432
435
|
|
|
433
436
|
/**
|
|
434
|
-
* [`render`]
|
|
435
|
-
*
|
|
437
|
+
* Like [`render`], but also returns **what normalization repaired**. Use it to log
|
|
438
|
+
* how often the model breaks formatting.
|
|
436
439
|
* @param {string} input
|
|
437
440
|
* @param {string} channel
|
|
438
441
|
* @param {RenderOptions | null} [options]
|
|
@@ -472,30 +475,30 @@ export function __wbg___wbindgen_string_get_92ab86bb19cbc12f(arg0, arg1) {
|
|
|
472
475
|
export function __wbg___wbindgen_throw_5d9e815e6fdf150f(arg0, arg1) {
|
|
473
476
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
474
477
|
}
|
|
475
|
-
export function
|
|
478
|
+
export function __wbg_html_89b49615556b2850(arg0) {
|
|
476
479
|
const ret = getObject(arg0).html;
|
|
477
480
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
478
481
|
}
|
|
479
|
-
export function
|
|
482
|
+
export function __wbg_images_fc88426d1f55bdfc(arg0, arg1) {
|
|
480
483
|
const ret = getObject(arg1).images;
|
|
481
484
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
482
485
|
var len1 = WASM_VECTOR_LEN;
|
|
483
486
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
484
487
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
485
488
|
}
|
|
486
|
-
export function
|
|
489
|
+
export function __wbg_limit_d1453e73fbf788db(arg0, arg1) {
|
|
487
490
|
const ret = getObject(arg1).limit;
|
|
488
491
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
489
492
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
490
493
|
}
|
|
491
|
-
export function
|
|
494
|
+
export function __wbg_lineBreaks_8b98689e9716a2c8(arg0, arg1) {
|
|
492
495
|
const ret = getObject(arg1).lineBreaks;
|
|
493
496
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
494
497
|
var len1 = WASM_VECTOR_LEN;
|
|
495
498
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
496
499
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
497
500
|
}
|
|
498
|
-
export function
|
|
501
|
+
export function __wbg_schemes_8e39175723a07726(arg0, arg1) {
|
|
499
502
|
const ret = getObject(arg1).schemes;
|
|
500
503
|
var ptr1 = isLikeNone(ret) ? 0 : passArrayJsValueToWasm0(ret, wasm.__wbindgen_export);
|
|
501
504
|
var len1 = WASM_VECTOR_LEN;
|
package/bundler/mdwire_bg.wasm
CHANGED
|
Binary file
|
package/js/events.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/** mdwire html
|
|
1
|
+
/** Tags that appear in mdwire's html output. */
|
|
2
2
|
export type MdTag =
|
|
3
3
|
| "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "ul" | "ol" | "li" | "blockquote" | "pre" | "code"
|
|
4
4
|
| "strong" | "em" | "del" | "a" | "table" | "thead" | "tbody" | "tr" | "th" | "td" | "hr" | "br"
|
|
5
5
|
| "sub" | "sup" | "b" | "i" | "u" | "s" | "strike" | "span" | "small" | "mark" | "kbd" | "ins" | "img";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
8
|
+
* A single event. Attributes hold only what the core emits:
|
|
9
|
+
* `href` on `a`, `class` on `code` (`language-…`), `style` on `th` and `td` (`text-align:…`), `start` on `ol`.
|
|
10
10
|
*/
|
|
11
11
|
export type MdEvent =
|
|
12
12
|
| { type: "open"; tag: MdTag; attrs: Record<string, string> }
|
|
13
13
|
| { type: "close"; tag: MdTag }
|
|
14
14
|
| { type: "void"; tag: "br" | "hr" }
|
|
15
|
-
/**
|
|
15
|
+
/** Images appear only with `html.images: "load"`. Holds `src` and `alt`. */
|
|
16
16
|
| { type: "void"; tag: "img"; attrs: Record<string, string> }
|
|
17
17
|
| { type: "text"; text: string };
|
|
18
18
|
|
|
19
|
-
/** html
|
|
19
|
+
/** Parses html channel output (or the accumulated stream output + `closeOpen()`) into an array of events. */
|
|
20
20
|
export function toEvents(html: string): MdEvent[];
|
package/js/events.js
CHANGED
|
@@ -18,8 +18,8 @@ const ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"' };
|
|
|
18
18
|
const decode = (s) => s.replace(/&(amp|lt|gt|quot);/g, (_, n) => ENTITIES[n]);
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* html
|
|
22
|
-
* @param {string} html `render(text, "html")
|
|
21
|
+
* Converts html channel output into an array of events.
|
|
22
|
+
* @param {string} html The result of `render(text, "html")`, or the accumulated stream output + `closeOpen()`.
|
|
23
23
|
* @returns {import("./events.d.ts").MdEvent[]}
|
|
24
24
|
*/
|
|
25
25
|
export function toEvents(html) {
|