@nicomatt69/streamtty 0.0.1
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/LICENSE +21 -0
- package/README.md +471 -0
- package/dist/ai-sdk-adapter.d.ts +113 -0
- package/dist/ai-sdk-adapter.d.ts.map +1 -0
- package/dist/ai-sdk-adapter.js +304 -0
- package/dist/ai-sdk-adapter.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +188 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors.d.ts +131 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +346 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +185 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +350 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +323 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/streaming-parser.d.ts +81 -0
- package/dist/parser/streaming-parser.d.ts.map +1 -0
- package/dist/parser/streaming-parser.js +522 -0
- package/dist/parser/streaming-parser.js.map +1 -0
- package/dist/performance.d.ts +139 -0
- package/dist/performance.d.ts.map +1 -0
- package/dist/performance.js +401 -0
- package/dist/performance.js.map +1 -0
- package/dist/plugins/index.d.ts +6 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +22 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/plugin-system-inline.d.ts +116 -0
- package/dist/plugins/plugin-system-inline.d.ts.map +1 -0
- package/dist/plugins/plugin-system-inline.js +289 -0
- package/dist/plugins/plugin-system-inline.js.map +1 -0
- package/dist/plugins/plugin-system.d.ts +65 -0
- package/dist/plugins/plugin-system.d.ts.map +1 -0
- package/dist/plugins/plugin-system.js +202 -0
- package/dist/plugins/plugin-system.js.map +1 -0
- package/dist/plugins/rehype/harden.d.ts +15 -0
- package/dist/plugins/rehype/harden.d.ts.map +1 -0
- package/dist/plugins/rehype/harden.js +71 -0
- package/dist/plugins/rehype/harden.js.map +1 -0
- package/dist/plugins/rehype/index.d.ts +5 -0
- package/dist/plugins/rehype/index.d.ts.map +1 -0
- package/dist/plugins/rehype/index.js +21 -0
- package/dist/plugins/rehype/index.js.map +1 -0
- package/dist/plugins/remark/index.d.ts +6 -0
- package/dist/plugins/remark/index.d.ts.map +1 -0
- package/dist/plugins/remark/index.js +22 -0
- package/dist/plugins/remark/index.js.map +1 -0
- package/dist/plugins/remark/math.d.ts +7 -0
- package/dist/plugins/remark/math.d.ts.map +1 -0
- package/dist/plugins/remark/math.js +22 -0
- package/dist/plugins/remark/math.js.map +1 -0
- package/dist/plugins/remark/mermaid.d.ts +7 -0
- package/dist/plugins/remark/mermaid.d.ts.map +1 -0
- package/dist/plugins/remark/mermaid.js +19 -0
- package/dist/plugins/remark/mermaid.js.map +1 -0
- package/dist/plugins/types.d.ts +72 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +3 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/renderer/blessed-renderer.d.ts +92 -0
- package/dist/renderer/blessed-renderer.d.ts.map +1 -0
- package/dist/renderer/blessed-renderer.js +610 -0
- package/dist/renderer/blessed-renderer.js.map +1 -0
- package/dist/renderers/index.d.ts +7 -0
- package/dist/renderers/index.d.ts.map +1 -0
- package/dist/renderers/index.js +21 -0
- package/dist/renderers/index.js.map +1 -0
- package/dist/renderers/math-renderer.d.ts +49 -0
- package/dist/renderers/math-renderer.d.ts.map +1 -0
- package/dist/renderers/math-renderer.js +193 -0
- package/dist/renderers/math-renderer.js.map +1 -0
- package/dist/renderers/mermaid-ascii.d.ts +14 -0
- package/dist/renderers/mermaid-ascii.d.ts.map +1 -0
- package/dist/renderers/mermaid-ascii.js +260 -0
- package/dist/renderers/mermaid-ascii.js.map +1 -0
- package/dist/renderers/mermaid-renderer.d.ts +79 -0
- package/dist/renderers/mermaid-renderer.d.ts.map +1 -0
- package/dist/renderers/mermaid-renderer.js +298 -0
- package/dist/renderers/mermaid-renderer.js.map +1 -0
- package/dist/renderers/shiki-ansi.d.ts +48 -0
- package/dist/renderers/shiki-ansi.d.ts.map +1 -0
- package/dist/renderers/shiki-ansi.js +206 -0
- package/dist/renderers/shiki-ansi.js.map +1 -0
- package/dist/renderers/table-ascii.d.ts +30 -0
- package/dist/renderers/table-ascii.d.ts.map +1 -0
- package/dist/renderers/table-ascii.js +243 -0
- package/dist/renderers/table-ascii.js.map +1 -0
- package/dist/renderers/table-renderer.d.ts +49 -0
- package/dist/renderers/table-renderer.d.ts.map +1 -0
- package/dist/renderers/table-renderer.js +224 -0
- package/dist/renderers/table-renderer.js.map +1 -0
- package/dist/renderers/unicode-math.d.ts +29 -0
- package/dist/renderers/unicode-math.d.ts.map +1 -0
- package/dist/renderers/unicode-math.js +181 -0
- package/dist/renderers/unicode-math.js.map +1 -0
- package/dist/security/ansi-sanitizer.d.ts +71 -0
- package/dist/security/ansi-sanitizer.d.ts.map +1 -0
- package/dist/security/ansi-sanitizer.js +275 -0
- package/dist/security/ansi-sanitizer.js.map +1 -0
- package/dist/security/chunk-processor.d.ts +81 -0
- package/dist/security/chunk-processor.d.ts.map +1 -0
- package/dist/security/chunk-processor.js +297 -0
- package/dist/security/chunk-processor.js.map +1 -0
- package/dist/security/index.d.ts +6 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +22 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/input-validator.d.ts +55 -0
- package/dist/security/input-validator.d.ts.map +1 -0
- package/dist/security/input-validator.js +201 -0
- package/dist/security/input-validator.js.map +1 -0
- package/dist/stream-protocol.d.ts +61 -0
- package/dist/stream-protocol.d.ts.map +1 -0
- package/dist/stream-protocol.js +214 -0
- package/dist/stream-protocol.js.map +1 -0
- package/dist/streamdown-compat.d.ts +74 -0
- package/dist/streamdown-compat.d.ts.map +1 -0
- package/dist/streamdown-compat.js +241 -0
- package/dist/streamdown-compat.js.map +1 -0
- package/dist/streaming/stream-stats.d.ts +97 -0
- package/dist/streaming/stream-stats.d.ts.map +1 -0
- package/dist/streaming/stream-stats.js +217 -0
- package/dist/streaming/stream-stats.js.map +1 -0
- package/dist/streaming-integration.d.ts +71 -0
- package/dist/streaming-integration.d.ts.map +1 -0
- package/dist/streaming-integration.js +194 -0
- package/dist/streaming-integration.js.map +1 -0
- package/dist/themes/index.d.ts +59 -0
- package/dist/themes/index.d.ts.map +1 -0
- package/dist/themes/index.js +122 -0
- package/dist/themes/index.js.map +1 -0
- package/dist/types/index.d.ts +222 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/plugin-types.d.ts +5 -0
- package/dist/types/plugin-types.d.ts.map +1 -0
- package/dist/types/plugin-types.js +6 -0
- package/dist/types/plugin-types.js.map +1 -0
- package/dist/types/stream-events.d.ts +71 -0
- package/dist/types/stream-events.d.ts.map +1 -0
- package/dist/types/stream-events.js +10 -0
- package/dist/types/stream-events.js.map +1 -0
- package/dist/utils/blessed-syntax-highlighter.d.ts +124 -0
- package/dist/utils/blessed-syntax-highlighter.d.ts.map +1 -0
- package/dist/utils/blessed-syntax-highlighter.js +440 -0
- package/dist/utils/blessed-syntax-highlighter.js.map +1 -0
- package/dist/utils/enhanced-table-renderer.d.ts +77 -0
- package/dist/utils/enhanced-table-renderer.d.ts.map +1 -0
- package/dist/utils/enhanced-table-renderer.js +376 -0
- package/dist/utils/enhanced-table-renderer.js.map +1 -0
- package/dist/utils/formatting.d.ts +100 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/formatting.js +220 -0
- package/dist/utils/formatting.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/math-unicode-renderer.d.ts +38 -0
- package/dist/utils/math-unicode-renderer.d.ts.map +1 -0
- package/dist/utils/math-unicode-renderer.js +380 -0
- package/dist/utils/math-unicode-renderer.js.map +1 -0
- package/dist/utils/mermaid-ascii-renderer.d.ts +20 -0
- package/dist/utils/mermaid-ascii-renderer.d.ts.map +1 -0
- package/dist/utils/mermaid-ascii-renderer.js +325 -0
- package/dist/utils/mermaid-ascii-renderer.js.map +1 -0
- package/dist/utils/mermaid-ascii.d.ts +53 -0
- package/dist/utils/mermaid-ascii.d.ts.map +1 -0
- package/dist/utils/mermaid-ascii.js +181 -0
- package/dist/utils/mermaid-ascii.js.map +1 -0
- package/dist/utils/shiki-ansi-renderer.d.ts +29 -0
- package/dist/utils/shiki-ansi-renderer.d.ts.map +1 -0
- package/dist/utils/shiki-ansi-renderer.js +354 -0
- package/dist/utils/shiki-ansi-renderer.js.map +1 -0
- package/dist/utils/syntax-highlighter.d.ts +87 -0
- package/dist/utils/syntax-highlighter.d.ts.map +1 -0
- package/dist/utils/syntax-highlighter.js +265 -0
- package/dist/utils/syntax-highlighter.js.map +1 -0
- package/dist/utils/table-formatter-inline.d.ts +37 -0
- package/dist/utils/table-formatter-inline.d.ts.map +1 -0
- package/dist/utils/table-formatter-inline.js +337 -0
- package/dist/utils/table-formatter-inline.js.map +1 -0
- package/dist/utils/table.d.ts +35 -0
- package/dist/utils/table.d.ts.map +1 -0
- package/dist/utils/table.js +197 -0
- package/dist/utils/table.js.map +1 -0
- package/dist/widgets/stream-indicator.d.ts +130 -0
- package/dist/widgets/stream-indicator.d.ts.map +1 -0
- package/dist/widgets/stream-indicator.js +276 -0
- package/dist/widgets/stream-indicator.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ANSI-based syntax highlighting for terminal output
|
|
4
|
+
* Uses standard ANSI color codes for highlighting paths, keywords, and other elements
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.syntaxColors = void 0;
|
|
8
|
+
exports.highlightPaths = highlightPaths;
|
|
9
|
+
exports.highlightFileRefs = highlightFileRefs;
|
|
10
|
+
exports.highlightKeywords = highlightKeywords;
|
|
11
|
+
exports.highlightTitles = highlightTitles;
|
|
12
|
+
exports.highlightStrings = highlightStrings;
|
|
13
|
+
exports.highlightNumbers = highlightNumbers;
|
|
14
|
+
exports.highlightComments = highlightComments;
|
|
15
|
+
exports.highlightShellCommands = highlightShellCommands;
|
|
16
|
+
exports.highlightPackages = highlightPackages;
|
|
17
|
+
exports.highlightCodeBlocks = highlightCodeBlocks;
|
|
18
|
+
exports.applySyntaxHighlight = applySyntaxHighlight;
|
|
19
|
+
exports.applyLightSyntaxHighlight = applyLightSyntaxHighlight;
|
|
20
|
+
exports.stripAnsiColors = stripAnsiColors;
|
|
21
|
+
exports.colorizeBlock = colorizeBlock;
|
|
22
|
+
/**
|
|
23
|
+
* ANSI color codes for syntax highlighting
|
|
24
|
+
*/
|
|
25
|
+
exports.syntaxColors = {
|
|
26
|
+
path: '\x1b[36m', // Cyan for file paths
|
|
27
|
+
lineNumber: '\x1b[33m', // Yellow for line numbers
|
|
28
|
+
keyword: '\x1b[35m', // Magenta for keywords
|
|
29
|
+
string: '\x1b[32m', // Green for strings
|
|
30
|
+
number: '\x1b[93m', // Bright yellow for numbers
|
|
31
|
+
comment: '\x1b[90m', // Dark gray for comments
|
|
32
|
+
title: '\x1b[96m', // Bright cyan for titles
|
|
33
|
+
error: '\x1b[91m', // Bright red for errors
|
|
34
|
+
success: '\x1b[92m', // Bright green for success
|
|
35
|
+
warning: '\x1b[93m', // Bright yellow for warnings
|
|
36
|
+
codeBlock: '\x1b[36m', // Cyan for code block delimiters
|
|
37
|
+
package: '\x1b[36m', // Cyan for package names
|
|
38
|
+
reset: '\x1b[0m', // Reset to default
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Common programming keywords to highlight
|
|
42
|
+
*/
|
|
43
|
+
const KEYWORDS = [
|
|
44
|
+
'async', 'await', 'function', 'const', 'let', 'var', 'class', 'interface',
|
|
45
|
+
'type', 'import', 'export', 'from', 'return', 'if', 'else', 'for', 'while',
|
|
46
|
+
'try', 'catch', 'throw', 'new', 'this', 'super', 'extends', 'implements',
|
|
47
|
+
'public', 'private', 'protected', 'static', 'readonly', 'enum', 'namespace',
|
|
48
|
+
];
|
|
49
|
+
/**
|
|
50
|
+
* Shell/bash commands to highlight
|
|
51
|
+
*/
|
|
52
|
+
const SHELL_COMMANDS = [
|
|
53
|
+
'git', 'npm', 'yarn', 'pnpm', 'docker', 'cd', 'ls', 'mkdir', 'rm', 'cp', 'mv',
|
|
54
|
+
'cat', 'grep', 'find', 'sed', 'awk', 'chmod', 'chown', 'sudo', 'apt', 'brew',
|
|
55
|
+
'curl', 'wget', 'tar', 'zip', 'unzip', 'ssh', 'scp', 'rsync', 'ps', 'kill',
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* Highlight file paths in text
|
|
59
|
+
* Matches: /path/to/file.ts, ./relative/path.js, ~/home/path
|
|
60
|
+
* NOTE: Disabled to avoid ANSI code injection issues
|
|
61
|
+
*/
|
|
62
|
+
function highlightPaths(text) {
|
|
63
|
+
// Path highlighting disabled to prevent ANSI code leakage
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Highlight file references with line numbers
|
|
68
|
+
* Matches: file.ts:123, /path/to/file.js:45:10
|
|
69
|
+
* NOTE: Disabled to avoid ANSI code injection issues
|
|
70
|
+
*/
|
|
71
|
+
function highlightFileRefs(text) {
|
|
72
|
+
// File reference highlighting disabled to prevent ANSI code leakage
|
|
73
|
+
return text;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Highlight programming keywords
|
|
77
|
+
*/
|
|
78
|
+
function highlightKeywords(text) {
|
|
79
|
+
let highlighted = text;
|
|
80
|
+
for (const keyword of KEYWORDS) {
|
|
81
|
+
// Match whole words only (with word boundaries)
|
|
82
|
+
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
83
|
+
highlighted = highlighted.replace(regex, `${exports.syntaxColors.keyword}$1${exports.syntaxColors.reset}`);
|
|
84
|
+
}
|
|
85
|
+
return highlighted;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Highlight markdown-style titles
|
|
89
|
+
* Matches: # Title, ## Subtitle, etc.
|
|
90
|
+
*/
|
|
91
|
+
function highlightTitles(text) {
|
|
92
|
+
// Match markdown headers
|
|
93
|
+
const titleRegex = /^(#{1,6})\s+(.+)$/gm;
|
|
94
|
+
return text.replace(titleRegex, (match, hashes, title) => {
|
|
95
|
+
return `${exports.syntaxColors.title}${hashes} ${title}${exports.syntaxColors.reset}`;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Highlight string literals in quotes
|
|
100
|
+
*/
|
|
101
|
+
function highlightStrings(text) {
|
|
102
|
+
// Match single and double quoted strings
|
|
103
|
+
const stringRegex = /(["'])(?:(?=(\\?))\2.)*?\1/g;
|
|
104
|
+
return text.replace(stringRegex, (match) => {
|
|
105
|
+
return `${exports.syntaxColors.string}${match}${exports.syntaxColors.reset}`;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Highlight numbers
|
|
110
|
+
*/
|
|
111
|
+
function highlightNumbers(text) {
|
|
112
|
+
// Match numbers (integers and floats)
|
|
113
|
+
const numberRegex = /\b(\d+\.?\d*)\b/g;
|
|
114
|
+
return text.replace(numberRegex, `${exports.syntaxColors.number}$1${exports.syntaxColors.reset}`);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Highlight code comments
|
|
118
|
+
* Matches single-line and multi-line comments, bash comments
|
|
119
|
+
*/
|
|
120
|
+
function highlightComments(text) {
|
|
121
|
+
let highlighted = text;
|
|
122
|
+
// Bash comments (# comment)
|
|
123
|
+
highlighted = highlighted.replace(/(#.*)$/gm, (match) => {
|
|
124
|
+
// Avoid highlighting markdown headers
|
|
125
|
+
if (/^#{1,6}\s/.test(match))
|
|
126
|
+
return match;
|
|
127
|
+
return `${exports.syntaxColors.comment}${match}${exports.syntaxColors.reset}`;
|
|
128
|
+
});
|
|
129
|
+
// Single-line comments
|
|
130
|
+
highlighted = highlighted.replace(/(\/\/.*)$/gm, `${exports.syntaxColors.comment}$1${exports.syntaxColors.reset}`);
|
|
131
|
+
// Multi-line comments
|
|
132
|
+
highlighted = highlighted.replace(/(\/\*[\s\S]*?\*\/)/g, `${exports.syntaxColors.comment}$1${exports.syntaxColors.reset}`);
|
|
133
|
+
return highlighted;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Highlight shell/bash commands
|
|
137
|
+
*/
|
|
138
|
+
function highlightShellCommands(text) {
|
|
139
|
+
let highlighted = text;
|
|
140
|
+
for (const cmd of SHELL_COMMANDS) {
|
|
141
|
+
const regex = new RegExp(`\\b(${cmd})\\b`, 'g');
|
|
142
|
+
highlighted = highlighted.replace(regex, `${exports.syntaxColors.keyword}$1${exports.syntaxColors.reset}`);
|
|
143
|
+
}
|
|
144
|
+
return highlighted;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Highlight package names like @scope/package or package-name
|
|
148
|
+
*/
|
|
149
|
+
function highlightPackages(text) {
|
|
150
|
+
// Match npm package names: @scope/package or package-name
|
|
151
|
+
const packageRegex = /(@[\w-]+\/[\w-]+|[\w-]+\/[\w-]+|\b[\w-]+@[\d.]+)/g;
|
|
152
|
+
return text.replace(packageRegex, (match) => {
|
|
153
|
+
return `${exports.syntaxColors.package}${match}${exports.syntaxColors.reset}`;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Highlight markdown code blocks with syntax highlighting
|
|
158
|
+
*/
|
|
159
|
+
function highlightCodeBlocks(text) {
|
|
160
|
+
// Match ```lang\ncode\n``` blocks
|
|
161
|
+
const codeBlockRegex = /```(\w+)?\n([\s\S]*?)```/g;
|
|
162
|
+
return text.replace(codeBlockRegex, (match, lang, code) => {
|
|
163
|
+
// Highlight the opening fence
|
|
164
|
+
let result = `${exports.syntaxColors.codeBlock}\`\`\`${lang || ''}${exports.syntaxColors.reset}\n`;
|
|
165
|
+
// Apply language-specific highlighting
|
|
166
|
+
const highlightedCode = highlightCodeBlockContent(code, lang);
|
|
167
|
+
result += highlightedCode;
|
|
168
|
+
// Highlight the closing fence
|
|
169
|
+
result += `${exports.syntaxColors.codeBlock}\`\`\`${exports.syntaxColors.reset}`;
|
|
170
|
+
return result;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Highlight code block content based on language
|
|
175
|
+
*/
|
|
176
|
+
function highlightCodeBlockContent(code, lang) {
|
|
177
|
+
let highlighted = code;
|
|
178
|
+
// Bash/shell highlighting
|
|
179
|
+
if (lang === 'bash' || lang === 'sh' || lang === 'shell') {
|
|
180
|
+
highlighted = highlightShellCommands(highlighted);
|
|
181
|
+
highlighted = highlightComments(highlighted);
|
|
182
|
+
highlighted = highlightStrings(highlighted);
|
|
183
|
+
return highlighted;
|
|
184
|
+
}
|
|
185
|
+
// JavaScript/TypeScript highlighting
|
|
186
|
+
if (lang === 'javascript' || lang === 'js' || lang === 'typescript' || lang === 'ts') {
|
|
187
|
+
highlighted = highlightComments(highlighted);
|
|
188
|
+
highlighted = highlightStrings(highlighted);
|
|
189
|
+
highlighted = highlightKeywords(highlighted);
|
|
190
|
+
highlighted = highlightNumbers(highlighted);
|
|
191
|
+
return highlighted;
|
|
192
|
+
}
|
|
193
|
+
// Generic highlighting for other languages
|
|
194
|
+
highlighted = highlightComments(highlighted);
|
|
195
|
+
highlighted = highlightStrings(highlighted);
|
|
196
|
+
highlighted = highlightKeywords(highlighted);
|
|
197
|
+
highlighted = highlightNumbers(highlighted);
|
|
198
|
+
return highlighted;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Apply comprehensive syntax highlighting to text
|
|
202
|
+
* Applies all highlighting rules in the correct order
|
|
203
|
+
*/
|
|
204
|
+
function applySyntaxHighlight(text) {
|
|
205
|
+
if (!text)
|
|
206
|
+
return text;
|
|
207
|
+
let highlighted = text;
|
|
208
|
+
// Order matters: highlight specific patterns first, then broader patterns
|
|
209
|
+
// 0. Code blocks (must be first to avoid interfering with content inside)
|
|
210
|
+
highlighted = highlightCodeBlocks(highlighted);
|
|
211
|
+
// 1. File references (must be before paths to handle file.ts:123)
|
|
212
|
+
highlighted = highlightFileRefs(highlighted);
|
|
213
|
+
// 2. Paths
|
|
214
|
+
highlighted = highlightPaths(highlighted);
|
|
215
|
+
// 3. Packages (npm packages)
|
|
216
|
+
highlighted = highlightPackages(highlighted);
|
|
217
|
+
// 4. Titles
|
|
218
|
+
highlighted = highlightTitles(highlighted);
|
|
219
|
+
// 5. Comments (before keywords to avoid highlighting keywords in comments)
|
|
220
|
+
highlighted = highlightComments(highlighted);
|
|
221
|
+
// 6. Strings
|
|
222
|
+
highlighted = highlightStrings(highlighted);
|
|
223
|
+
// 7. Shell commands
|
|
224
|
+
highlighted = highlightShellCommands(highlighted);
|
|
225
|
+
// 8. Keywords
|
|
226
|
+
highlighted = highlightKeywords(highlighted);
|
|
227
|
+
// 9. Numbers
|
|
228
|
+
highlighted = highlightNumbers(highlighted);
|
|
229
|
+
return highlighted;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Apply syntax highlighting only to specific elements (more conservative)
|
|
233
|
+
*/
|
|
234
|
+
function applyLightSyntaxHighlight(text) {
|
|
235
|
+
if (!text)
|
|
236
|
+
return text;
|
|
237
|
+
let highlighted = text;
|
|
238
|
+
// Only highlight paths and file references
|
|
239
|
+
highlighted = highlightFileRefs(highlighted);
|
|
240
|
+
highlighted = highlightPaths(highlighted);
|
|
241
|
+
return highlighted;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Strip all ANSI color codes from text
|
|
245
|
+
* Handles multiple ANSI escape sequence formats
|
|
246
|
+
*/
|
|
247
|
+
function stripAnsiColors(text) {
|
|
248
|
+
// More comprehensive ANSI removal:
|
|
249
|
+
// \x1b\[[0-9;]*m - standard ANSI sequences
|
|
250
|
+
// \x1b\[[\d;]*[A-Za-z] - all ANSI control sequences
|
|
251
|
+
// \x1b[A-Z] - single char ANSI codes
|
|
252
|
+
return text
|
|
253
|
+
.replace(/\x1b\[[0-9;]*m/g, '') // Standard color codes
|
|
254
|
+
.replace(/\x1b\[[\d;]*[A-Za-z]/g, '') // All ANSI CSI sequences
|
|
255
|
+
.replace(/\x1b[A-Z]/g, '') // Single char sequences
|
|
256
|
+
.replace(/\x1b\([AB0-9]/g, '') // Character set sequences
|
|
257
|
+
.replace(/[\x00-\x08\x0B-\x0C\x0E-\x1F]/g, ''); // Other control chars
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Colorize entire text block with a specific color
|
|
261
|
+
*/
|
|
262
|
+
function colorizeBlock(text, color) {
|
|
263
|
+
return `${color}${text}${exports.syntaxColors.reset}`;
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=syntax-highlighter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-highlighter.js","sourceRoot":"","sources":["../../src/utils/syntax-highlighter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA+CH,wCAGC;AAOD,8CAGC;AAKD,8CAUC;AAMD,0CAMC;AAKD,4CAMC;AAKD,4CAIC;AAMD,8CA0BC;AAKD,wDASC;AAKD,8CAMC;AAKD,kDAiBC;AAsCD,oDAsCC;AAKD,8DAUC;AAMD,0CAWC;AAKD,sCAEC;AAzSD;;GAEG;AACU,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,UAAU,EAAY,sBAAsB;IAClD,UAAU,EAAE,UAAU,EAAM,0BAA0B;IACtD,OAAO,EAAE,UAAU,EAAS,uBAAuB;IACnD,MAAM,EAAE,UAAU,EAAU,oBAAoB;IAChD,MAAM,EAAE,UAAU,EAAU,4BAA4B;IACxD,OAAO,E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atted tables
|
|
4
|
+
*/
|
|
5
|
+
export interface TableData {
|
|
6
|
+
headers: string[];
|
|
7
|
+
rows: string[][];
|
|
8
|
+
align?: ('left' | 'center' | 'right')[];
|
|
9
|
+
}
|
|
10
|
+
export interface TableFormatOptions {
|
|
11
|
+
maxWidth?: number;
|
|
12
|
+
align?: ('left' | 'center' | 'right')[];
|
|
13
|
+
borderStyle?: 'simple' | 'rounded' | 'double' | 'minimal';
|
|
14
|
+
stripMarkdown?: boolean;
|
|
15
|
+
compact?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parse markdown table to structured data
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseMarkdownTable(markdown: string): TableData | null;
|
|
21
|
+
/**
|
|
22
|
+
* Format table to ASCII art
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatTableToASCII(table: TableData, options?: TableFormatOptions): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format table with multi-line cells
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatTableMultiline(table: TableData, options?: TableFormatOptions): string;
|
|
29
|
+
/**
|
|
30
|
+
* CSV to table data
|
|
31
|
+
*/
|
|
32
|
+
export declare function csvToTable(csv: string): TableData;
|
|
33
|
+
/**
|
|
34
|
+
* Detect if text is a table
|
|
35
|
+
*/
|
|
36
|
+
export declare function isTableMarkdown(text: string): boolean;
|
|
37
|
+
//# sourceMappingURL=table-formatter-inline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-formatter-inline.d.ts","sourceRoot":"","sources":["../../src/utils/table-formatter-inline.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,CAAC,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,EAAE,CAAC;CACzC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,CAAC,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,EAAE,CAAC;IACxC,WAAW,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC1D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CA4CrE;AA2ID;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CA+DR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CA8ER;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAYjD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAcrD"}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Table Formatter for ASCII output
|
|
4
|
+
* Converts markdown tables to beautiful ASCII formatted tables
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.parseMarkdownTable = parseMarkdownTable;
|
|
8
|
+
exports.formatTableToASCII = formatTableToASCII;
|
|
9
|
+
exports.formatTableMultiline = formatTableMultiline;
|
|
10
|
+
exports.csvToTable = csvToTable;
|
|
11
|
+
exports.isTableMarkdown = isTableMarkdown;
|
|
12
|
+
/**
|
|
13
|
+
* Parse markdown table to structured data
|
|
14
|
+
*/
|
|
15
|
+
function parseMarkdownTable(markdown) {
|
|
16
|
+
const lines = markdown.split('\n').filter(l => l.trim());
|
|
17
|
+
if (lines.length < 2)
|
|
18
|
+
return null;
|
|
19
|
+
// First line is headers
|
|
20
|
+
const headerLine = lines[0];
|
|
21
|
+
const separatorLine = lines[1];
|
|
22
|
+
// Parse headers
|
|
23
|
+
const headers = headerLine
|
|
24
|
+
.split('|')
|
|
25
|
+
.map(h => h.trim())
|
|
26
|
+
.filter(h => h && h !== '');
|
|
27
|
+
if (headers.length === 0)
|
|
28
|
+
return null;
|
|
29
|
+
// Detect alignment from separator line
|
|
30
|
+
const alignmentCells = separatorLine
|
|
31
|
+
.split('|')
|
|
32
|
+
.map(a => a.trim())
|
|
33
|
+
.filter(a => a && a !== '');
|
|
34
|
+
const align = alignmentCells.map(cell => {
|
|
35
|
+
if (/^:-+:$/.test(cell))
|
|
36
|
+
return 'center';
|
|
37
|
+
if (/-+:$/.test(cell))
|
|
38
|
+
return 'right';
|
|
39
|
+
if (/^:-+/.test(cell))
|
|
40
|
+
return 'left';
|
|
41
|
+
return 'left';
|
|
42
|
+
});
|
|
43
|
+
// Parse data rows
|
|
44
|
+
const rows = [];
|
|
45
|
+
for (let i = 2; i < lines.length; i++) {
|
|
46
|
+
const cells = lines[i]
|
|
47
|
+
.split('|')
|
|
48
|
+
.map(c => c.trim())
|
|
49
|
+
.filter((_c, idx) => idx > 0 && idx <= headers.length);
|
|
50
|
+
if (cells.length === headers.length) {
|
|
51
|
+
rows.push(cells);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { headers, rows, align };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Calculate column widths
|
|
58
|
+
*/
|
|
59
|
+
function calculateColumnWidths(table, maxWidth = 80, compact = false) {
|
|
60
|
+
const minWidth = compact ? 3 : 5;
|
|
61
|
+
const availableWidth = maxWidth - table.headers.length * 3 - 1;
|
|
62
|
+
// Start with header widths
|
|
63
|
+
let widths = table.headers.map(h => Math.max(h.length, minWidth));
|
|
64
|
+
// Check data widths
|
|
65
|
+
for (const row of table.rows) {
|
|
66
|
+
for (let i = 0; i < row.length; i++) {
|
|
67
|
+
widths[i] = Math.max(widths[i], Math.min(row[i].length, 30));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Scale if total exceeds max width
|
|
71
|
+
const totalWidth = widths.reduce((a, b) => a + b, 0);
|
|
72
|
+
if (totalWidth > availableWidth) {
|
|
73
|
+
const scale = availableWidth / totalWidth;
|
|
74
|
+
widths = widths.map(w => Math.max(minWidth, Math.floor(w * scale)));
|
|
75
|
+
}
|
|
76
|
+
return widths;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Wrap text to fit column width
|
|
80
|
+
*/
|
|
81
|
+
function wrapText(text, width) {
|
|
82
|
+
if (text.length <= width) {
|
|
83
|
+
return [text];
|
|
84
|
+
}
|
|
85
|
+
const words = text.split(/\s+/);
|
|
86
|
+
const lines = [];
|
|
87
|
+
let currentLine = '';
|
|
88
|
+
for (const word of words) {
|
|
89
|
+
if ((currentLine + ' ' + word).length <= width) {
|
|
90
|
+
currentLine += (currentLine ? ' ' : '') + word;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (currentLine)
|
|
94
|
+
lines.push(currentLine);
|
|
95
|
+
currentLine = word;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (currentLine)
|
|
99
|
+
lines.push(currentLine);
|
|
100
|
+
return lines.length === 0 ? [''] : lines;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Align text in cell
|
|
104
|
+
*/
|
|
105
|
+
function alignText(text, width, align) {
|
|
106
|
+
text = text.padEnd(width);
|
|
107
|
+
switch (align) {
|
|
108
|
+
case 'right':
|
|
109
|
+
return text.slice(-width); // Right align
|
|
110
|
+
case 'center':
|
|
111
|
+
const leftPad = Math.floor((width - text.trimEnd().length) / 2);
|
|
112
|
+
return text.slice(0, leftPad).padEnd(width);
|
|
113
|
+
case 'left':
|
|
114
|
+
default:
|
|
115
|
+
return text.slice(0, width);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get border characters for style
|
|
120
|
+
*/
|
|
121
|
+
function getBorderChars(style) {
|
|
122
|
+
const borders = {
|
|
123
|
+
simple: {
|
|
124
|
+
topLeft: '┌',
|
|
125
|
+
topRight: '┐',
|
|
126
|
+
bottomLeft: '└',
|
|
127
|
+
bottomRight: '┘',
|
|
128
|
+
topMid: '┬',
|
|
129
|
+
bottomMid: '┴',
|
|
130
|
+
leftMid: '├',
|
|
131
|
+
rightMid: '┤',
|
|
132
|
+
cross: '┼',
|
|
133
|
+
horizontal: '─',
|
|
134
|
+
vertical: '│',
|
|
135
|
+
},
|
|
136
|
+
rounded: {
|
|
137
|
+
topLeft: '╭',
|
|
138
|
+
topRight: '╮',
|
|
139
|
+
bottomLeft: '╰',
|
|
140
|
+
bottomRight: '╯',
|
|
141
|
+
topMid: '┬',
|
|
142
|
+
bottomMid: '┴',
|
|
143
|
+
leftMid: '├',
|
|
144
|
+
rightMid: '┤',
|
|
145
|
+
cross: '┼',
|
|
146
|
+
horizontal: '─',
|
|
147
|
+
vertical: '│',
|
|
148
|
+
},
|
|
149
|
+
double: {
|
|
150
|
+
topLeft: '╔',
|
|
151
|
+
topRight: '╗',
|
|
152
|
+
bottomLeft: '╚',
|
|
153
|
+
bottomRight: '╝',
|
|
154
|
+
topMid: '╦',
|
|
155
|
+
bottomMid: '╩',
|
|
156
|
+
leftMid: '╠',
|
|
157
|
+
rightMid: '╣',
|
|
158
|
+
cross: '╬',
|
|
159
|
+
horizontal: '═',
|
|
160
|
+
vertical: '║',
|
|
161
|
+
},
|
|
162
|
+
minimal: {
|
|
163
|
+
topLeft: ' ',
|
|
164
|
+
topRight: ' ',
|
|
165
|
+
bottomLeft: ' ',
|
|
166
|
+
bottomRight: ' ',
|
|
167
|
+
topMid: ' ',
|
|
168
|
+
bottomMid: ' ',
|
|
169
|
+
leftMid: ' ',
|
|
170
|
+
rightMid: ' ',
|
|
171
|
+
cross: ' ',
|
|
172
|
+
horizontal: ' ',
|
|
173
|
+
vertical: ' ',
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
return borders[style];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Format table to ASCII art
|
|
180
|
+
*/
|
|
181
|
+
function formatTableToASCII(table, options) {
|
|
182
|
+
const maxWidth = options?.maxWidth || 80;
|
|
183
|
+
const borderStyle = options?.borderStyle || 'simple';
|
|
184
|
+
const compact = options?.compact ?? false;
|
|
185
|
+
const align = options?.align || table.align || table.headers.map(() => 'left');
|
|
186
|
+
const borders = getBorderChars(borderStyle);
|
|
187
|
+
const colWidths = calculateColumnWidths(table, maxWidth, compact);
|
|
188
|
+
const lines = [];
|
|
189
|
+
// Top border
|
|
190
|
+
let topLine = borders.topLeft;
|
|
191
|
+
for (let i = 0; i < colWidths.length; i++) {
|
|
192
|
+
topLine += borders.horizontal.repeat(colWidths[i] + 2);
|
|
193
|
+
if (i < colWidths.length - 1) {
|
|
194
|
+
topLine += borders.topMid;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
topLine += borders.topRight;
|
|
198
|
+
lines.push(topLine);
|
|
199
|
+
// Header row
|
|
200
|
+
let headerLine = borders.vertical;
|
|
201
|
+
for (let i = 0; i < table.headers.length; i++) {
|
|
202
|
+
const aligned = alignText(table.headers[i], colWidths[i], align[i] || 'left');
|
|
203
|
+
headerLine += ' ' + aligned + ' ' + borders.vertical;
|
|
204
|
+
}
|
|
205
|
+
lines.push(headerLine);
|
|
206
|
+
// Separator after header
|
|
207
|
+
let separatorLine = borders.leftMid;
|
|
208
|
+
for (let i = 0; i < colWidths.length; i++) {
|
|
209
|
+
separatorLine += borders.horizontal.repeat(colWidths[i] + 2);
|
|
210
|
+
if (i < colWidths.length - 1) {
|
|
211
|
+
separatorLine += borders.cross;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
separatorLine += borders.rightMid;
|
|
215
|
+
lines.push(separatorLine);
|
|
216
|
+
// Data rows
|
|
217
|
+
for (const row of table.rows) {
|
|
218
|
+
let dataLine = borders.vertical;
|
|
219
|
+
for (let i = 0; i < row.length; i++) {
|
|
220
|
+
const aligned = alignText(row[i], colWidths[i], align[i] || 'left');
|
|
221
|
+
dataLine += ' ' + aligned + ' ' + borders.vertical;
|
|
222
|
+
}
|
|
223
|
+
lines.push(dataLine);
|
|
224
|
+
}
|
|
225
|
+
// Bottom border
|
|
226
|
+
let bottomLine = borders.bottomLeft;
|
|
227
|
+
for (let i = 0; i < colWidths.length; i++) {
|
|
228
|
+
bottomLine += borders.horizontal.repeat(colWidths[i] + 2);
|
|
229
|
+
if (i < colWidths.length - 1) {
|
|
230
|
+
bottomLine += borders.bottomMid;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
bottomLine += borders.bottomRight;
|
|
234
|
+
lines.push(bottomLine);
|
|
235
|
+
return lines.join('\n');
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Format table with multi-line cells
|
|
239
|
+
*/
|
|
240
|
+
function formatTableMultiline(table, options) {
|
|
241
|
+
const maxWidth = options?.maxWidth || 80;
|
|
242
|
+
const borderStyle = options?.borderStyle || 'simple';
|
|
243
|
+
const align = options?.align || table.align || table.headers.map(() => 'left');
|
|
244
|
+
const borders = getBorderChars(borderStyle);
|
|
245
|
+
const colWidths = calculateColumnWidths(table, maxWidth, false);
|
|
246
|
+
const lines = [];
|
|
247
|
+
// Top border
|
|
248
|
+
let topLine = borders.topLeft;
|
|
249
|
+
for (let i = 0; i < colWidths.length; i++) {
|
|
250
|
+
topLine += borders.horizontal.repeat(colWidths[i] + 2);
|
|
251
|
+
if (i < colWidths.length - 1) {
|
|
252
|
+
topLine += borders.topMid;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
topLine += borders.topRight;
|
|
256
|
+
lines.push(topLine);
|
|
257
|
+
// Header row
|
|
258
|
+
const headerLines = table.headers.map((h, i) => {
|
|
259
|
+
const wrapped = wrapText(h, colWidths[i]);
|
|
260
|
+
return wrapped.map(line => alignText(line, colWidths[i], align[i] || 'left'));
|
|
261
|
+
});
|
|
262
|
+
const maxHeaderLines = Math.max(...headerLines.map(h => h.length));
|
|
263
|
+
for (let lineIdx = 0; lineIdx < maxHeaderLines; lineIdx++) {
|
|
264
|
+
let headerLine = borders.vertical;
|
|
265
|
+
for (let colIdx = 0; colIdx < table.headers.length; colIdx++) {
|
|
266
|
+
const line = headerLines[colIdx][lineIdx] || '';
|
|
267
|
+
headerLine += ' ' + line.padEnd(colWidths[colIdx]) + ' ' + borders.vertical;
|
|
268
|
+
}
|
|
269
|
+
lines.push(headerLine);
|
|
270
|
+
}
|
|
271
|
+
// Separator
|
|
272
|
+
let separatorLine = borders.leftMid;
|
|
273
|
+
for (let i = 0; i < colWidths.length; i++) {
|
|
274
|
+
separatorLine += borders.horizontal.repeat(colWidths[i] + 2);
|
|
275
|
+
if (i < colWidths.length - 1) {
|
|
276
|
+
separatorLine += borders.cross;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
separatorLine += borders.rightMid;
|
|
280
|
+
lines.push(separatorLine);
|
|
281
|
+
// Data rows
|
|
282
|
+
for (const row of table.rows) {
|
|
283
|
+
const cellLines = row.map((cell, i) => {
|
|
284
|
+
const wrapped = wrapText(cell, colWidths[i]);
|
|
285
|
+
return wrapped.map(line => alignText(line, colWidths[i], align[i] || 'left'));
|
|
286
|
+
});
|
|
287
|
+
const maxCellLines = Math.max(...cellLines.map(c => c.length));
|
|
288
|
+
for (let lineIdx = 0; lineIdx < maxCellLines; lineIdx++) {
|
|
289
|
+
let dataLine = borders.vertical;
|
|
290
|
+
for (let colIdx = 0; colIdx < row.length; colIdx++) {
|
|
291
|
+
const line = cellLines[colIdx][lineIdx] || '';
|
|
292
|
+
dataLine += ' ' + line.padEnd(colWidths[colIdx]) + ' ' + borders.vertical;
|
|
293
|
+
}
|
|
294
|
+
lines.push(dataLine);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// Bottom border
|
|
298
|
+
let bottomLine = borders.bottomLeft;
|
|
299
|
+
for (let i = 0; i < colWidths.length; i++) {
|
|
300
|
+
bottomLine += borders.horizontal.repeat(colWidths[i] + 2);
|
|
301
|
+
if (i < colWidths.length - 1) {
|
|
302
|
+
bottomLine += borders.bottomMid;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
bottomLine += borders.bottomRight;
|
|
306
|
+
lines.push(bottomLine);
|
|
307
|
+
return lines.join('\n');
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* CSV to table data
|
|
311
|
+
*/
|
|
312
|
+
function csvToTable(csv) {
|
|
313
|
+
const lines = csv.trim().split('\n');
|
|
314
|
+
if (lines.length === 0) {
|
|
315
|
+
return { headers: [], rows: [] };
|
|
316
|
+
}
|
|
317
|
+
const headers = lines[0].split(',').map(h => h.trim());
|
|
318
|
+
const rows = lines.slice(1).map(line => line.split(',').map(cell => cell.trim()));
|
|
319
|
+
return { headers, rows };
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Detect if text is a table
|
|
323
|
+
*/
|
|
324
|
+
function isTableMarkdown(text) {
|
|
325
|
+
const lines = text.split('\n');
|
|
326
|
+
if (lines.length < 2)
|
|
327
|
+
return false;
|
|
328
|
+
// Check for pipe separators
|
|
329
|
+
const firstLine = lines[0];
|
|
330
|
+
const secondLine = lines[1];
|
|
331
|
+
if (!firstLine.includes('|') || !secondLine.includes('|')) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
// Check if second line looks like a separator
|
|
335
|
+
return /^[\s|:-]+$/.test(secondLine);
|
|
336
|
+
}
|
|
337
|
+
//# sourceMappingURL=table-formatter-inline.js.map
|