MCPcopy Create free account
hub / github.com/Surfer-Org/Protocol / CodeBlock

Function CodeBlock

desktop/src/renderer/components/CodeBlock.jsx:7–64  ·  view source on GitHub ↗
({ run, code, filename })

Source from the content-addressed store, hash-verified

5import { getLanguageFromFilename } from '../helpers';
6
7const CodeBlock = ({ run, code, filename }) => {
8 const [showCheck, setShowCheck] = useState(false);
9
10 const detectedLanguage = filename
11 ? getLanguageFromFilename(filename)
12 : 'plaintext';
13
14 const handleCopyCode = () => {
15 navigator.clipboard.writeText(code);
16 setShowCheck(true);
17 setTimeout(() => setShowCheck(false), 500);
18 };
19
20 let formattedCode;
21
22 if (detectedLanguage === 'python') {
23 formattedCode = code.replace('platform-001', run.platformId);
24 }
25 else if (detectedLanguage === 'markdown') {
26 formattedCode = code.replace('[insert-folder-path-of-your-choice-here]', run.exportPath);
27 }
28 else {
29 formattedCode = code;
30 }
31
32 return (
33 <div className="scroll-mt-16">
34 <div className="relative">
35 <div className="relative rounded-lg overflow-hidden">
36 <Button
37 variant="ghost"
38 size="sm"
39 className="absolute right-2 top-2 hover:bg-zinc-800 z-10"
40 onClick={handleCopyCode}
41 >
42 {showCheck ? (
43 <Check className="h-4 w-4 text-green-500" />
44 ) : (
45 <Copy className="h-4 w-4 text-muted-foreground" />
46 )}
47 </Button>
48 <MonacoEditor
49 height="70vh"
50 language={detectedLanguage}
51 theme="vs-dark"
52 value={formattedCode}
53 options={{
54 readOnly: true,
55 minimap: { enabled: false },
56 scrollBeyondLastLine: false,
57 wordWrap: 'on',
58 }}
59 />
60 </div>
61 </div>
62 </div>
63 );
64};

Callers

nothing calls this directly

Calls 1

getLanguageFromFilenameFunction · 0.90

Tested by

no test coverage detected