toolcraft-openapi 0.0.74 → 0.0.76
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/node_modules/toolcraft-design/README.md +47 -3
- package/node_modules/toolcraft-design/dist/brand.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/brand.js +1 -0
- package/node_modules/toolcraft-design/dist/brands.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/brands.js +1 -0
- package/node_modules/toolcraft-design/dist/cancel.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/cancel.js +1 -0
- package/node_modules/toolcraft-design/dist/color.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/color.js +1 -0
- package/node_modules/toolcraft-design/dist/configure-theme.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/configure-theme.js +1 -0
- package/node_modules/toolcraft-design/dist/confirm-or-cancel.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/confirm-or-cancel.js +1 -0
- package/node_modules/toolcraft-design/dist/confirm.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/confirm.js +1 -0
- package/node_modules/toolcraft-design/dist/create-dashboard.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/create-dashboard.js +1 -0
- package/node_modules/toolcraft-design/dist/create-logger.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/create-logger.js +1 -0
- package/node_modules/toolcraft-design/dist/dark.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/dark.js +1 -0
- package/node_modules/toolcraft-design/dist/format-columns.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/format-columns.js +1 -0
- package/node_modules/toolcraft-design/dist/format-command-list.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/format-command-list.js +1 -0
- package/node_modules/toolcraft-design/dist/format-command-not-found-panel.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/format-command-not-found-panel.js +1 -0
- package/node_modules/toolcraft-design/dist/format-command-not-found.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/format-command-not-found.js +1 -0
- package/node_modules/toolcraft-design/dist/format-command.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/format-command.js +1 -0
- package/node_modules/toolcraft-design/dist/format-option-list.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/format-option-list.js +1 -0
- package/node_modules/toolcraft-design/dist/format-option.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/format-option.js +1 -0
- package/node_modules/toolcraft-design/dist/format-usage.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/format-usage.js +1 -0
- package/node_modules/toolcraft-design/dist/get-template-partial-names.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/get-template-partial-names.js +1 -0
- package/node_modules/toolcraft-design/dist/get-theme-config.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/get-theme-config.js +1 -0
- package/node_modules/toolcraft-design/dist/get-theme.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/get-theme.js +1 -0
- package/node_modules/toolcraft-design/dist/help-formatter-plain.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/help-formatter-plain.js +2 -0
- package/node_modules/toolcraft-design/dist/help-formatter.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/help-formatter.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/intro-plain.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/intro-plain.js +1 -0
- package/node_modules/toolcraft-design/dist/intro.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/intro.js +1 -0
- package/node_modules/toolcraft-design/dist/is-cancel.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/is-cancel.js +1 -0
- package/node_modules/toolcraft-design/dist/light.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/light.js +1 -0
- package/node_modules/toolcraft-design/dist/log.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/log.js +1 -0
- package/node_modules/toolcraft-design/dist/logger.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/logger.js +1 -0
- package/node_modules/toolcraft-design/dist/multiselect.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/multiselect.js +1 -0
- package/node_modules/toolcraft-design/dist/note.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/note.js +1 -0
- package/node_modules/toolcraft-design/dist/open-external.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/open-external.js +1 -0
- package/node_modules/toolcraft-design/dist/outro.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/outro.js +1 -0
- package/node_modules/toolcraft-design/dist/parse.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/parse.js +1 -0
- package/node_modules/toolcraft-design/dist/password.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/password.js +1 -0
- package/node_modules/toolcraft-design/dist/prompt-cancelled-error.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/prompt-cancelled-error.js +1 -0
- package/node_modules/toolcraft-design/dist/prompt-text.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/prompt-text.js +1 -0
- package/node_modules/toolcraft-design/dist/prompt-theme.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/prompt-theme.js +1 -0
- package/node_modules/toolcraft-design/dist/render-catalog.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-catalog.js +1 -0
- package/node_modules/toolcraft-design/dist/render-detail-card.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-detail-card.js +1 -0
- package/node_modules/toolcraft-design/dist/render-html.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-html.js +1 -0
- package/node_modules/toolcraft-design/dist/render-inspector-card.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-inspector-card.js +1 -0
- package/node_modules/toolcraft-design/dist/render-markdown-html.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-markdown-html.js +1 -0
- package/node_modules/toolcraft-design/dist/render-markdown.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-markdown.js +1 -0
- package/node_modules/toolcraft-design/dist/render-menu.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-menu.js +1 -0
- package/node_modules/toolcraft-design/dist/render-resource-browser.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-resource-browser.js +1 -0
- package/node_modules/toolcraft-design/dist/render-spinner-frame.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-spinner-frame.js +1 -0
- package/node_modules/toolcraft-design/dist/render-spinner-stopped.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-spinner-stopped.js +1 -0
- package/node_modules/toolcraft-design/dist/render-table.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-table.js +1 -0
- package/node_modules/toolcraft-design/dist/render-template.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render-template.js +1 -0
- package/node_modules/toolcraft-design/dist/render.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/render.js +1 -0
- package/node_modules/toolcraft-design/dist/reset-output-format-cache.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/reset-output-format-cache.js +1 -0
- package/node_modules/toolcraft-design/dist/reset-theme-cache.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/reset-theme-cache.js +1 -0
- package/node_modules/toolcraft-design/dist/reset-theme.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/reset-theme.js +1 -0
- package/node_modules/toolcraft-design/dist/resolve-output-format.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/resolve-output-format.js +1 -0
- package/node_modules/toolcraft-design/dist/resolve-template-partials.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/resolve-template-partials.js +1 -0
- package/node_modules/toolcraft-design/dist/resolve-theme-name.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/resolve-theme-name.js +1 -0
- package/node_modules/toolcraft-design/dist/run-explorer.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/run-explorer.js +1 -0
- package/node_modules/toolcraft-design/dist/run-two-pane-explorer.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/run-two-pane-explorer.js +1 -0
- package/node_modules/toolcraft-design/dist/select.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/select.js +1 -0
- package/node_modules/toolcraft-design/dist/should-use-interactive-dashboard.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/should-use-interactive-dashboard.js +1 -0
- package/node_modules/toolcraft-design/dist/single-detail.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/single-detail.js +1 -0
- package/node_modules/toolcraft-design/dist/spacing.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/spacing.js +1 -0
- package/node_modules/toolcraft-design/dist/spinner-frames.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/spinner-frames.js +1 -0
- package/node_modules/toolcraft-design/dist/spinner.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/spinner.js +1 -0
- package/node_modules/toolcraft-design/dist/strip-ansi.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/strip-ansi.js +1 -0
- package/node_modules/toolcraft-design/dist/symbols.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/symbols.js +1 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/html-renderer.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/html-renderer.js +356 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/index.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/index.js +6 -0
- package/node_modules/toolcraft-design/dist/text.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/text.js +1 -0
- package/node_modules/toolcraft-design/dist/typography.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/typography.js +1 -0
- package/node_modules/toolcraft-design/dist/widths.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/widths.js +1 -0
- package/node_modules/toolcraft-design/dist/with-output-format.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/with-output-format.js +1 -0
- package/node_modules/toolcraft-design/dist/with-spinner.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/with-spinner.js +1 -0
- package/node_modules/toolcraft-design/package.json +4 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { symbols } from "./components/symbols.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { symbols } from "./components/symbols.js";
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
export function renderHtml(ast, options = {}) {
|
|
2
|
+
const context = {
|
|
3
|
+
showFrontmatter: options.showFrontmatter ?? false,
|
|
4
|
+
allowRawHtml: options.allowRawHtml ?? false,
|
|
5
|
+
footnotes: ast.type === "root" ? createFootnoteState(ast.children) : undefined
|
|
6
|
+
};
|
|
7
|
+
return renderNode(ast, context);
|
|
8
|
+
}
|
|
9
|
+
function renderNode(node, context) {
|
|
10
|
+
switch (node.type) {
|
|
11
|
+
case "root":
|
|
12
|
+
return renderRoot(node, context);
|
|
13
|
+
case "heading":
|
|
14
|
+
return renderHeading(node, context);
|
|
15
|
+
case "paragraph":
|
|
16
|
+
return renderParagraph(node, context);
|
|
17
|
+
case "blockquote":
|
|
18
|
+
return renderBlockquote(node, context);
|
|
19
|
+
case "alert":
|
|
20
|
+
return renderAlert(node, context);
|
|
21
|
+
case "code":
|
|
22
|
+
return renderCodeBlock(node);
|
|
23
|
+
case "list":
|
|
24
|
+
return renderList(node, context);
|
|
25
|
+
case "table":
|
|
26
|
+
return renderTable(node, context);
|
|
27
|
+
case "html":
|
|
28
|
+
return context.allowRawHtml ? node.value : escapeHtml(node.value);
|
|
29
|
+
case "thematicBreak":
|
|
30
|
+
return "<hr>";
|
|
31
|
+
case "frontmatter":
|
|
32
|
+
return context.showFrontmatter ? renderFrontmatter(node.data) : "";
|
|
33
|
+
case "footnoteDefinition":
|
|
34
|
+
return "";
|
|
35
|
+
case "text":
|
|
36
|
+
case "strong":
|
|
37
|
+
case "emphasis":
|
|
38
|
+
case "strikethrough":
|
|
39
|
+
case "inlineCode":
|
|
40
|
+
case "link":
|
|
41
|
+
case "image":
|
|
42
|
+
case "break":
|
|
43
|
+
case "footnoteReference":
|
|
44
|
+
return renderInline(node, context);
|
|
45
|
+
default:
|
|
46
|
+
return "children" in node ? renderChildren(node.children, context) : "";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function renderRoot(node, context) {
|
|
50
|
+
const blocks = node.children
|
|
51
|
+
.filter((child) => child.type !== "footnoteDefinition")
|
|
52
|
+
.map((child) => renderNode(child, context))
|
|
53
|
+
.filter((value) => value.length > 0);
|
|
54
|
+
const footnotes = renderReferencedFootnotes(context);
|
|
55
|
+
if (footnotes.length > 0) {
|
|
56
|
+
blocks.push(footnotes);
|
|
57
|
+
}
|
|
58
|
+
return blocks.join("\n");
|
|
59
|
+
}
|
|
60
|
+
function renderChildren(children, context) {
|
|
61
|
+
return children
|
|
62
|
+
.map((child) => renderNode(child, context))
|
|
63
|
+
.filter((value) => value.length > 0)
|
|
64
|
+
.join("\n");
|
|
65
|
+
}
|
|
66
|
+
function renderHeading(node, context) {
|
|
67
|
+
const content = renderInlineChildren(node.children, context);
|
|
68
|
+
return content.length === 0 ? "" : `<h${node.depth}>${content}</h${node.depth}>`;
|
|
69
|
+
}
|
|
70
|
+
function renderParagraph(node, context) {
|
|
71
|
+
const content = renderInlineChildren(node.children, context);
|
|
72
|
+
return content.length === 0 ? "" : `<p>${content}</p>`;
|
|
73
|
+
}
|
|
74
|
+
function renderBlockquote(node, context) {
|
|
75
|
+
const content = renderChildren(node.children, context);
|
|
76
|
+
return `<blockquote>${content}</blockquote>`;
|
|
77
|
+
}
|
|
78
|
+
function renderAlert(node, context) {
|
|
79
|
+
const content = renderChildren(node.children, context);
|
|
80
|
+
return `<blockquote data-alert="${escapeAttribute(node.kind)}">${content}</blockquote>`;
|
|
81
|
+
}
|
|
82
|
+
function renderCodeBlock(node) {
|
|
83
|
+
const classAttribute = node.lang === undefined || node.lang.length === 0
|
|
84
|
+
? ""
|
|
85
|
+
: ` class="language-${escapeAttribute(node.lang)}"`;
|
|
86
|
+
return `<pre><code${classAttribute}>${escapeHtml(node.value)}</code></pre>`;
|
|
87
|
+
}
|
|
88
|
+
function renderList(node, context) {
|
|
89
|
+
const tag = node.ordered ? "ol" : "ul";
|
|
90
|
+
const startAttribute = node.ordered && node.start !== undefined && node.start !== 1
|
|
91
|
+
? ` start="${escapeAttribute(String(node.start))}"`
|
|
92
|
+
: "";
|
|
93
|
+
const items = node.children
|
|
94
|
+
.map((child) => (child.type === "listItem" ? renderListItem(child, context) : renderNode(child, context)))
|
|
95
|
+
.filter((value) => value.length > 0)
|
|
96
|
+
.join("");
|
|
97
|
+
return items.length === 0 ? "" : `<${tag}${startAttribute}>${items}</${tag}>`;
|
|
98
|
+
}
|
|
99
|
+
function renderListItem(node, context) {
|
|
100
|
+
const renderedChildren = node.children
|
|
101
|
+
.map((child, index) => {
|
|
102
|
+
if (index === 0 && child.type === "paragraph") {
|
|
103
|
+
return renderInlineChildren(child.children, context);
|
|
104
|
+
}
|
|
105
|
+
return renderNode(child, context);
|
|
106
|
+
})
|
|
107
|
+
.filter((value) => value.length > 0);
|
|
108
|
+
const checkbox = renderTaskCheckbox(node);
|
|
109
|
+
return `<li>${checkbox}${renderedChildren.join("")}</li>`;
|
|
110
|
+
}
|
|
111
|
+
function renderTaskCheckbox(node) {
|
|
112
|
+
if (node.checked === true) {
|
|
113
|
+
return '<input type="checkbox" disabled checked> ';
|
|
114
|
+
}
|
|
115
|
+
if (node.checked === false) {
|
|
116
|
+
return '<input type="checkbox" disabled> ';
|
|
117
|
+
}
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
120
|
+
function renderTable(node, context) {
|
|
121
|
+
const rows = node.children.filter((child) => child.type === "tableRow");
|
|
122
|
+
const headerRow = rows[0];
|
|
123
|
+
if (headerRow === undefined) {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
const header = `<thead>${renderTableRow(headerRow, node.align, "th", context)}</thead>`;
|
|
127
|
+
const bodyRows = rows
|
|
128
|
+
.slice(1)
|
|
129
|
+
.map((row) => renderTableRow(row, node.align, "td", context))
|
|
130
|
+
.join("");
|
|
131
|
+
const body = `<tbody>${bodyRows}</tbody>`;
|
|
132
|
+
return ["<table>", header, body, "</table>"].join("\n");
|
|
133
|
+
}
|
|
134
|
+
function renderTableRow(node, alignments, cellTag, context) {
|
|
135
|
+
const cells = node.children
|
|
136
|
+
.map((cell, index) => {
|
|
137
|
+
if (cell.type !== "tableCell") {
|
|
138
|
+
return "";
|
|
139
|
+
}
|
|
140
|
+
const style = renderTableAlignment(alignments[index] ?? null);
|
|
141
|
+
return `<${cellTag}${style}>${renderInlineChildren(cell.children, context)}</${cellTag}>`;
|
|
142
|
+
})
|
|
143
|
+
.join("");
|
|
144
|
+
return `<tr>${cells}</tr>`;
|
|
145
|
+
}
|
|
146
|
+
function renderTableAlignment(alignment) {
|
|
147
|
+
if (alignment === null) {
|
|
148
|
+
return "";
|
|
149
|
+
}
|
|
150
|
+
return ` style="text-align: ${alignment}"`;
|
|
151
|
+
}
|
|
152
|
+
function renderFrontmatter(data) {
|
|
153
|
+
const lines = Object.entries(data).map(([key, value]) => `${key}: ${formatFrontmatterValue(value)}`);
|
|
154
|
+
if (lines.length === 0) {
|
|
155
|
+
return "";
|
|
156
|
+
}
|
|
157
|
+
return `<pre><code class="language-yaml">${escapeHtml(lines.join("\n"))}</code></pre>`;
|
|
158
|
+
}
|
|
159
|
+
function formatFrontmatterValue(value) {
|
|
160
|
+
if (value === null) {
|
|
161
|
+
return "null";
|
|
162
|
+
}
|
|
163
|
+
if (typeof value === "string") {
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
167
|
+
return String(value);
|
|
168
|
+
}
|
|
169
|
+
const ancestors = [];
|
|
170
|
+
return JSON.stringify(value, function (_key, nestedValue) {
|
|
171
|
+
if (typeof nestedValue !== "object" || nestedValue === null) {
|
|
172
|
+
return nestedValue;
|
|
173
|
+
}
|
|
174
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {
|
|
175
|
+
ancestors.pop();
|
|
176
|
+
}
|
|
177
|
+
if (ancestors.includes(nestedValue)) {
|
|
178
|
+
return "[Circular]";
|
|
179
|
+
}
|
|
180
|
+
ancestors.push(nestedValue);
|
|
181
|
+
return nestedValue;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function renderInlineChildren(children, context) {
|
|
185
|
+
return children.map((child) => renderInline(child, context)).join("");
|
|
186
|
+
}
|
|
187
|
+
function renderInline(node, context) {
|
|
188
|
+
switch (node.type) {
|
|
189
|
+
case "text":
|
|
190
|
+
return escapeHtml(node.value);
|
|
191
|
+
case "strong":
|
|
192
|
+
return `<strong>${renderInlineChildren(node.children, context)}</strong>`;
|
|
193
|
+
case "emphasis":
|
|
194
|
+
return `<em>${renderInlineChildren(node.children, context)}</em>`;
|
|
195
|
+
case "strikethrough":
|
|
196
|
+
return `<del>${renderInlineChildren(node.children, context)}</del>`;
|
|
197
|
+
case "inlineCode":
|
|
198
|
+
return `<code>${escapeHtml(node.value)}</code>`;
|
|
199
|
+
case "link":
|
|
200
|
+
return renderLink(node, context);
|
|
201
|
+
case "image":
|
|
202
|
+
return renderImage(node);
|
|
203
|
+
case "break":
|
|
204
|
+
return "<br>";
|
|
205
|
+
case "footnoteReference":
|
|
206
|
+
return renderFootnoteReference(node, context);
|
|
207
|
+
case "html":
|
|
208
|
+
return context.allowRawHtml ? node.value : escapeHtml(node.value);
|
|
209
|
+
default:
|
|
210
|
+
return "children" in node ? renderInlineChildren(node.children, context) : renderNode(node, context);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function renderLink(node, context) {
|
|
214
|
+
const href = sanitizeUrl(node.url);
|
|
215
|
+
const attributes = [
|
|
216
|
+
href === null ? "" : ` href="${escapeAttribute(href)}"`,
|
|
217
|
+
node.title === undefined ? "" : ` title="${escapeAttribute(node.title)}"`
|
|
218
|
+
].join("");
|
|
219
|
+
return `<a${attributes}>${renderInlineChildren(node.children, context)}</a>`;
|
|
220
|
+
}
|
|
221
|
+
function renderImage(node) {
|
|
222
|
+
const src = sanitizeUrl(node.url);
|
|
223
|
+
const attributes = [
|
|
224
|
+
src === null ? "" : ` src="${escapeAttribute(src)}"`,
|
|
225
|
+
` alt="${escapeAttribute(node.alt)}"`,
|
|
226
|
+
node.title === undefined ? "" : ` title="${escapeAttribute(node.title)}"`
|
|
227
|
+
].join("");
|
|
228
|
+
return `<img${attributes}>`;
|
|
229
|
+
}
|
|
230
|
+
function renderFootnoteReference(node, context) {
|
|
231
|
+
const footnotes = context.footnotes;
|
|
232
|
+
if (footnotes === undefined || !footnotes.definitions.has(node.label)) {
|
|
233
|
+
return "";
|
|
234
|
+
}
|
|
235
|
+
let number = footnotes.numbers.get(node.label);
|
|
236
|
+
if (number === undefined) {
|
|
237
|
+
footnotes.labelsInOrder.push(node.label);
|
|
238
|
+
number = footnotes.labelsInOrder.length;
|
|
239
|
+
footnotes.numbers.set(node.label, number);
|
|
240
|
+
}
|
|
241
|
+
const id = escapeAttribute(createFootnoteId(node.label));
|
|
242
|
+
return `<sup id="fnref-${id}"><a href="#fn-${id}">${number}</a></sup>`;
|
|
243
|
+
}
|
|
244
|
+
function renderReferencedFootnotes(context) {
|
|
245
|
+
const footnotes = context.footnotes;
|
|
246
|
+
if (footnotes === undefined || footnotes.labelsInOrder.length === 0) {
|
|
247
|
+
return "";
|
|
248
|
+
}
|
|
249
|
+
const items = footnotes.labelsInOrder
|
|
250
|
+
.map((label) => {
|
|
251
|
+
const definition = footnotes.definitions.get(label);
|
|
252
|
+
if (definition === undefined) {
|
|
253
|
+
return "";
|
|
254
|
+
}
|
|
255
|
+
const id = escapeAttribute(createFootnoteId(label));
|
|
256
|
+
const content = renderChildren(definition.children, context);
|
|
257
|
+
return `<li id="fn-${id}">${content} <a href="#fnref-${id}" aria-label="Back to content">Back</a></li>`;
|
|
258
|
+
})
|
|
259
|
+
.filter((value) => value.length > 0)
|
|
260
|
+
.join("");
|
|
261
|
+
return items.length === 0 ? "" : `<section class="footnotes"><ol>${items}</ol></section>`;
|
|
262
|
+
}
|
|
263
|
+
function createFootnoteState(children) {
|
|
264
|
+
const definitions = new Map();
|
|
265
|
+
for (const child of children) {
|
|
266
|
+
collectFootnoteDefinitions(child, definitions);
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
definitions,
|
|
270
|
+
labelsInOrder: [],
|
|
271
|
+
numbers: new Map()
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function collectFootnoteDefinitions(node, definitions) {
|
|
275
|
+
if (node.type === "footnoteDefinition") {
|
|
276
|
+
definitions.set(node.label, node);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if ("children" in node) {
|
|
280
|
+
for (const child of node.children) {
|
|
281
|
+
collectFootnoteDefinitions(child, definitions);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function createFootnoteId(label) {
|
|
286
|
+
return encodeURIComponent(label);
|
|
287
|
+
}
|
|
288
|
+
function sanitizeUrl(url) {
|
|
289
|
+
const trimmed = url.trim();
|
|
290
|
+
if (trimmed.startsWith("//")) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
const scheme = readScheme(trimmed);
|
|
294
|
+
if (scheme === null) {
|
|
295
|
+
return trimmed;
|
|
296
|
+
}
|
|
297
|
+
switch (scheme.toLowerCase()) {
|
|
298
|
+
case "http":
|
|
299
|
+
case "https":
|
|
300
|
+
case "mailto":
|
|
301
|
+
case "tel":
|
|
302
|
+
return trimmed;
|
|
303
|
+
default:
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function readScheme(url) {
|
|
308
|
+
let value = "";
|
|
309
|
+
for (let index = 0; index < url.length; index += 1) {
|
|
310
|
+
const char = url[index];
|
|
311
|
+
if (char === "/" || char === "?" || char === "#") {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
if (char === ":") {
|
|
315
|
+
return value.length === 0 ? null : value;
|
|
316
|
+
}
|
|
317
|
+
if (!isSchemeChar(char, index)) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
value += char;
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
function isSchemeChar(char, index) {
|
|
325
|
+
const code = char.charCodeAt(0);
|
|
326
|
+
const isAlpha = (code >= 65 && code <= 90) || (code >= 97 && code <= 122);
|
|
327
|
+
if (index === 0) {
|
|
328
|
+
return isAlpha;
|
|
329
|
+
}
|
|
330
|
+
return isAlpha || (code >= 48 && code <= 57) || char === "+" || char === "-" || char === ".";
|
|
331
|
+
}
|
|
332
|
+
function escapeHtml(value) {
|
|
333
|
+
let output = "";
|
|
334
|
+
for (const char of value) {
|
|
335
|
+
switch (char) {
|
|
336
|
+
case "&":
|
|
337
|
+
output += "&";
|
|
338
|
+
break;
|
|
339
|
+
case "<":
|
|
340
|
+
output += "<";
|
|
341
|
+
break;
|
|
342
|
+
case ">":
|
|
343
|
+
output += ">";
|
|
344
|
+
break;
|
|
345
|
+
case '"':
|
|
346
|
+
output += """;
|
|
347
|
+
break;
|
|
348
|
+
default:
|
|
349
|
+
output += char;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return output;
|
|
353
|
+
}
|
|
354
|
+
function escapeAttribute(value) {
|
|
355
|
+
return escapeHtml(value);
|
|
356
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { type HtmlRenderOptions } from "./html-renderer.js";
|
|
1
2
|
import { type RenderOptions } from "./renderer.js";
|
|
2
3
|
export type { MdNode } from "./ast.js";
|
|
4
|
+
export { renderHtml } from "./html-renderer.js";
|
|
5
|
+
export type { HtmlRenderOptions } from "./html-renderer.js";
|
|
3
6
|
export { parse } from "./parser.js";
|
|
4
7
|
export { render } from "./renderer.js";
|
|
5
8
|
export type { RenderOptions } from "./renderer.js";
|
|
6
9
|
export declare function renderMarkdown(markdown: string, options?: RenderOptions): string;
|
|
10
|
+
export declare function renderMarkdownHtml(markdown: string, options?: HtmlRenderOptions): string;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { parse } from "./parser.js";
|
|
2
|
+
import { renderHtml } from "./html-renderer.js";
|
|
2
3
|
import { render } from "./renderer.js";
|
|
4
|
+
export { renderHtml } from "./html-renderer.js";
|
|
3
5
|
export { parse } from "./parser.js";
|
|
4
6
|
export { render } from "./renderer.js";
|
|
5
7
|
export function renderMarkdown(markdown, options) {
|
|
6
8
|
const { ast } = parse(markdown);
|
|
7
9
|
return render(ast, options);
|
|
8
10
|
}
|
|
11
|
+
export function renderMarkdownHtml(markdown, options) {
|
|
12
|
+
const { ast } = parse(markdown);
|
|
13
|
+
return renderHtml(ast, options);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { text } from "./components/text.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { text } from "./components/text.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { typography } from "./tokens/typography.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { typography } from "./tokens/typography.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { widths } from "./tokens/widths.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { widths } from "./tokens/widths.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { withOutputFormat } from "./internal/output-format.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { withSpinner } from "./prompts/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft-openapi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.76",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"toolcraft-openapi-generate": "dist/bin/generate.js"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"toolcraft": "0.0.
|
|
31
|
+
"toolcraft": "0.0.76",
|
|
32
32
|
"auth-store": "^0.0.1",
|
|
33
33
|
"fast-string-width": "^3.0.2",
|
|
34
34
|
"fast-wrap-ansi": "^0.2.0",
|