snow-ai 0.3.24 → 0.3.25
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/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import './utils/patch-highlight.js';
|
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// CRITICAL: Patch cli-highlight BEFORE any other imports
|
|
3
|
+
// This must be the first import to ensure the patch is applied before cli-markdown loads
|
|
4
|
+
import './utils/patch-highlight.js';
|
|
2
5
|
import React from 'react';
|
|
3
6
|
import { render, Text, Box } from 'ink';
|
|
4
7
|
import Spinner from 'ink-spinner';
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Text } from 'ink';
|
|
3
|
-
import { highlight } from 'cli-highlight';
|
|
4
3
|
// @ts-expect-error - cli-markdown doesn't have TypeScript definitions
|
|
5
4
|
import cliMarkdown from 'cli-markdown';
|
|
6
5
|
export default function MarkdownRenderer({ content }) {
|
|
7
6
|
// Use cli-markdown for elegant markdown rendering with syntax highlighting
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
code: (code, language) => {
|
|
11
|
-
if (!language)
|
|
12
|
-
return code;
|
|
13
|
-
try {
|
|
14
|
-
return highlight(code, { language, ignoreIllegals: true });
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return code;
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
});
|
|
7
|
+
// The patched highlight function will gracefully handle unknown languages
|
|
8
|
+
const rendered = cliMarkdown(content);
|
|
21
9
|
// Remove excessive trailing newlines and whitespace from cli-markdown output
|
|
22
10
|
// Keep single blank lines for paragraph spacing (better readability)
|
|
23
11
|
const trimmedRendered = rendered
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patch cli-highlight to gracefully handle unknown languages
|
|
3
|
+
* This must be loaded BEFORE any modules that use cli-highlight
|
|
4
|
+
*/
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const cliHighlightModule = require('cli-highlight');
|
|
8
|
+
const originalHighlight = cliHighlightModule.highlight;
|
|
9
|
+
// Override the highlight function to handle unknown languages gracefully
|
|
10
|
+
cliHighlightModule.highlight = function (code, options) {
|
|
11
|
+
try {
|
|
12
|
+
return originalHighlight(code, options);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
// If the error is about an unknown language, return the original code without highlighting
|
|
16
|
+
if (error?.message?.includes('Unknown language') ||
|
|
17
|
+
error?.message?.includes('Could not find the language')) {
|
|
18
|
+
return code;
|
|
19
|
+
}
|
|
20
|
+
// Re-throw other unexpected errors
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
};
|