@lightblues/jig 0.1.6 → 0.1.7
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/dist/markdown/index.d.ts
CHANGED
|
@@ -116,6 +116,11 @@ export type MarkdownOptions = {
|
|
|
116
116
|
export type RenderOptions = {
|
|
117
117
|
/** The text is a partial answer: close what it left open first (`closeOpenMarkdown`). */
|
|
118
118
|
streaming?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Per-render `links.map` override — avoids a module variable when route mapping depends on per-page data
|
|
121
|
+
* (forge-018, assay-020). Replaces the instance-level `links.map` for this render only.
|
|
122
|
+
*/
|
|
123
|
+
map?: (href: string) => string | null | undefined;
|
|
119
124
|
};
|
|
120
125
|
/** `renderDocument`'s result: the HTML with its slots, and what goes in them. */
|
|
121
126
|
export type MarkdownDocument = BlockEnv & {
|
package/dist/markdown/index.js
CHANGED
|
@@ -41,6 +41,8 @@ export function createMarkdown(opts = {}) {
|
|
|
41
41
|
const rel = opts.links?.rel ?? DEFAULT_REL;
|
|
42
42
|
const target = opts.links?.target;
|
|
43
43
|
const map = opts.links?.map;
|
|
44
|
+
// Per-render override (RenderOptions.map): set around each md.render call and cleared afterwards.
|
|
45
|
+
let renderMap;
|
|
44
46
|
// Parse time: a refused URL is not a link at all (its source stays as text).
|
|
45
47
|
md.validateLink = (url) => urlAllowed(url, 'link', allow) || (images && urlAllowed(url, 'image', allow));
|
|
46
48
|
if (opts.cjk)
|
|
@@ -64,8 +66,8 @@ export function createMarkdown(opts = {}) {
|
|
|
64
66
|
const href = a === null ? null : String(a);
|
|
65
67
|
if (href === null || !urlAllowed(href, 'link', allow))
|
|
66
68
|
dropAttr(t, 'href');
|
|
67
|
-
else if (map && !external(href) && !SCHEME.test(href)) {
|
|
68
|
-
const mapped = map(href);
|
|
69
|
+
else if ((map || renderMap) && !external(href) && !SCHEME.test(href)) {
|
|
70
|
+
const mapped = (renderMap ?? map)(href);
|
|
69
71
|
if (mapped === null)
|
|
70
72
|
return unlink(tokens, idx);
|
|
71
73
|
if (mapped !== undefined && !urlAllowed(mapped, 'link', allow))
|
|
@@ -113,16 +115,22 @@ export function createMarkdown(opts = {}) {
|
|
|
113
115
|
const blocks = useBlocks(md, opts);
|
|
114
116
|
const strip = opts.streamingStrip;
|
|
115
117
|
const doc = (text, r, out) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
renderMap = r.map;
|
|
119
|
+
try {
|
|
120
|
+
if (!r.streaming)
|
|
121
|
+
return md.render(text, blocks ? { [ENV]: out } : {});
|
|
122
|
+
if (!blocks)
|
|
123
|
+
return md.render(closeOpenMarkdown(text, strip ? { strip } : {}));
|
|
124
|
+
// Which fence, if any, the closer added: that block is still being written.
|
|
125
|
+
const s = strip ? stripTail(text, strip) : text;
|
|
126
|
+
const closed = closeOpenMarkdown(s);
|
|
127
|
+
const tail = closed.slice(s.length);
|
|
128
|
+
const open = closed.startsWith(s) && /^\n?(`{3,}|~{3,})$/.test(tail);
|
|
129
|
+
return md.render(closed, { [ENV]: out, [OPEN]: open });
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
renderMap = undefined;
|
|
133
|
+
}
|
|
126
134
|
};
|
|
127
135
|
return {
|
|
128
136
|
md,
|
|
@@ -30,5 +30,6 @@ export declare const MERMAID_CONFIG: {
|
|
|
30
30
|
* shows the source as escaped code with class `jig-mermaid-error`. Resolves to whether it drew. `mermaid` is the module,
|
|
31
31
|
* or a loader (`() => import('mermaid')`) called on first use.
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
/** Draws `source` into `el`. Resolves to `null` on success, or the parse/render error message on failure (forge-018). */
|
|
34
|
+
export declare function drawMermaid(el: Element, source: string, mermaid: MermaidSource, o?: DrawMermaidOptions): Promise<null | string>;
|
|
34
35
|
export {};
|
package/dist/markdown/mermaid.js
CHANGED
|
@@ -50,6 +50,7 @@ function scrub(root) {
|
|
|
50
50
|
* shows the source as escaped code with class `jig-mermaid-error`. Resolves to whether it drew. `mermaid` is the module,
|
|
51
51
|
* or a loader (`() => import('mermaid')`) called on first use.
|
|
52
52
|
*/
|
|
53
|
+
/** Draws `source` into `el`. Resolves to `null` on success, or the parse/render error message on failure (forge-018). */
|
|
53
54
|
export async function drawMermaid(el, source, mermaid, o = {}) {
|
|
54
55
|
const id = `jig-mmd-${++seq}`;
|
|
55
56
|
const doc = el.ownerDocument;
|
|
@@ -72,9 +73,9 @@ export async function drawMermaid(el, source, mermaid, o = {}) {
|
|
|
72
73
|
view.className = 'jig-mermaid';
|
|
73
74
|
view.append(tpl.content);
|
|
74
75
|
el.replaceChildren(view);
|
|
75
|
-
return
|
|
76
|
+
return null;
|
|
76
77
|
}
|
|
77
|
-
catch {
|
|
78
|
+
catch (err) {
|
|
78
79
|
cleanup();
|
|
79
80
|
const pre = doc.createElement('pre');
|
|
80
81
|
pre.className = 'jig-mermaid-error';
|
|
@@ -83,6 +84,6 @@ export async function drawMermaid(el, source, mermaid, o = {}) {
|
|
|
83
84
|
code.textContent = source;
|
|
84
85
|
pre.append(code);
|
|
85
86
|
el.replaceChildren(pre);
|
|
86
|
-
return
|
|
87
|
+
return err instanceof Error ? err.message : String(err);
|
|
87
88
|
}
|
|
88
89
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightblues/jig",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Reusable parts for my apps: agent runtimes (Paseo, pi) that speak AG-UI, a thin thread-following client, one markdown renderer, and more as they prove reusable.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -87,7 +87,8 @@
|
|
|
87
87
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
88
88
|
"test": "node --test --experimental-strip-types 'test/**/*.test.ts'",
|
|
89
89
|
"test:contract": "node --test --experimental-strip-types 'test/agent-paseo-contract.ts'",
|
|
90
|
-
"prepack": "npm run build"
|
|
90
|
+
"prepack": "npm run build",
|
|
91
|
+
"gallery": "node --experimental-strip-types scripts/gallery.ts"
|
|
91
92
|
},
|
|
92
93
|
"devDependencies": {
|
|
93
94
|
"@ag-ui/core": "1.0.5",
|