ovr 7.0.0-next.32 → 7.0.0-next.34
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/CHANGELOG.md +18 -0
- package/dist/context/index.d.ts +2 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +6 -6
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/jsx/index.d.ts +2 -2
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/markdown/index.d.ts +7 -27
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +20 -37
- package/dist/markup/index.d.ts +9 -26
- package/dist/markup/index.d.ts.map +1 -1
- package/dist/markup/index.js +14 -28
- package/dist/render/index.d.ts +96 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +70 -0
- package/package.json +1 -1
- package/src/context/index.ts +6 -6
- package/src/index.ts +1 -2
- package/src/jsx/index.ts +2 -2
- package/src/markdown/index.ts +26 -41
- package/src/markup/index.ts +18 -39
- package/src/render/index.ts +124 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# ovr
|
|
2
2
|
|
|
3
|
+
## 7.0.0-next.34
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3906e66: `Render` is the one export for rendering, in place of `Markup` and `Markdown`:
|
|
8
|
+
|
|
9
|
+
- `Render.raw({ html, markdown })` writes what is already rendered, for `Markup.raw(html)` and `Markdown.raw(markdown, html)`. With only `html`, agents get the markup too; with only `markdown`, the page shows nothing; and an empty `markdown` hides the markup from agents.
|
|
10
|
+
- `Render.markup(element, options)` and `Render.markdown(element, options)` return a render: an async iterable with `stream()` and `string()`, for `new Markup(element)`, `Markup.stream(element)`, `Markup.string(element)`, and the same of `Markdown`.
|
|
11
|
+
- `Render.escape(text)` for `Markup.escape(text)`.
|
|
12
|
+
- The types are `Render.Chunk`, `Render.Markup.Options`, and `Render.Markdown.Options`.
|
|
13
|
+
- `c.markdown(body)` for `c.md(body)`.
|
|
14
|
+
|
|
15
|
+
## 7.0.0-next.33
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- c5defc5: `Markdown.raw(markdown, html)` with one line of source stays in its line, such as a separator only agents read, `Markdown.raw(" · ", "")`, inside a list item. It was always its own block, which broke the line apart anywhere but a paragraph. Source of several lines, or whose HTML starts with a block element, is still its own block.
|
|
20
|
+
|
|
3
21
|
## 7.0.0-next.32
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/context/index.d.ts
CHANGED
|
@@ -142,7 +142,7 @@ export declare class Context<Params extends Record<string, unknown> = Record<str
|
|
|
142
142
|
* that is a Markdown document, so agents read its source.
|
|
143
143
|
*
|
|
144
144
|
* ```tsx
|
|
145
|
-
* if (c.
|
|
145
|
+
* if (c.markdown(post.body)) return;
|
|
146
146
|
*
|
|
147
147
|
* return <Post post={post} />;
|
|
148
148
|
* ```
|
|
@@ -151,7 +151,7 @@ export declare class Context<Params extends Record<string, unknown> = Record<str
|
|
|
151
151
|
* @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
152
152
|
* @returns `true` if it responded, otherwise the page renders for the browser
|
|
153
153
|
*/
|
|
154
|
-
|
|
154
|
+
markdown(body: BodyInit | null, status?: number): boolean;
|
|
155
155
|
/**
|
|
156
156
|
* Creates a redirect response.
|
|
157
157
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,KAAK,EAA6B,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,QAAQ,EA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AAG,GAAG,GAAS,QAQzC;IAED;;;;;;;;OAQG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,WAalB;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,aAEpC;IAED;;;;;;;;;;;OAWG;IACH,OAAO,oCAIN;IAED;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAgEtE;IAqGD;;;;;;OAMG;IACH,OAAa,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,qBAoBxD;CACD"}
|
package/dist/context/index.js
CHANGED
|
@@ -116,7 +116,7 @@ export class Context {
|
|
|
116
116
|
* that is a Markdown document, so agents read its source.
|
|
117
117
|
*
|
|
118
118
|
* ```tsx
|
|
119
|
-
* if (c.
|
|
119
|
+
* if (c.markdown(post.body)) return;
|
|
120
120
|
*
|
|
121
121
|
* return <Post post={post} />;
|
|
122
122
|
* ```
|
|
@@ -125,7 +125,7 @@ export class Context {
|
|
|
125
125
|
* @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
126
126
|
* @returns `true` if it responded, otherwise the page renders for the browser
|
|
127
127
|
*/
|
|
128
|
-
|
|
128
|
+
markdown(body, status) {
|
|
129
129
|
if (!this.#markdown())
|
|
130
130
|
return false;
|
|
131
131
|
this.#respond(body, status, Header.utf8(Mime.type.md));
|
|
@@ -328,18 +328,18 @@ export class Context {
|
|
|
328
328
|
// for both
|
|
329
329
|
if (!/^\s*attachment/i.test(res.headers.get("content-disposition") ?? "") &&
|
|
330
330
|
this.#markdown()) {
|
|
331
|
-
res.body = Markdown
|
|
331
|
+
res.body = new Markdown(r, {
|
|
332
332
|
base: this.url,
|
|
333
333
|
[tools]: agent.get(this.req)?.tool,
|
|
334
|
-
});
|
|
334
|
+
}).stream();
|
|
335
335
|
res.headers.set(Header.name.type, Header.utf8(Mime.type.md));
|
|
336
336
|
return;
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
|
-
res.body = Markup
|
|
339
|
+
res.body = new Markup(r, {
|
|
340
340
|
// other defined types are not markup, so they are not escaped
|
|
341
341
|
raw: Boolean(mime && !Mime.markup(mime)),
|
|
342
|
-
});
|
|
342
|
+
}).stream();
|
|
343
343
|
if (!mime) {
|
|
344
344
|
// default to HTML
|
|
345
345
|
res.headers.set(Header.name.type, Header.utf8(Mime.type.html));
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,7 @@ export { Mcp } from "./mcp/index.js";
|
|
|
6
6
|
export type { JSX } from "./jsx/index.js";
|
|
7
7
|
export type { Middleware } from "./middleware/index.js";
|
|
8
8
|
export { Multipart } from "./multipart/index.js";
|
|
9
|
-
export {
|
|
10
|
-
export { Markdown } from "./markdown/index.js";
|
|
9
|
+
export { Render } from "./render/index.js";
|
|
11
10
|
export { Route } from "./route/index.js";
|
|
12
11
|
export { Table } from "./table/index.js";
|
|
13
12
|
export { Field } from "./form/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,7 @@ export { Database } from "./database/index.js";
|
|
|
4
4
|
export { Limiter } from "./limiter/index.js";
|
|
5
5
|
export { Mcp } from "./mcp/index.js";
|
|
6
6
|
export { Multipart } from "./multipart/index.js";
|
|
7
|
-
export {
|
|
8
|
-
export { Markdown } from "./markdown/index.js";
|
|
7
|
+
export { Render } from "./render/index.js";
|
|
9
8
|
export { Route } from "./route/index.js";
|
|
10
9
|
export { Table } from "./table/index.js";
|
|
11
10
|
export { Field } from "./form/index.js";
|
package/dist/jsx/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Chunk } from "../markup/index.js";
|
|
2
2
|
import type { IntrinsicElements as IE } from "./elements.js";
|
|
3
3
|
export declare namespace JSX {
|
|
4
4
|
/**
|
|
@@ -39,7 +39,7 @@ export declare class JSX {
|
|
|
39
39
|
* @param props object containing all the properties and attributes passed to the element or component
|
|
40
40
|
* @returns Generator of the element's `Chunk`s of HTML
|
|
41
41
|
*/
|
|
42
|
-
static jsx<P extends JSX.Props = JSX.Props>(tag: ((props: P) => JSX.Element) | string, props: P): AsyncGenerator<
|
|
42
|
+
static jsx<P extends JSX.Props = JSX.Props>(tag: ((props: P) => JSX.Element) | string, props: P): AsyncGenerator<Chunk, void, unknown>;
|
|
43
43
|
/**
|
|
44
44
|
* JSX requires a `Fragment` export to resolve `<></>`
|
|
45
45
|
*
|
package/dist/jsx/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAW,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,IAAI,EAAE,EAAE,MAAM,eAAe,CAAC;AAE7D,yBAAiB,GAAG,CAAC;IACpB;;;;OAIG;IACH,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtC;;;;OAIG;IACH,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAEtC,6BAA6B;IAC7B,MAAM,WAAW,iBAAkB,SAAQ,EAAE;KAAG;IAEhD,kBAAkB;IAClB,MAAM,MAAM,OAAO,GAAG,aAAa,CAClC,YAAY,CACT,MAAM,GACN,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,IAAI,GACJ,SAAS,GACT,MAAM,GACN,QAAQ,CAAC,OAAO,CAAC,GACjB,aAAa,CAAC,OAAO,CAAC,CACxB,CACD,CAAC;IAEF,8BAA8B;IAC9B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAEhD;;;;OAIG;IACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC;;CAC7D;AAED,cAAc;AACd,qBAAa,GAAG;IACf;;;;;;;;OAQG;IACH,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,EACzC,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,MAAM,EACzC,KAAK,EAAE,CAAC,GACN,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAMtC;IAED;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;KAAE,eAEhD;CACD;AAED,eAAO,MAAQ,GAAG,kBAAE,QAAQ,qBAAQ,CAAC"}
|
package/dist/markdown/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { JSX } from "../jsx/index.js";
|
|
2
|
-
import { type Markup } from "../markup/index.js";
|
|
3
2
|
/** Internal protocol for the MCP endpoint, to write a form as its tool's call. */
|
|
4
3
|
export declare const tools: unique symbol;
|
|
5
4
|
export declare namespace Markdown {
|
|
@@ -30,12 +29,13 @@ export declare namespace Markdown {
|
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* Renders an element to Markdown, as an `AsyncIterable` of blocks, a stream,
|
|
33
|
-
* or a string, from the same elements `Markup` renders.
|
|
32
|
+
* or a string, from the same elements `Markup` renders. Made with
|
|
33
|
+
* `Render.markdown`. Each top level block is
|
|
34
34
|
* written as soon as it closes, and when the page has a `<main>` element, only
|
|
35
35
|
* its contents are kept. Raw HTML is written as it is.
|
|
36
36
|
*
|
|
37
37
|
* ```tsx
|
|
38
|
-
* const markdown = await
|
|
38
|
+
* const markdown = await Render.markdown(<Post post={post} />, { base: url }).string();
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
export declare class Markdown {
|
|
@@ -49,33 +49,13 @@ export declare class Markdown {
|
|
|
49
49
|
constructor(element: JSX.Element, options?: Markdown.Options);
|
|
50
50
|
/** @yields Markdown as each block completes */
|
|
51
51
|
[Symbol.asyncIterator](): AsyncGenerator<string, void, unknown>;
|
|
52
|
+
/** @returns `ReadableStream` of Markdown */
|
|
53
|
+
stream(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
52
54
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param options Markdown options
|
|
55
|
-
* @returns `ReadableStream` of Markdown
|
|
56
|
-
*/
|
|
57
|
-
static stream(element: JSX.Element, options?: Markdown.Options): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
58
|
-
/**
|
|
59
|
-
* Converts a render into a fully concatenated string of Markdown.
|
|
55
|
+
* The whole render as one string.
|
|
60
56
|
*
|
|
61
|
-
* @param element Element to render
|
|
62
|
-
* @param options Markdown options
|
|
63
57
|
* @returns Concatenated Markdown
|
|
64
58
|
*/
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Markdown source with the HTML it renders to, such as steps written in
|
|
68
|
-
* Markdown. Pages show the HTML, and agents reading the page as Markdown
|
|
69
|
-
* get the source. Neither is escaped, so both must be safe.
|
|
70
|
-
*
|
|
71
|
-
* ```tsx
|
|
72
|
-
* <section>{Markdown.raw(recipe.steps, render(recipe.steps))}</section>
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* @param markdown Markdown source
|
|
76
|
-
* @param html Safe HTML it renders to
|
|
77
|
-
* @returns New _safe_ chunk
|
|
78
|
-
*/
|
|
79
|
-
static raw(markdown: unknown, html: unknown): Markup.Chunk;
|
|
59
|
+
string(): Promise<string>;
|
|
80
60
|
}
|
|
81
61
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAiD3C,kFAAkF;AAClF,eAAO,MAAM,KAAK,eAAkB,CAAC;AAErC,yBAAiB,QAAQ,CAAC;IACzB,kCAAkC;IAClC,KAAY,OAAO,GAAG;QACrB,wEAAwE;QACxE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC;QAEzC;;;;;;;;;;;;WAYG;QACH,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EACd,CAAC,CACD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,GAAG,KAET;YACA,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC7B,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAC7B,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;SAC1B,GACD,SAAS,CAAC,GACZ,SAAS,CAAC;KACb,CAAC;CACF;AA41CD;;;;;;;;;;GAUG;AACH,qBAAa,QAAQ;;IAOpB;;;;;OAKG;IACH,YAAY,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,EAG3D;IAED,+CAA+C;IACxC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAWrE;IAED,4CAA4C;IAC5C,MAAM,gDAEL;IAED;;;;OAIG;IACG,MAAM,oBAcX;CACD"}
|
package/dist/markdown/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Group,
|
|
1
|
+
import { Group, Renderer, Source, Tag, readable, } from "../markup/index.js";
|
|
2
2
|
/** Internal protocol for the MCP endpoint, to write a form as its tool's call. */
|
|
3
3
|
export const tools = Symbol("tools");
|
|
4
4
|
/** Writes Markdown from rendered chunks, one block at a time */
|
|
@@ -133,7 +133,12 @@ class Writer {
|
|
|
133
133
|
this.#close(chunk.name);
|
|
134
134
|
}
|
|
135
135
|
else if (chunk instanceof Source)
|
|
136
|
-
this.#raw(chunk.markdown,
|
|
136
|
+
this.#raw(chunk.markdown,
|
|
137
|
+
// its own block when it is written as one, or stands for one. A
|
|
138
|
+
// line for a line, such as a separator only agents read, stays
|
|
139
|
+
// in its sentence
|
|
140
|
+
/\n/.test(chunk.markdown.trim()) ||
|
|
141
|
+
Writer.#rawBlock.test(String(chunk.value)));
|
|
137
142
|
else if (chunk.raw)
|
|
138
143
|
this.#raw(chunk.value);
|
|
139
144
|
else
|
|
@@ -157,12 +162,11 @@ class Writer {
|
|
|
157
162
|
parent.children.push(text);
|
|
158
163
|
}
|
|
159
164
|
/**
|
|
160
|
-
* Raw HTML, such as from `
|
|
161
|
-
* written as it is, as is Markdown
|
|
162
|
-
* always its own block.
|
|
165
|
+
* Raw HTML, such as from `Render.raw`, is valid Markdown, so it is
|
|
166
|
+
* written as it is, as is the Markdown it is given with.
|
|
163
167
|
*
|
|
164
168
|
* @param html HTML, or Markdown source
|
|
165
|
-
* @param source The text is Markdown source
|
|
169
|
+
* @param source The text is Markdown source that is its own block
|
|
166
170
|
*/
|
|
167
171
|
#raw(html, source) {
|
|
168
172
|
if (!html || this.#skipping)
|
|
@@ -1236,7 +1240,7 @@ class Blocks {
|
|
|
1236
1240
|
* @param options Markdown options
|
|
1237
1241
|
*/
|
|
1238
1242
|
constructor(element, options) {
|
|
1239
|
-
this.#render = new
|
|
1243
|
+
this.#render = new Renderer(element, undefined);
|
|
1240
1244
|
this.#writer = new Writer(options);
|
|
1241
1245
|
}
|
|
1242
1246
|
/**
|
|
@@ -1264,12 +1268,13 @@ class Blocks {
|
|
|
1264
1268
|
}
|
|
1265
1269
|
/**
|
|
1266
1270
|
* Renders an element to Markdown, as an `AsyncIterable` of blocks, a stream,
|
|
1267
|
-
* or a string, from the same elements `Markup` renders.
|
|
1271
|
+
* or a string, from the same elements `Markup` renders. Made with
|
|
1272
|
+
* `Render.markdown`. Each top level block is
|
|
1268
1273
|
* written as soon as it closes, and when the page has a `<main>` element, only
|
|
1269
1274
|
* its contents are kept. Raw HTML is written as it is.
|
|
1270
1275
|
*
|
|
1271
1276
|
* ```tsx
|
|
1272
|
-
* const markdown = await
|
|
1277
|
+
* const markdown = await Render.markdown(<Post post={post} />, { base: url }).string();
|
|
1273
1278
|
* ```
|
|
1274
1279
|
*/
|
|
1275
1280
|
export class Markdown {
|
|
@@ -1302,23 +1307,17 @@ export class Markdown {
|
|
|
1302
1307
|
await blocks.close();
|
|
1303
1308
|
}
|
|
1304
1309
|
}
|
|
1305
|
-
/**
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
* @returns `ReadableStream` of Markdown
|
|
1309
|
-
*/
|
|
1310
|
-
static stream(element, options) {
|
|
1311
|
-
return readable(new Blocks(element, options));
|
|
1310
|
+
/** @returns `ReadableStream` of Markdown */
|
|
1311
|
+
stream() {
|
|
1312
|
+
return readable(new Blocks(this.#element, this.#options));
|
|
1312
1313
|
}
|
|
1313
1314
|
/**
|
|
1314
|
-
*
|
|
1315
|
+
* The whole render as one string.
|
|
1315
1316
|
*
|
|
1316
|
-
* @param element Element to render
|
|
1317
|
-
* @param options Markdown options
|
|
1318
1317
|
* @returns Concatenated Markdown
|
|
1319
1318
|
*/
|
|
1320
|
-
|
|
1321
|
-
const blocks = new Blocks(element, options);
|
|
1319
|
+
async string() {
|
|
1320
|
+
const blocks = new Blocks(this.#element, this.#options);
|
|
1322
1321
|
let markdown = "";
|
|
1323
1322
|
try {
|
|
1324
1323
|
for (let result; (result = blocks.step());) {
|
|
@@ -1333,20 +1332,4 @@ export class Markdown {
|
|
|
1333
1332
|
}
|
|
1334
1333
|
return markdown;
|
|
1335
1334
|
}
|
|
1336
|
-
/**
|
|
1337
|
-
* Markdown source with the HTML it renders to, such as steps written in
|
|
1338
|
-
* Markdown. Pages show the HTML, and agents reading the page as Markdown
|
|
1339
|
-
* get the source. Neither is escaped, so both must be safe.
|
|
1340
|
-
*
|
|
1341
|
-
* ```tsx
|
|
1342
|
-
* <section>{Markdown.raw(recipe.steps, render(recipe.steps))}</section>
|
|
1343
|
-
* ```
|
|
1344
|
-
*
|
|
1345
|
-
* @param markdown Markdown source
|
|
1346
|
-
* @param html Safe HTML it renders to
|
|
1347
|
-
* @returns New _safe_ chunk
|
|
1348
|
-
*/
|
|
1349
|
-
static raw(markdown, html) {
|
|
1350
|
-
return new Source(markdown, html);
|
|
1351
|
-
}
|
|
1352
1335
|
}
|
package/dist/markup/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { JSX } from "../jsx/index.js";
|
|
2
2
|
/** Chunk of a rendered element: text, or markup */
|
|
3
|
-
declare class Chunk {
|
|
3
|
+
export declare class Chunk {
|
|
4
4
|
/** Text, or markup when `raw` */
|
|
5
5
|
readonly value: string;
|
|
6
6
|
/** `true` if the value is markup, which is not escaped */
|
|
@@ -38,7 +38,7 @@ export declare class Tag extends Chunk {
|
|
|
38
38
|
toString(): string;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
* Markup with
|
|
41
|
+
* Markup with the Markdown agents get in its place, from `Render.raw`, internal to ovr. It
|
|
42
42
|
* is written as its markup, and as its source in Markdown.
|
|
43
43
|
*/
|
|
44
44
|
export declare class Source extends Chunk {
|
|
@@ -95,7 +95,7 @@ export type Step = Chunk | Promise<unknown> | undefined;
|
|
|
95
95
|
* synchronous unless the element has to be waited for, so nested elements cost
|
|
96
96
|
* a loop instead of a generator and a promise for each chunk at every level.
|
|
97
97
|
*/
|
|
98
|
-
export declare class
|
|
98
|
+
export declare class Renderer {
|
|
99
99
|
#private;
|
|
100
100
|
/** Chunks rendered before the element is its parent's current child */
|
|
101
101
|
queue: Chunk[] | undefined;
|
|
@@ -129,22 +129,17 @@ export declare const readable: (render: {
|
|
|
129
129
|
step(): Chunk | string | Promise<unknown> | undefined;
|
|
130
130
|
close(): Promise<unknown>;
|
|
131
131
|
}) => ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
132
|
-
/** The class `Markup.Chunk` is named for */
|
|
133
|
-
type ChunkClass = Chunk;
|
|
134
132
|
export declare namespace Markup {
|
|
135
133
|
/** Markup options */
|
|
136
134
|
type Options = {
|
|
137
135
|
/** Set to `true` to disable escaping, for content that is not markup */
|
|
138
136
|
raw?: boolean;
|
|
139
137
|
};
|
|
140
|
-
/** Rendered `Chunk` instance, an interface so declaration files name it */
|
|
141
|
-
interface Chunk extends ChunkClass {
|
|
142
|
-
}
|
|
143
138
|
}
|
|
144
139
|
/**
|
|
145
140
|
* Renders an element to markup, such as HTML, SVG, or XML, as an
|
|
146
141
|
* `AsyncIterable` of strings, a stream, or a string. `Markdown` renders the
|
|
147
|
-
* same elements to Markdown.
|
|
142
|
+
* same elements to Markdown. Made with `Render.markup`.
|
|
148
143
|
*/
|
|
149
144
|
export declare class Markup {
|
|
150
145
|
#private;
|
|
@@ -160,34 +155,22 @@ export declare class Markup {
|
|
|
160
155
|
/** @yields Markup as the `Element` resolves */
|
|
161
156
|
[Symbol.asyncIterator](): AsyncGenerator<string, void, unknown>;
|
|
162
157
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
158
|
+
* The render piped into a `ReadableStream`. Iterate it when possible, to
|
|
159
|
+
* avoid the overhead of the stream.
|
|
165
160
|
*
|
|
166
|
-
* @param element Element to render
|
|
167
|
-
* @param options Markup options
|
|
168
161
|
* @returns `ReadableStream` of markup
|
|
169
162
|
*/
|
|
170
|
-
|
|
163
|
+
stream(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
171
164
|
/**
|
|
172
|
-
*
|
|
165
|
+
* The whole render as one string.
|
|
173
166
|
*
|
|
174
167
|
* ### WARNING
|
|
175
168
|
*
|
|
176
169
|
* This negates streaming benefits and buffers the result into a string.
|
|
177
170
|
*
|
|
178
|
-
* @param element Element to render
|
|
179
|
-
* @param options Markup options
|
|
180
171
|
* @returns Concatenated markup
|
|
181
172
|
*/
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Render raw markup and dangerously bypass escaping. It is written as it is
|
|
185
|
-
* in Markdown too, which can contain HTML.
|
|
186
|
-
*
|
|
187
|
-
* @param html Safe markup to render
|
|
188
|
-
* @returns New _safe_ `Chunk`
|
|
189
|
-
*/
|
|
190
|
-
static raw(html: unknown): Markup.Chunk;
|
|
173
|
+
string(): Promise<string>;
|
|
191
174
|
/**
|
|
192
175
|
* Escapes text for markup.
|
|
193
176
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markup/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG3C,mDAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markup/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG3C,mDAAmD;AACnD,qBAAa,KAAK;IACjB,iCAAiC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,0DAA0D;IAC1D,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC;IAElC;;;;;OAKG;IACH,YAAY,KAAK,EAAE,OAAO,EAAE,GAAG,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AAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,EAGzD;IAED,0EAA0E;IAC1E,IAAI,CAAC,MAAM,CAAC,gBAEX;IAED,+CAA+C;IACxC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAWrE;IAED;;;;;OAKG;IACH,MAAM,gDAEL;IAED;;;;;;;;OAQG;IACG,MAAM,oBAeX;IAED;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,UAOzC;CACD"}
|
package/dist/markup/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Codec, Size } from "../util/index.js";
|
|
2
2
|
/** Chunk of a rendered element: text, or markup */
|
|
3
|
-
class Chunk {
|
|
3
|
+
export class Chunk {
|
|
4
4
|
/** Text, or markup when `raw` */
|
|
5
5
|
value;
|
|
6
6
|
/** `true` if the value is markup, which is not escaped */
|
|
@@ -76,7 +76,7 @@ export class Tag extends Chunk {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
* Markup with
|
|
79
|
+
* Markup with the Markdown agents get in its place, from `Render.raw`, internal to ovr. It
|
|
80
80
|
* is written as its markup, and as its source in Markdown.
|
|
81
81
|
*/
|
|
82
82
|
export class Source extends Chunk {
|
|
@@ -166,7 +166,7 @@ export class Element {
|
|
|
166
166
|
*/
|
|
167
167
|
get #generator() {
|
|
168
168
|
return (this.#chunks ??= (async function* (element) {
|
|
169
|
-
const render = new
|
|
169
|
+
const render = new Renderer(element, undefined);
|
|
170
170
|
try {
|
|
171
171
|
for (let result; (result = render.step());) {
|
|
172
172
|
if (result instanceof Chunk)
|
|
@@ -204,7 +204,7 @@ const source = Symbol("source");
|
|
|
204
204
|
* synchronous unless the element has to be waited for, so nested elements cost
|
|
205
205
|
* a loop instead of a generator and a promise for each chunk at every level.
|
|
206
206
|
*/
|
|
207
|
-
export class
|
|
207
|
+
export class Renderer {
|
|
208
208
|
/** Chunks rendered before the element is its parent's current child */
|
|
209
209
|
queue;
|
|
210
210
|
/** Waiting, set by the parent of a child */
|
|
@@ -410,7 +410,7 @@ class Parallel {
|
|
|
410
410
|
this.#children = [];
|
|
411
411
|
// each child starts before any is waited for
|
|
412
412
|
for (const element of elements) {
|
|
413
|
-
const child = new
|
|
413
|
+
const child = new Renderer(element, raw);
|
|
414
414
|
const chunk = this.#advance(child);
|
|
415
415
|
if (chunk)
|
|
416
416
|
child.queue = [chunk];
|
|
@@ -628,7 +628,7 @@ export const readable = (render) => {
|
|
|
628
628
|
/**
|
|
629
629
|
* Renders an element to markup, such as HTML, SVG, or XML, as an
|
|
630
630
|
* `AsyncIterable` of strings, a stream, or a string. `Markdown` renders the
|
|
631
|
-
* same elements to Markdown.
|
|
631
|
+
* same elements to Markdown. Made with `Render.markup`.
|
|
632
632
|
*/
|
|
633
633
|
export class Markup {
|
|
634
634
|
/** Regex to find escape character for attributes */
|
|
@@ -657,7 +657,7 @@ export class Markup {
|
|
|
657
657
|
}
|
|
658
658
|
/** @yields Markup as the `Element` resolves */
|
|
659
659
|
async *[Symbol.asyncIterator]() {
|
|
660
|
-
const render = new
|
|
660
|
+
const render = new Renderer(this.#element, this.#options?.raw);
|
|
661
661
|
try {
|
|
662
662
|
for (let result; (result = render.step());) {
|
|
663
663
|
if (result instanceof Chunk)
|
|
@@ -671,29 +671,25 @@ export class Markup {
|
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
673
|
/**
|
|
674
|
-
*
|
|
675
|
-
*
|
|
674
|
+
* The render piped into a `ReadableStream`. Iterate it when possible, to
|
|
675
|
+
* avoid the overhead of the stream.
|
|
676
676
|
*
|
|
677
|
-
* @param element Element to render
|
|
678
|
-
* @param options Markup options
|
|
679
677
|
* @returns `ReadableStream` of markup
|
|
680
678
|
*/
|
|
681
|
-
|
|
682
|
-
return readable(new
|
|
679
|
+
stream() {
|
|
680
|
+
return readable(new Renderer(this.#element, this.#options?.raw));
|
|
683
681
|
}
|
|
684
682
|
/**
|
|
685
|
-
*
|
|
683
|
+
* The whole render as one string.
|
|
686
684
|
*
|
|
687
685
|
* ### WARNING
|
|
688
686
|
*
|
|
689
687
|
* This negates streaming benefits and buffers the result into a string.
|
|
690
688
|
*
|
|
691
|
-
* @param element Element to render
|
|
692
|
-
* @param options Markup options
|
|
693
689
|
* @returns Concatenated markup
|
|
694
690
|
*/
|
|
695
|
-
|
|
696
|
-
const render = new
|
|
691
|
+
async string() {
|
|
692
|
+
const render = new Renderer(this.#element, this.#options?.raw);
|
|
697
693
|
const chunks = [];
|
|
698
694
|
try {
|
|
699
695
|
for (let result; (result = render.step());) {
|
|
@@ -709,16 +705,6 @@ export class Markup {
|
|
|
709
705
|
// written once every chunk is rendered, as a group of them is
|
|
710
706
|
return new Group(chunks).toString();
|
|
711
707
|
}
|
|
712
|
-
/**
|
|
713
|
-
* Render raw markup and dangerously bypass escaping. It is written as it is
|
|
714
|
-
* in Markdown too, which can contain HTML.
|
|
715
|
-
*
|
|
716
|
-
* @param html Safe markup to render
|
|
717
|
-
* @returns New _safe_ `Chunk`
|
|
718
|
-
*/
|
|
719
|
-
static raw(html) {
|
|
720
|
-
return new Chunk(html, true);
|
|
721
|
-
}
|
|
722
708
|
/**
|
|
723
709
|
* Escapes text for markup.
|
|
724
710
|
*
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { JSX } from "../jsx/index.js";
|
|
2
|
+
import { Markdown as MarkdownRender } from "../markdown/index.js";
|
|
3
|
+
import { Chunk as ChunkClass, Markup as MarkupRender } from "../markup/index.js";
|
|
4
|
+
export declare namespace Render {
|
|
5
|
+
/** A piece of a render, an interface so declaration files name it */
|
|
6
|
+
interface Chunk extends ChunkClass {
|
|
7
|
+
}
|
|
8
|
+
/** A render of markup: an `AsyncIterable` of strings, a stream, or a string */
|
|
9
|
+
interface Markup extends MarkupRender {
|
|
10
|
+
}
|
|
11
|
+
namespace Markup {
|
|
12
|
+
/** Markup options */
|
|
13
|
+
type Options = MarkupRender.Options;
|
|
14
|
+
}
|
|
15
|
+
/** A render of Markdown: an `AsyncIterable` of strings, a stream, or a string */
|
|
16
|
+
interface Markdown extends MarkdownRender {
|
|
17
|
+
}
|
|
18
|
+
namespace Markdown {
|
|
19
|
+
/** Markdown options */
|
|
20
|
+
type Options = MarkdownRender.Options;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* What is written as it is, for people, agents, or both. With only
|
|
24
|
+
* `html`, agents get the HTML too, which Markdown can contain.
|
|
25
|
+
*/
|
|
26
|
+
type Raw = {
|
|
27
|
+
/** Safe markup the page shows */
|
|
28
|
+
readonly html: unknown;
|
|
29
|
+
/** What agents reading the page as Markdown get in its place, empty for nothing */
|
|
30
|
+
readonly markdown?: unknown;
|
|
31
|
+
} | {
|
|
32
|
+
/** Safe markup the page shows, nothing when left out */
|
|
33
|
+
readonly html?: unknown;
|
|
34
|
+
/** What agents reading the page as Markdown get */
|
|
35
|
+
readonly markdown: unknown;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Renders elements, to markup such as HTML for browsers and to Markdown for
|
|
40
|
+
* agents, and writes what is already rendered as it is.
|
|
41
|
+
*
|
|
42
|
+
* ```tsx
|
|
43
|
+
* const html = await Render.markup(<Page />).string();
|
|
44
|
+
* const markdown = await Render.markdown(<Page />).string();
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class Render {
|
|
48
|
+
/**
|
|
49
|
+
* Writes markup, Markdown, or both as they are, dangerously bypassing
|
|
50
|
+
* escaping, so both must be safe.
|
|
51
|
+
*
|
|
52
|
+
* ```tsx
|
|
53
|
+
* Render.raw({ html: icon }); // the page and agents get the markup
|
|
54
|
+
* Render.raw({ html: render(steps), markdown: steps }); // each its own
|
|
55
|
+
* Render.raw({ markdown: " · " }); // only agents
|
|
56
|
+
* Render.raw({ html: button, markdown: "" }); // only the page
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param raw Safe markup for the page, and what agents get in its place
|
|
60
|
+
* @returns New _safe_ chunk
|
|
61
|
+
*/
|
|
62
|
+
static raw(raw: Render.Raw): Render.Chunk;
|
|
63
|
+
/**
|
|
64
|
+
* Escapes text for markup.
|
|
65
|
+
*
|
|
66
|
+
* @param text Text to escape
|
|
67
|
+
* @param attr Set to `true` if the value is an attribute, otherwise it is content
|
|
68
|
+
* @returns Escaped text
|
|
69
|
+
*/
|
|
70
|
+
static escape(text: string, attr?: boolean): string;
|
|
71
|
+
/**
|
|
72
|
+
* Renders an element to markup, such as HTML, SVG, or XML.
|
|
73
|
+
*
|
|
74
|
+
* ```tsx
|
|
75
|
+
* for await (const chunk of Render.markup(<Page />)) {
|
|
76
|
+
* // each string as the element resolves
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param element Element to render
|
|
81
|
+
* @param options Markup options
|
|
82
|
+
* @returns The render, to iterate, `stream()`, or `string()`
|
|
83
|
+
*/
|
|
84
|
+
static markup(element: JSX.Element, options?: Render.Markup.Options): Render.Markup;
|
|
85
|
+
/**
|
|
86
|
+
* Renders an element to Markdown, as agents that ask for it read a page.
|
|
87
|
+
* Each top level block is written as soon as it closes, and when the page
|
|
88
|
+
* has a `<main>` element, only its contents are kept.
|
|
89
|
+
*
|
|
90
|
+
* @param element Element to render
|
|
91
|
+
* @param options Markdown options
|
|
92
|
+
* @returns The render, to iterate, `stream()`, or `string()`
|
|
93
|
+
*/
|
|
94
|
+
static markdown(element: JSX.Element, options?: Render.Markdown.Options): Render.Markdown;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAA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,CAAC,MAAM,CAAC,OAAO,GAC7B,MAAM,CAAC,MAAM,CAEf;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,QAAQ,CACd,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,OAAO,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,GAC/B,MAAM,CAAC,QAAQ,CAEjB;CACD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Markdown as MarkdownRender } from "../markdown/index.js";
|
|
2
|
+
import { Chunk as ChunkClass, Markup as MarkupRender, Source, } from "../markup/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders elements, to markup such as HTML for browsers and to Markdown for
|
|
5
|
+
* agents, and writes what is already rendered as it is.
|
|
6
|
+
*
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const html = await Render.markup(<Page />).string();
|
|
9
|
+
* const markdown = await Render.markdown(<Page />).string();
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export class Render {
|
|
13
|
+
/**
|
|
14
|
+
* Writes markup, Markdown, or both as they are, dangerously bypassing
|
|
15
|
+
* escaping, so both must be safe.
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* Render.raw({ html: icon }); // the page and agents get the markup
|
|
19
|
+
* Render.raw({ html: render(steps), markdown: steps }); // each its own
|
|
20
|
+
* Render.raw({ markdown: " · " }); // only agents
|
|
21
|
+
* Render.raw({ html: button, markdown: "" }); // only the page
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param raw Safe markup for the page, and what agents get in its place
|
|
25
|
+
* @returns New _safe_ chunk
|
|
26
|
+
*/
|
|
27
|
+
static raw(raw) {
|
|
28
|
+
return raw.markdown === undefined
|
|
29
|
+
? new ChunkClass(raw.html, true)
|
|
30
|
+
: new Source(raw.markdown, raw.html);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Escapes text for markup.
|
|
34
|
+
*
|
|
35
|
+
* @param text Text to escape
|
|
36
|
+
* @param attr Set to `true` if the value is an attribute, otherwise it is content
|
|
37
|
+
* @returns Escaped text
|
|
38
|
+
*/
|
|
39
|
+
static escape(text, attr) {
|
|
40
|
+
return MarkupRender.escape(text, attr);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Renders an element to markup, such as HTML, SVG, or XML.
|
|
44
|
+
*
|
|
45
|
+
* ```tsx
|
|
46
|
+
* for await (const chunk of Render.markup(<Page />)) {
|
|
47
|
+
* // each string as the element resolves
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param element Element to render
|
|
52
|
+
* @param options Markup options
|
|
53
|
+
* @returns The render, to iterate, `stream()`, or `string()`
|
|
54
|
+
*/
|
|
55
|
+
static markup(element, options) {
|
|
56
|
+
return new MarkupRender(element, options);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Renders an element to Markdown, as agents that ask for it read a page.
|
|
60
|
+
* Each top level block is written as soon as it closes, and when the page
|
|
61
|
+
* has a `<main>` element, only its contents are kept.
|
|
62
|
+
*
|
|
63
|
+
* @param element Element to render
|
|
64
|
+
* @param options Markdown options
|
|
65
|
+
* @returns The render, to iterate, `stream()`, or `string()`
|
|
66
|
+
*/
|
|
67
|
+
static markdown(element, options) {
|
|
68
|
+
return new MarkdownRender(element, options);
|
|
69
|
+
}
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ovr",
|
|
3
3
|
"description": "Web apps anyone can use. Each route serves people a page and agents Markdown and MCP tools, with forms, Postgres, and passkey sign-in built in.",
|
|
4
|
-
"version": "7.0.0-next.
|
|
4
|
+
"version": "7.0.0-next.34",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
package/src/context/index.ts
CHANGED
|
@@ -194,7 +194,7 @@ export class Context<
|
|
|
194
194
|
* that is a Markdown document, so agents read its source.
|
|
195
195
|
*
|
|
196
196
|
* ```tsx
|
|
197
|
-
* if (c.
|
|
197
|
+
* if (c.markdown(post.body)) return;
|
|
198
198
|
*
|
|
199
199
|
* return <Post post={post} />;
|
|
200
200
|
* ```
|
|
@@ -203,7 +203,7 @@ export class Context<
|
|
|
203
203
|
* @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
204
204
|
* @returns `true` if it responded, otherwise the page renders for the browser
|
|
205
205
|
*/
|
|
206
|
-
|
|
206
|
+
markdown(body: BodyInit | null, status?: number) {
|
|
207
207
|
if (!this.#markdown()) return false;
|
|
208
208
|
|
|
209
209
|
this.#respond(body, status, Header.utf8(Mime.type.md));
|
|
@@ -450,19 +450,19 @@ export class Context<
|
|
|
450
450
|
) &&
|
|
451
451
|
this.#markdown()
|
|
452
452
|
) {
|
|
453
|
-
res.body = Markdown
|
|
453
|
+
res.body = new Markdown(r, {
|
|
454
454
|
base: this.url,
|
|
455
455
|
[tools]: agent.get(this.req)?.tool,
|
|
456
|
-
});
|
|
456
|
+
}).stream();
|
|
457
457
|
res.headers.set(Header.name.type, Header.utf8(Mime.type.md));
|
|
458
458
|
return;
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
-
res.body = Markup
|
|
462
|
+
res.body = new Markup(r, {
|
|
463
463
|
// other defined types are not markup, so they are not escaped
|
|
464
464
|
raw: Boolean(mime && !Mime.markup(mime)),
|
|
465
|
-
});
|
|
465
|
+
}).stream();
|
|
466
466
|
|
|
467
467
|
if (!mime) {
|
|
468
468
|
// default to HTML
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,7 @@ export { Mcp } from "./mcp/index.js";
|
|
|
6
6
|
export type { JSX } from "./jsx/index.js";
|
|
7
7
|
export type { Middleware } from "./middleware/index.js";
|
|
8
8
|
export { Multipart } from "./multipart/index.js";
|
|
9
|
-
export {
|
|
10
|
-
export { Markdown } from "./markdown/index.js";
|
|
9
|
+
export { Render } from "./render/index.js";
|
|
11
10
|
export { Route } from "./route/index.js";
|
|
12
11
|
export { Table } from "./table/index.js";
|
|
13
12
|
export { Field } from "./form/index.js";
|
package/src/jsx/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Chunk, Element } from "../markup/index.js";
|
|
2
2
|
import type { IntrinsicElements as IE } from "./elements.js";
|
|
3
3
|
|
|
4
4
|
export namespace JSX {
|
|
@@ -59,7 +59,7 @@ export class JSX {
|
|
|
59
59
|
static jsx<P extends JSX.Props = JSX.Props>(
|
|
60
60
|
tag: ((props: P) => JSX.Element) | string,
|
|
61
61
|
props: P,
|
|
62
|
-
): AsyncGenerator<
|
|
62
|
+
): AsyncGenerator<Chunk, void, unknown> {
|
|
63
63
|
// this function doesn't need to be called recursively
|
|
64
64
|
// JSX will be transformed into `jsx()` function calls automatically
|
|
65
65
|
|
package/src/markdown/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { JSX } from "../jsx/index.js";
|
|
2
2
|
import {
|
|
3
|
+
type Chunk,
|
|
3
4
|
Group,
|
|
4
|
-
|
|
5
|
-
Render,
|
|
5
|
+
Renderer,
|
|
6
6
|
Source,
|
|
7
7
|
Tag,
|
|
8
8
|
readable,
|
|
@@ -210,7 +210,7 @@ class Writer {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/** @param chunk Rendered chunk, read by its kind instead of parsing its HTML */
|
|
213
|
-
chunk(chunk:
|
|
213
|
+
chunk(chunk: Chunk) {
|
|
214
214
|
if (chunk instanceof Group) {
|
|
215
215
|
for (const child of chunk.chunks) this.chunk(child);
|
|
216
216
|
} else if (chunk instanceof Tag) {
|
|
@@ -228,7 +228,15 @@ class Writer {
|
|
|
228
228
|
// it ends, so they share one empty set, which is never changed
|
|
229
229
|
this.#open(chunk.name, attrs ?? Writer.#none);
|
|
230
230
|
if (chunk.closed) this.#close(chunk.name);
|
|
231
|
-
} else if (chunk instanceof Source)
|
|
231
|
+
} else if (chunk instanceof Source)
|
|
232
|
+
this.#raw(
|
|
233
|
+
chunk.markdown,
|
|
234
|
+
// its own block when it is written as one, or stands for one. A
|
|
235
|
+
// line for a line, such as a separator only agents read, stays
|
|
236
|
+
// in its sentence
|
|
237
|
+
/\n/.test(chunk.markdown.trim()) ||
|
|
238
|
+
Writer.#rawBlock.test(String(chunk.value)),
|
|
239
|
+
);
|
|
232
240
|
else if (chunk.raw) this.#raw(chunk.value);
|
|
233
241
|
else this.#text(chunk.value);
|
|
234
242
|
}
|
|
@@ -251,12 +259,11 @@ class Writer {
|
|
|
251
259
|
}
|
|
252
260
|
|
|
253
261
|
/**
|
|
254
|
-
* Raw HTML, such as from `
|
|
255
|
-
* written as it is, as is Markdown
|
|
256
|
-
* always its own block.
|
|
262
|
+
* Raw HTML, such as from `Render.raw`, is valid Markdown, so it is
|
|
263
|
+
* written as it is, as is the Markdown it is given with.
|
|
257
264
|
*
|
|
258
265
|
* @param html HTML, or Markdown source
|
|
259
|
-
* @param source The text is Markdown source
|
|
266
|
+
* @param source The text is Markdown source that is its own block
|
|
260
267
|
*/
|
|
261
268
|
#raw(html: string, source?: boolean) {
|
|
262
269
|
if (!html || this.#skipping) return;
|
|
@@ -1406,7 +1413,7 @@ class Writer {
|
|
|
1406
1413
|
*/
|
|
1407
1414
|
class Blocks {
|
|
1408
1415
|
/** Render of the element's chunks */
|
|
1409
|
-
readonly #render:
|
|
1416
|
+
readonly #render: Renderer;
|
|
1410
1417
|
|
|
1411
1418
|
/** Writes Markdown from the chunks */
|
|
1412
1419
|
readonly #writer: Writer;
|
|
@@ -1419,7 +1426,7 @@ class Blocks {
|
|
|
1419
1426
|
* @param options Markdown options
|
|
1420
1427
|
*/
|
|
1421
1428
|
constructor(element: JSX.Element, options?: Markdown.Options) {
|
|
1422
|
-
this.#render = new
|
|
1429
|
+
this.#render = new Renderer(element, undefined);
|
|
1423
1430
|
this.#writer = new Writer(options);
|
|
1424
1431
|
}
|
|
1425
1432
|
|
|
@@ -1450,12 +1457,13 @@ class Blocks {
|
|
|
1450
1457
|
|
|
1451
1458
|
/**
|
|
1452
1459
|
* Renders an element to Markdown, as an `AsyncIterable` of blocks, a stream,
|
|
1453
|
-
* or a string, from the same elements `Markup` renders.
|
|
1460
|
+
* or a string, from the same elements `Markup` renders. Made with
|
|
1461
|
+
* `Render.markdown`. Each top level block is
|
|
1454
1462
|
* written as soon as it closes, and when the page has a `<main>` element, only
|
|
1455
1463
|
* its contents are kept. Raw HTML is written as it is.
|
|
1456
1464
|
*
|
|
1457
1465
|
* ```tsx
|
|
1458
|
-
* const markdown = await
|
|
1466
|
+
* const markdown = await Render.markdown(<Post post={post} />, { base: url }).string();
|
|
1459
1467
|
* ```
|
|
1460
1468
|
*/
|
|
1461
1469
|
export class Markdown {
|
|
@@ -1490,24 +1498,18 @@ export class Markdown {
|
|
|
1490
1498
|
}
|
|
1491
1499
|
}
|
|
1492
1500
|
|
|
1493
|
-
/**
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
* @returns `ReadableStream` of Markdown
|
|
1497
|
-
*/
|
|
1498
|
-
static stream(element: JSX.Element, options?: Markdown.Options) {
|
|
1499
|
-
return readable(new Blocks(element, options));
|
|
1501
|
+
/** @returns `ReadableStream` of Markdown */
|
|
1502
|
+
stream() {
|
|
1503
|
+
return readable(new Blocks(this.#element, this.#options));
|
|
1500
1504
|
}
|
|
1501
1505
|
|
|
1502
1506
|
/**
|
|
1503
|
-
*
|
|
1507
|
+
* The whole render as one string.
|
|
1504
1508
|
*
|
|
1505
|
-
* @param element Element to render
|
|
1506
|
-
* @param options Markdown options
|
|
1507
1509
|
* @returns Concatenated Markdown
|
|
1508
1510
|
*/
|
|
1509
|
-
|
|
1510
|
-
const blocks = new Blocks(element, options);
|
|
1511
|
+
async string() {
|
|
1512
|
+
const blocks = new Blocks(this.#element, this.#options);
|
|
1511
1513
|
let markdown = "";
|
|
1512
1514
|
|
|
1513
1515
|
try {
|
|
@@ -1521,21 +1523,4 @@ export class Markdown {
|
|
|
1521
1523
|
|
|
1522
1524
|
return markdown;
|
|
1523
1525
|
}
|
|
1524
|
-
|
|
1525
|
-
/**
|
|
1526
|
-
* Markdown source with the HTML it renders to, such as steps written in
|
|
1527
|
-
* Markdown. Pages show the HTML, and agents reading the page as Markdown
|
|
1528
|
-
* get the source. Neither is escaped, so both must be safe.
|
|
1529
|
-
*
|
|
1530
|
-
* ```tsx
|
|
1531
|
-
* <section>{Markdown.raw(recipe.steps, render(recipe.steps))}</section>
|
|
1532
|
-
* ```
|
|
1533
|
-
*
|
|
1534
|
-
* @param markdown Markdown source
|
|
1535
|
-
* @param html Safe HTML it renders to
|
|
1536
|
-
* @returns New _safe_ chunk
|
|
1537
|
-
*/
|
|
1538
|
-
static raw(markdown: unknown, html: unknown): Markup.Chunk {
|
|
1539
|
-
return new Source(markdown, html);
|
|
1540
|
-
}
|
|
1541
1526
|
}
|
package/src/markup/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { JSX } from "../jsx/index.js";
|
|
|
2
2
|
import { Codec, Size } from "../util/index.js";
|
|
3
3
|
|
|
4
4
|
/** Chunk of a rendered element: text, or markup */
|
|
5
|
-
class Chunk {
|
|
5
|
+
export class Chunk {
|
|
6
6
|
/** Text, or markup when `raw` */
|
|
7
7
|
readonly value: string;
|
|
8
8
|
|
|
@@ -88,7 +88,7 @@ export class Tag extends Chunk {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* Markup with
|
|
91
|
+
* Markup with the Markdown agents get in its place, from `Render.raw`, internal to ovr. It
|
|
92
92
|
* is written as its markup, and as its source in Markdown.
|
|
93
93
|
*/
|
|
94
94
|
export class Source extends Chunk {
|
|
@@ -189,7 +189,7 @@ export class Element implements AsyncGenerator<Chunk, void, unknown> {
|
|
|
189
189
|
*/
|
|
190
190
|
get #generator(): AsyncGenerator<Chunk, void, unknown> {
|
|
191
191
|
return (this.#chunks ??= (async function* (element) {
|
|
192
|
-
const render = new
|
|
192
|
+
const render = new Renderer(element, undefined);
|
|
193
193
|
|
|
194
194
|
try {
|
|
195
195
|
for (let result: Step; (result = render.step());) {
|
|
@@ -241,7 +241,7 @@ type Sequence = {
|
|
|
241
241
|
* synchronous unless the element has to be waited for, so nested elements cost
|
|
242
242
|
* a loop instead of a generator and a promise for each chunk at every level.
|
|
243
243
|
*/
|
|
244
|
-
export class
|
|
244
|
+
export class Renderer {
|
|
245
245
|
/** Chunks rendered before the element is its parent's current child */
|
|
246
246
|
queue: Chunk[] | undefined;
|
|
247
247
|
|
|
@@ -458,14 +458,14 @@ export class Render {
|
|
|
458
458
|
*/
|
|
459
459
|
class Parallel {
|
|
460
460
|
/** Render of each child */
|
|
461
|
-
readonly #children:
|
|
461
|
+
readonly #children: Renderer[];
|
|
462
462
|
|
|
463
463
|
/**
|
|
464
464
|
* Children after the current one that can step: not waiting, and not done.
|
|
465
465
|
* Only these are looked at as the others wait, so a list of many children
|
|
466
466
|
* that each wait costs no more for each one that resolves.
|
|
467
467
|
*/
|
|
468
|
-
readonly #idle:
|
|
468
|
+
readonly #idle: Renderer[] = [];
|
|
469
469
|
|
|
470
470
|
/** Index of the child being yielded */
|
|
471
471
|
#current = 0;
|
|
@@ -491,7 +491,7 @@ class Parallel {
|
|
|
491
491
|
|
|
492
492
|
// each child starts before any is waited for
|
|
493
493
|
for (const element of elements) {
|
|
494
|
-
const child = new
|
|
494
|
+
const child = new Renderer(element, raw);
|
|
495
495
|
const chunk = this.#advance(child);
|
|
496
496
|
|
|
497
497
|
if (chunk) child.queue = [chunk];
|
|
@@ -549,7 +549,7 @@ class Parallel {
|
|
|
549
549
|
* @param child Child that is not waiting
|
|
550
550
|
* @returns The chunk, if it rendered one
|
|
551
551
|
*/
|
|
552
|
-
#advance(child:
|
|
552
|
+
#advance(child: Renderer) {
|
|
553
553
|
let result: Step;
|
|
554
554
|
|
|
555
555
|
try {
|
|
@@ -627,7 +627,7 @@ class Parallel {
|
|
|
627
627
|
*
|
|
628
628
|
* @param child Current child, which is waiting
|
|
629
629
|
*/
|
|
630
|
-
async #wait(child:
|
|
630
|
+
async #wait(child: Renderer) {
|
|
631
631
|
while (child.waiting && !this.#failed && !this.#closed) {
|
|
632
632
|
if (this.#rest()) await undefined;
|
|
633
633
|
else await new Promise<void>((resolve) => (this.#notify = resolve));
|
|
@@ -737,24 +737,18 @@ export const readable = (render: {
|
|
|
737
737
|
);
|
|
738
738
|
};
|
|
739
739
|
|
|
740
|
-
/** The class `Markup.Chunk` is named for */
|
|
741
|
-
type ChunkClass = Chunk;
|
|
742
|
-
|
|
743
740
|
export namespace Markup {
|
|
744
741
|
/** Markup options */
|
|
745
742
|
export type Options = {
|
|
746
743
|
/** Set to `true` to disable escaping, for content that is not markup */
|
|
747
744
|
raw?: boolean;
|
|
748
745
|
};
|
|
749
|
-
|
|
750
|
-
/** Rendered `Chunk` instance, an interface so declaration files name it */
|
|
751
|
-
export interface Chunk extends ChunkClass {}
|
|
752
746
|
}
|
|
753
747
|
|
|
754
748
|
/**
|
|
755
749
|
* Renders an element to markup, such as HTML, SVG, or XML, as an
|
|
756
750
|
* `AsyncIterable` of strings, a stream, or a string. `Markdown` renders the
|
|
757
|
-
* same elements to Markdown.
|
|
751
|
+
* same elements to Markdown. Made with `Render.markup`.
|
|
758
752
|
*/
|
|
759
753
|
export class Markup {
|
|
760
754
|
/** Regex to find escape character for attributes */
|
|
@@ -790,7 +784,7 @@ export class Markup {
|
|
|
790
784
|
|
|
791
785
|
/** @yields Markup as the `Element` resolves */
|
|
792
786
|
async *[Symbol.asyncIterator](): AsyncGenerator<string, void, unknown> {
|
|
793
|
-
const render = new
|
|
787
|
+
const render = new Renderer(this.#element, this.#options?.raw);
|
|
794
788
|
|
|
795
789
|
try {
|
|
796
790
|
for (let result: Step; (result = render.step());) {
|
|
@@ -803,30 +797,26 @@ export class Markup {
|
|
|
803
797
|
}
|
|
804
798
|
|
|
805
799
|
/**
|
|
806
|
-
*
|
|
807
|
-
*
|
|
800
|
+
* The render piped into a `ReadableStream`. Iterate it when possible, to
|
|
801
|
+
* avoid the overhead of the stream.
|
|
808
802
|
*
|
|
809
|
-
* @param element Element to render
|
|
810
|
-
* @param options Markup options
|
|
811
803
|
* @returns `ReadableStream` of markup
|
|
812
804
|
*/
|
|
813
|
-
|
|
814
|
-
return readable(new
|
|
805
|
+
stream() {
|
|
806
|
+
return readable(new Renderer(this.#element, this.#options?.raw));
|
|
815
807
|
}
|
|
816
808
|
|
|
817
809
|
/**
|
|
818
|
-
*
|
|
810
|
+
* The whole render as one string.
|
|
819
811
|
*
|
|
820
812
|
* ### WARNING
|
|
821
813
|
*
|
|
822
814
|
* This negates streaming benefits and buffers the result into a string.
|
|
823
815
|
*
|
|
824
|
-
* @param element Element to render
|
|
825
|
-
* @param options Markup options
|
|
826
816
|
* @returns Concatenated markup
|
|
827
817
|
*/
|
|
828
|
-
|
|
829
|
-
const render = new
|
|
818
|
+
async string() {
|
|
819
|
+
const render = new Renderer(this.#element, this.#options?.raw);
|
|
830
820
|
const chunks: Chunk[] = [];
|
|
831
821
|
|
|
832
822
|
try {
|
|
@@ -842,17 +832,6 @@ export class Markup {
|
|
|
842
832
|
return new Group(chunks).toString();
|
|
843
833
|
}
|
|
844
834
|
|
|
845
|
-
/**
|
|
846
|
-
* Render raw markup and dangerously bypass escaping. It is written as it is
|
|
847
|
-
* in Markdown too, which can contain HTML.
|
|
848
|
-
*
|
|
849
|
-
* @param html Safe markup to render
|
|
850
|
-
* @returns New _safe_ `Chunk`
|
|
851
|
-
*/
|
|
852
|
-
static raw(html: unknown): Markup.Chunk {
|
|
853
|
-
return new Chunk(html, true);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
835
|
/**
|
|
857
836
|
* Escapes text for markup.
|
|
858
837
|
*
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { JSX } from "../jsx/index.js";
|
|
2
|
+
import { Markdown as MarkdownRender } from "../markdown/index.js";
|
|
3
|
+
import {
|
|
4
|
+
Chunk as ChunkClass,
|
|
5
|
+
Markup as MarkupRender,
|
|
6
|
+
Source,
|
|
7
|
+
} from "../markup/index.js";
|
|
8
|
+
|
|
9
|
+
export namespace Render {
|
|
10
|
+
/** A piece of a render, an interface so declaration files name it */
|
|
11
|
+
export interface Chunk extends ChunkClass {}
|
|
12
|
+
|
|
13
|
+
/** A render of markup: an `AsyncIterable` of strings, a stream, or a string */
|
|
14
|
+
export interface Markup extends MarkupRender {}
|
|
15
|
+
|
|
16
|
+
export namespace Markup {
|
|
17
|
+
/** Markup options */
|
|
18
|
+
export type Options = MarkupRender.Options;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A render of Markdown: an `AsyncIterable` of strings, a stream, or a string */
|
|
22
|
+
export interface Markdown extends MarkdownRender {}
|
|
23
|
+
|
|
24
|
+
export namespace Markdown {
|
|
25
|
+
/** Markdown options */
|
|
26
|
+
export type Options = MarkdownRender.Options;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* What is written as it is, for people, agents, or both. With only
|
|
31
|
+
* `html`, agents get the HTML too, which Markdown can contain.
|
|
32
|
+
*/
|
|
33
|
+
export type Raw =
|
|
34
|
+
| {
|
|
35
|
+
/** Safe markup the page shows */
|
|
36
|
+
readonly html: unknown;
|
|
37
|
+
/** What agents reading the page as Markdown get in its place, empty for nothing */
|
|
38
|
+
readonly markdown?: unknown;
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
/** Safe markup the page shows, nothing when left out */
|
|
42
|
+
readonly html?: unknown;
|
|
43
|
+
/** What agents reading the page as Markdown get */
|
|
44
|
+
readonly markdown: unknown;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Renders elements, to markup such as HTML for browsers and to Markdown for
|
|
50
|
+
* agents, and writes what is already rendered as it is.
|
|
51
|
+
*
|
|
52
|
+
* ```tsx
|
|
53
|
+
* const html = await Render.markup(<Page />).string();
|
|
54
|
+
* const markdown = await Render.markdown(<Page />).string();
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export class Render {
|
|
58
|
+
/**
|
|
59
|
+
* Writes markup, Markdown, or both as they are, dangerously bypassing
|
|
60
|
+
* escaping, so both must be safe.
|
|
61
|
+
*
|
|
62
|
+
* ```tsx
|
|
63
|
+
* Render.raw({ html: icon }); // the page and agents get the markup
|
|
64
|
+
* Render.raw({ html: render(steps), markdown: steps }); // each its own
|
|
65
|
+
* Render.raw({ markdown: " · " }); // only agents
|
|
66
|
+
* Render.raw({ html: button, markdown: "" }); // only the page
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param raw Safe markup for the page, and what agents get in its place
|
|
70
|
+
* @returns New _safe_ chunk
|
|
71
|
+
*/
|
|
72
|
+
static raw(raw: Render.Raw): Render.Chunk {
|
|
73
|
+
return raw.markdown === undefined
|
|
74
|
+
? new ChunkClass(raw.html, true)
|
|
75
|
+
: new Source(raw.markdown, raw.html);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Escapes text for markup.
|
|
80
|
+
*
|
|
81
|
+
* @param text Text to escape
|
|
82
|
+
* @param attr Set to `true` if the value is an attribute, otherwise it is content
|
|
83
|
+
* @returns Escaped text
|
|
84
|
+
*/
|
|
85
|
+
static escape(text: string, attr?: boolean) {
|
|
86
|
+
return MarkupRender.escape(text, attr);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Renders an element to markup, such as HTML, SVG, or XML.
|
|
91
|
+
*
|
|
92
|
+
* ```tsx
|
|
93
|
+
* for await (const chunk of Render.markup(<Page />)) {
|
|
94
|
+
* // each string as the element resolves
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @param element Element to render
|
|
99
|
+
* @param options Markup options
|
|
100
|
+
* @returns The render, to iterate, `stream()`, or `string()`
|
|
101
|
+
*/
|
|
102
|
+
static markup(
|
|
103
|
+
element: JSX.Element,
|
|
104
|
+
options?: Render.Markup.Options,
|
|
105
|
+
): Render.Markup {
|
|
106
|
+
return new MarkupRender(element, options);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Renders an element to Markdown, as agents that ask for it read a page.
|
|
111
|
+
* Each top level block is written as soon as it closes, and when the page
|
|
112
|
+
* has a `<main>` element, only its contents are kept.
|
|
113
|
+
*
|
|
114
|
+
* @param element Element to render
|
|
115
|
+
* @param options Markdown options
|
|
116
|
+
* @returns The render, to iterate, `stream()`, or `string()`
|
|
117
|
+
*/
|
|
118
|
+
static markdown(
|
|
119
|
+
element: JSX.Element,
|
|
120
|
+
options?: Render.Markdown.Options,
|
|
121
|
+
): Render.Markdown {
|
|
122
|
+
return new MarkdownRender(element, options);
|
|
123
|
+
}
|
|
124
|
+
}
|