toolcraft 0.0.84 → 0.0.85
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/design/render-markdown-plaintext.d.ts +2 -0
- package/dist/design/render-markdown-plaintext.js +1 -0
- package/node_modules/toolcraft-design/dist/index.d.ts +2 -2
- package/node_modules/toolcraft-design/dist/index.js +1 -1
- package/node_modules/toolcraft-design/dist/render-markdown-plaintext.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-markdown-plaintext.js +1 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/index.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/index.js +1 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/inline.js +38 -2
- package/node_modules/toolcraft-design/dist/terminal-markdown/plaintext-renderer.d.ts +11 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/plaintext-renderer.js +228 -0
- package/node_modules/toolcraft-design/package.json +4 -0
- package/package.json +6 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { renderMarkdownPlaintext, renderPlaintext } from "toolcraft-design/render-markdown-plaintext";
|
|
@@ -44,8 +44,8 @@ export { promptTheme } from "./prompts/theme.js";
|
|
|
44
44
|
export * as staticRender from "./static/index.js";
|
|
45
45
|
export { SPINNER_FRAMES, renderSpinnerFrame, renderSpinnerStopped, renderMenu } from "./static/index.js";
|
|
46
46
|
export type { SpinnerFrameOptions, SpinnerStoppedOptions, MenuOption, RenderMenuOptions } from "./static/index.js";
|
|
47
|
-
export { parse, render, renderHtml, renderMarkdown, renderMarkdownHtml } from "./terminal-markdown/index.js";
|
|
48
|
-
export type { CodeToken, CodeTokenKind, HtmlRenderOptions, MdNode, RenderOptions } from "./terminal-markdown/index.js";
|
|
47
|
+
export { parse, render, renderHtml, renderMarkdown, renderMarkdownHtml, renderPlaintext, renderMarkdownPlaintext } from "./terminal-markdown/index.js";
|
|
48
|
+
export type { CodeToken, CodeTokenKind, HtmlRenderOptions, MdNode, PlaintextRenderOptions, RenderOptions } from "./terminal-markdown/index.js";
|
|
49
49
|
export { getTheme, resolveThemeName, resetThemeCache } from "./internal/theme-detect.js";
|
|
50
50
|
export type { ThemeEnv } from "./internal/theme-detect.js";
|
|
51
51
|
export { configureTheme, getThemeConfig, resetTheme } from "./internal/theme-state.js";
|
|
@@ -37,7 +37,7 @@ export { promptTheme } from "./prompts/theme.js";
|
|
|
37
37
|
export * as staticRender from "./static/index.js";
|
|
38
38
|
export { SPINNER_FRAMES, renderSpinnerFrame, renderSpinnerStopped, renderMenu } from "./static/index.js";
|
|
39
39
|
// Terminal markdown
|
|
40
|
-
export { parse, render, renderHtml, renderMarkdown, renderMarkdownHtml } from "./terminal-markdown/index.js";
|
|
40
|
+
export { parse, render, renderHtml, renderMarkdown, renderMarkdownHtml, renderPlaintext, renderMarkdownPlaintext } from "./terminal-markdown/index.js";
|
|
41
41
|
// Internal utilities (for advanced use)
|
|
42
42
|
export { getTheme, resolveThemeName, resetThemeCache } from "./internal/theme-detect.js";
|
|
43
43
|
export { configureTheme, getThemeConfig, resetTheme } from "./internal/theme-state.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { renderMarkdownPlaintext, renderPlaintext } from "./terminal-markdown/index.js";
|
|
@@ -3,6 +3,8 @@ import { type RenderOptions } from "./renderer.js";
|
|
|
3
3
|
export type { CodeToken, CodeTokenKind, MdNode } from "./ast.js";
|
|
4
4
|
export { renderHtml } from "./html-renderer.js";
|
|
5
5
|
export type { HtmlRenderOptions } from "./html-renderer.js";
|
|
6
|
+
export { renderPlaintext, renderMarkdownPlaintext } from "./plaintext-renderer.js";
|
|
7
|
+
export type { PlaintextRenderOptions } from "./plaintext-renderer.js";
|
|
6
8
|
export { parse } from "./parser.js";
|
|
7
9
|
export { render } from "./renderer.js";
|
|
8
10
|
export type { RenderOptions } from "./renderer.js";
|
|
@@ -2,6 +2,7 @@ import { parse } from "./parser.js";
|
|
|
2
2
|
import { renderHtml } from "./html-renderer.js";
|
|
3
3
|
import { render } from "./renderer.js";
|
|
4
4
|
export { renderHtml } from "./html-renderer.js";
|
|
5
|
+
export { renderPlaintext, renderMarkdownPlaintext } from "./plaintext-renderer.js";
|
|
5
6
|
export { parse } from "./parser.js";
|
|
6
7
|
export { render } from "./renderer.js";
|
|
7
8
|
export function renderMarkdown(markdown, options) {
|
|
@@ -853,9 +853,12 @@ function parseInlineHtmlTag(input, start, offsets) {
|
|
|
853
853
|
return null;
|
|
854
854
|
}
|
|
855
855
|
if (input[index] === ">") {
|
|
856
|
+
const tagEnd = index + 1;
|
|
857
|
+
const closingTagEnd = findClosingInlineHtmlTagEnd(input, tagEnd, tagName);
|
|
858
|
+
const nodeEnd = closingTagEnd ?? tagEnd;
|
|
856
859
|
return {
|
|
857
|
-
node: withRange({ type: "html", value: input.slice(start,
|
|
858
|
-
end:
|
|
860
|
+
node: withRange({ type: "html", value: input.slice(start, nodeEnd) }, offsets === undefined ? { start, end: nodeEnd } : createRange(offsets, start, nodeEnd)),
|
|
861
|
+
end: nodeEnd
|
|
859
862
|
};
|
|
860
863
|
}
|
|
861
864
|
if (input[index] === "/") {
|
|
@@ -907,6 +910,39 @@ function parseInlineHtmlTag(input, start, offsets) {
|
|
|
907
910
|
}
|
|
908
911
|
return null;
|
|
909
912
|
}
|
|
913
|
+
function findClosingInlineHtmlTagEnd(input, start, tagName) {
|
|
914
|
+
let index = start;
|
|
915
|
+
while (index < input.length) {
|
|
916
|
+
if (input[index] !== "<") {
|
|
917
|
+
index += 1;
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
const closingEnd = readClosingInlineHtmlTagEnd(input, index, tagName);
|
|
921
|
+
if (closingEnd !== undefined) {
|
|
922
|
+
return closingEnd;
|
|
923
|
+
}
|
|
924
|
+
index += 1;
|
|
925
|
+
}
|
|
926
|
+
return undefined;
|
|
927
|
+
}
|
|
928
|
+
function readClosingInlineHtmlTagEnd(input, start, tagName) {
|
|
929
|
+
let index = start + 1;
|
|
930
|
+
if (index >= input.length || input[index] !== "/") {
|
|
931
|
+
return undefined;
|
|
932
|
+
}
|
|
933
|
+
index += 1;
|
|
934
|
+
for (const expectedChar of tagName) {
|
|
935
|
+
if (index >= input.length || input[index]?.toLowerCase() !== expectedChar) {
|
|
936
|
+
return undefined;
|
|
937
|
+
}
|
|
938
|
+
index += 1;
|
|
939
|
+
}
|
|
940
|
+
index = skipHtmlWhitespace(input, index);
|
|
941
|
+
if (index >= input.length || input[index] !== ">") {
|
|
942
|
+
return undefined;
|
|
943
|
+
}
|
|
944
|
+
return index + 1;
|
|
945
|
+
}
|
|
910
946
|
function decodeEscapes(value) {
|
|
911
947
|
let result = "";
|
|
912
948
|
let index = 0;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MdNode } from "./ast.js";
|
|
2
|
+
export interface PlaintextRenderOptions {
|
|
3
|
+
announceHeadings?: boolean;
|
|
4
|
+
announceCode?: boolean;
|
|
5
|
+
announceAlerts?: boolean;
|
|
6
|
+
showLinks?: boolean;
|
|
7
|
+
expandLinks?: boolean;
|
|
8
|
+
includeFrontmatter?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function renderPlaintext(ast: MdNode, options?: PlaintextRenderOptions): string;
|
|
11
|
+
export declare function renderMarkdownPlaintext(markdown: string, options?: PlaintextRenderOptions): string;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { stripAnsi } from "../internal/strip-ansi.js";
|
|
2
|
+
import { parse } from "./parser.js";
|
|
3
|
+
function renderInline(node, ctx) {
|
|
4
|
+
switch (node.type) {
|
|
5
|
+
case "text":
|
|
6
|
+
return stripAnsi(node.value);
|
|
7
|
+
case "emphasis":
|
|
8
|
+
case "strong":
|
|
9
|
+
return renderChildren(node.children, ctx);
|
|
10
|
+
case "strikethrough":
|
|
11
|
+
return "";
|
|
12
|
+
case "inlineCode":
|
|
13
|
+
return stripAnsi(node.value);
|
|
14
|
+
case "break":
|
|
15
|
+
return " ";
|
|
16
|
+
case "html":
|
|
17
|
+
return "";
|
|
18
|
+
case "link": {
|
|
19
|
+
const childText = renderChildren(node.children, ctx) || node.url;
|
|
20
|
+
if (ctx.expandLinks) {
|
|
21
|
+
return `${childText} ${stripAnsi(node.url)}`;
|
|
22
|
+
}
|
|
23
|
+
if (ctx.showLinks) {
|
|
24
|
+
return `${childText} (link)`;
|
|
25
|
+
}
|
|
26
|
+
return childText;
|
|
27
|
+
}
|
|
28
|
+
case "image":
|
|
29
|
+
return stripAnsi(node.alt);
|
|
30
|
+
case "footnoteReference": {
|
|
31
|
+
if (!ctx.footnoteOrder.includes(node.label)) {
|
|
32
|
+
ctx.footnoteOrder.push(node.label);
|
|
33
|
+
}
|
|
34
|
+
const index = ctx.footnoteOrder.indexOf(node.label) + 1;
|
|
35
|
+
return `[${index}]`;
|
|
36
|
+
}
|
|
37
|
+
default:
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function renderChildren(nodes, ctx) {
|
|
42
|
+
return nodes.map((node) => renderInline(node, ctx)).join("");
|
|
43
|
+
}
|
|
44
|
+
function renderBlock(node, ctx) {
|
|
45
|
+
switch (node.type) {
|
|
46
|
+
case "root": {
|
|
47
|
+
collectFootnoteDefinitions(node.children, ctx);
|
|
48
|
+
const text = trimBlockSeparators(renderBlockChildren(node.children, ctx));
|
|
49
|
+
const footnotes = renderReferencedFootnotes(ctx);
|
|
50
|
+
return footnotes.length === 0 ? text : trimBlockSeparators(`${text}\n\n${footnotes}`);
|
|
51
|
+
}
|
|
52
|
+
case "paragraph":
|
|
53
|
+
return `${renderChildren(node.children, ctx)}\n\n`;
|
|
54
|
+
case "thematicBreak":
|
|
55
|
+
return "";
|
|
56
|
+
case "heading": {
|
|
57
|
+
const prefix = ctx.announceHeadings && node.depth === 1
|
|
58
|
+
? "Section: "
|
|
59
|
+
: ctx.announceHeadings && node.depth === 2
|
|
60
|
+
? "Subsection: "
|
|
61
|
+
: ctx.announceHeadings
|
|
62
|
+
? "Topic: "
|
|
63
|
+
: "";
|
|
64
|
+
return `${prefix}${renderChildren(node.children, ctx).trim()}\n\n`;
|
|
65
|
+
}
|
|
66
|
+
case "blockquote":
|
|
67
|
+
return `Quote: ${renderBlockChildren(node.children, ctx).trim()}\n\n`;
|
|
68
|
+
case "alert": {
|
|
69
|
+
const prefix = ctx.announceAlerts ? `${node.kind}: ` : "";
|
|
70
|
+
return `${prefix}${renderBlockChildren(node.children, ctx).trim()}\n\n`;
|
|
71
|
+
}
|
|
72
|
+
case "list": {
|
|
73
|
+
const items = node.children
|
|
74
|
+
.filter((child) => child.type === "listItem")
|
|
75
|
+
.map((child, index) => {
|
|
76
|
+
const text = renderBlock(child, ctx).trim();
|
|
77
|
+
return node.ordered ? `${getOrderedListPrefix(index)}${text}` : text;
|
|
78
|
+
});
|
|
79
|
+
return `${items.join(node.ordered ? " " : getUnorderedListSeparator(items.length))}\n\n`;
|
|
80
|
+
}
|
|
81
|
+
case "listItem": {
|
|
82
|
+
const text = renderBlockChildren(node.children, ctx).trim();
|
|
83
|
+
if (node.checked === true) {
|
|
84
|
+
return `done: ${text}`;
|
|
85
|
+
}
|
|
86
|
+
if (node.checked === false) {
|
|
87
|
+
return `to do: ${text}`;
|
|
88
|
+
}
|
|
89
|
+
return text;
|
|
90
|
+
}
|
|
91
|
+
case "table": {
|
|
92
|
+
const [headerRow, ...bodyRows] = node.children.filter((child) => child.type === "tableRow");
|
|
93
|
+
if (!headerRow) {
|
|
94
|
+
return "\n\n";
|
|
95
|
+
}
|
|
96
|
+
const headers = headerRow.children.map((cell) => cell.type === "tableCell" ? renderChildren(cell.children, ctx).trim() : "");
|
|
97
|
+
const sentences = bodyRows.flatMap((row) => row.children.flatMap((cell, index) => {
|
|
98
|
+
if (cell.type !== "tableCell") {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
const header = headers[index]?.trim() ?? "";
|
|
102
|
+
const value = renderChildren(cell.children, ctx).trim();
|
|
103
|
+
return value === "" ? [] : `${header} is ${value}.`;
|
|
104
|
+
}));
|
|
105
|
+
return `${sentences.join(" ")}\n\n`;
|
|
106
|
+
}
|
|
107
|
+
case "tableRow":
|
|
108
|
+
case "tableCell":
|
|
109
|
+
return "";
|
|
110
|
+
case "code": {
|
|
111
|
+
const prefix = ctx.announceCode ? "Code: " : "";
|
|
112
|
+
const value = node.value.length === 0 && ctx.announceCode ? "Code:" : `${prefix}${node.value}`;
|
|
113
|
+
return `${value}\n\n`;
|
|
114
|
+
}
|
|
115
|
+
case "frontmatter": {
|
|
116
|
+
if (!ctx.includeFrontmatter) {
|
|
117
|
+
return "";
|
|
118
|
+
}
|
|
119
|
+
return `${Object.entries(node.data)
|
|
120
|
+
.map(([key, value]) => `${key}: ${String(value)}.`)
|
|
121
|
+
.join(" ")}\n\n`;
|
|
122
|
+
}
|
|
123
|
+
case "footnoteDefinition":
|
|
124
|
+
return "";
|
|
125
|
+
default:
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function renderBlockChildren(nodes, ctx) {
|
|
130
|
+
return nodes
|
|
131
|
+
.map((node) => (isBlockNode(node) ? renderBlock(node, ctx) : renderInline(node, ctx)))
|
|
132
|
+
.join("");
|
|
133
|
+
}
|
|
134
|
+
function isBlockNode(node) {
|
|
135
|
+
switch (node.type) {
|
|
136
|
+
case "root":
|
|
137
|
+
case "paragraph":
|
|
138
|
+
case "thematicBreak":
|
|
139
|
+
case "heading":
|
|
140
|
+
case "blockquote":
|
|
141
|
+
case "alert":
|
|
142
|
+
case "list":
|
|
143
|
+
case "listItem":
|
|
144
|
+
case "table":
|
|
145
|
+
case "tableRow":
|
|
146
|
+
case "tableCell":
|
|
147
|
+
case "code":
|
|
148
|
+
case "frontmatter":
|
|
149
|
+
case "footnoteDefinition":
|
|
150
|
+
return true;
|
|
151
|
+
default:
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function collectFootnoteDefinitions(nodes, ctx) {
|
|
156
|
+
for (const node of nodes) {
|
|
157
|
+
if (node.type === "footnoteDefinition") {
|
|
158
|
+
ctx.footnoteDefinitions.set(node.label, renderBlockChildren(node.children, createFootnoteDefinitionContext(ctx)).trim());
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if ("children" in node) {
|
|
162
|
+
collectFootnoteDefinitions(node.children, ctx);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function createFootnoteDefinitionContext(ctx) {
|
|
167
|
+
return {
|
|
168
|
+
announceHeadings: ctx.announceHeadings,
|
|
169
|
+
announceCode: ctx.announceCode,
|
|
170
|
+
announceAlerts: ctx.announceAlerts,
|
|
171
|
+
showLinks: ctx.showLinks,
|
|
172
|
+
expandLinks: ctx.expandLinks,
|
|
173
|
+
includeFrontmatter: ctx.includeFrontmatter,
|
|
174
|
+
footnoteDefinitions: new Map(),
|
|
175
|
+
footnoteOrder: []
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function renderReferencedFootnotes(ctx) {
|
|
179
|
+
return ctx.footnoteOrder
|
|
180
|
+
.map((label, index) => {
|
|
181
|
+
const definitionText = ctx.footnoteDefinitions.get(label);
|
|
182
|
+
return definitionText === undefined ? "" : `Note ${index + 1}: ${definitionText}.`;
|
|
183
|
+
})
|
|
184
|
+
.filter((value) => value.length > 0)
|
|
185
|
+
.join(" ");
|
|
186
|
+
}
|
|
187
|
+
function getOrderedListPrefix(index) {
|
|
188
|
+
switch (index) {
|
|
189
|
+
case 0:
|
|
190
|
+
return "First, ";
|
|
191
|
+
case 1:
|
|
192
|
+
return "Second, ";
|
|
193
|
+
case 2:
|
|
194
|
+
return "Third, ";
|
|
195
|
+
default:
|
|
196
|
+
return "Next, ";
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function getUnorderedListSeparator(itemCount) {
|
|
200
|
+
return itemCount <= 3 ? ", " : "; ";
|
|
201
|
+
}
|
|
202
|
+
function trimBlockSeparators(value) {
|
|
203
|
+
let start = 0;
|
|
204
|
+
let end = value.length;
|
|
205
|
+
while (start < end && value[start] === "\n") {
|
|
206
|
+
start += 1;
|
|
207
|
+
}
|
|
208
|
+
while (end > start && value[end - 1] === "\n") {
|
|
209
|
+
end -= 1;
|
|
210
|
+
}
|
|
211
|
+
return value.slice(start, end);
|
|
212
|
+
}
|
|
213
|
+
export function renderPlaintext(ast, options) {
|
|
214
|
+
return renderBlock(ast, {
|
|
215
|
+
announceHeadings: options?.announceHeadings ?? true,
|
|
216
|
+
announceCode: options?.announceCode ?? true,
|
|
217
|
+
announceAlerts: options?.announceAlerts ?? true,
|
|
218
|
+
showLinks: options?.showLinks ?? false,
|
|
219
|
+
expandLinks: options?.expandLinks ?? false,
|
|
220
|
+
includeFrontmatter: options?.includeFrontmatter ?? false,
|
|
221
|
+
footnoteDefinitions: new Map(),
|
|
222
|
+
footnoteOrder: []
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
export function renderMarkdownPlaintext(markdown, options) {
|
|
226
|
+
const { ast } = parse(markdown);
|
|
227
|
+
return renderPlaintext(ast, options);
|
|
228
|
+
}
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
30
|
"import": "./dist/index.js"
|
|
31
31
|
},
|
|
32
|
+
"./render-markdown-plaintext": {
|
|
33
|
+
"types": "./dist/render-markdown-plaintext.d.ts",
|
|
34
|
+
"import": "./dist/render-markdown-plaintext.js"
|
|
35
|
+
},
|
|
32
36
|
"./*": {
|
|
33
37
|
"types": "./dist/*.d.ts",
|
|
34
38
|
"import": "./dist/*.js"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.85",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"types": "./dist/design.d.ts",
|
|
18
18
|
"import": "./dist/design.js"
|
|
19
19
|
},
|
|
20
|
+
"./design/render-markdown-plaintext": {
|
|
21
|
+
"types": "./dist/design/render-markdown-plaintext.d.ts",
|
|
22
|
+
"import": "./dist/design/render-markdown-plaintext.js"
|
|
23
|
+
},
|
|
20
24
|
"./design/*": {
|
|
21
25
|
"types": "./dist/design/*.d.ts",
|
|
22
26
|
"import": "./dist/design/*.js"
|
|
@@ -51,7 +55,7 @@
|
|
|
51
55
|
"postpack": "node ../../scripts/manage-bundled-workspace-deps.mjs cleanup . toolcraft-design @poe-code/frontmatter @poe-code/agent-mcp-config @poe-code/agent-human-in-loop @poe-code/task-list @poe-code/agent-defs @poe-code/config-mutations @poe-code/process-runner tiny-mcp-client mcp-oauth auth-store"
|
|
52
56
|
},
|
|
53
57
|
"dependencies": {
|
|
54
|
-
"toolcraft-schema": "0.0.
|
|
58
|
+
"toolcraft-schema": "0.0.85",
|
|
55
59
|
"commander": "^13.1.0",
|
|
56
60
|
"fast-string-width": "^3.0.2",
|
|
57
61
|
"fast-wrap-ansi": "^0.2.0",
|