Skip to content

Commit 6716b94

Browse files
authored
Merge pull request #448 from cloudflare/vshinde/md-support
fix: support markdown in monaco editor
2 parents 434c5b3 + fb6ce57 commit 6716b94

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

src/components/cloudflare-account-selector.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ import { Switch } from '@/components/ui/switch';
1111
import { toast } from 'sonner';
1212
import { apiClient } from '@/lib/api-client';
1313
import { CloudflareLogo } from '@cloudflare/kumo';
14-
import { Loader2, CheckCircle2, AlertCircle, MoreVertical, ExternalLink, LogOut, RefreshCw } from 'lucide-react';
14+
import {
15+
Loader2,
16+
CheckCircle2,
17+
AlertCircle,
18+
MoreVertical,
19+
RefreshCw,
20+
} from 'lucide-react';
1521
import { useLimitsContext } from '@/contexts/limits-context';
1622
import { CloudflareLogoThemed } from './shared/CloudflareLogoThemed';
1723
import { startCloudflareConnect } from '@/lib/cloudflare-connect';
24+
import { ArrowSquareOutIcon, SignOutIcon } from '@phosphor-icons/react';
1825

1926
interface CloudflareAccount {
2027
id: string;
@@ -309,17 +316,17 @@ export function CloudflareAccountSelector() {
309316
<DropdownMenu.Content align="end">
310317
{gatewayDashUrl && (
311318
<DropdownMenu.Item
319+
icon={ArrowSquareOutIcon}
312320
onClick={() => window.open(gatewayDashUrl, '_blank')}
313321
>
314-
<ExternalLink className="size-4" />
315322
View gateway
316323
</DropdownMenu.Item>
317324
)}
318325
<DropdownMenu.Item
326+
icon={SignOutIcon}
319327
onClick={handleDisconnect}
320328
variant="danger"
321329
>
322-
<LogOut className="size-4" />
323330
Disconnect
324331
</DropdownMenu.Item>
325332
</DropdownMenu.Content>

src/components/monaco-editor/monaco-editor.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ self.MonacoEnvironment = {
3030
},
3131
};
3232

33+
/** Resolve Monaco language id, including markdown when only a path is known. */
34+
function resolveLanguage(
35+
language: string | undefined,
36+
path: string | undefined,
37+
): string {
38+
if (language && language !== 'plaintext') {
39+
return language;
40+
}
41+
if (path) {
42+
const ext = path.split('.').pop()?.toLowerCase();
43+
if (ext === 'md' || ext === 'markdown') return 'markdown';
44+
if (ext === 'mdx') return 'mdx';
45+
}
46+
return language || 'typescript';
47+
}
48+
3349
monaco.editor.defineTheme('vesper', vesperTheme);
3450

3551
monaco.editor.defineTheme('vibesdk', {
@@ -247,7 +263,7 @@ export const MonacoEditor = memo<MonacoEditorProps>(function MonacoEditor({
247263
...restOptions
248264
} = options;
249265

250-
const initialLanguage = language || 'typescript';
266+
const initialLanguage = resolveLanguage(language, pathRef.current);
251267
const initialValue = value ?? '';
252268
const model = getOrCreateModel(
253269
initialValue,
@@ -320,7 +336,7 @@ export const MonacoEditor = memo<MonacoEditorProps>(function MonacoEditor({
320336
if (!editor.current) return;
321337

322338
const nextValue = createOptions.value ?? '';
323-
const nextLanguage = createOptions.language || 'typescript';
339+
const nextLanguage = resolveLanguage(createOptions.language, path);
324340
const pathChanged = path !== prevPath.current;
325341
const valueChanged = nextValue !== prevValue.current;
326342

@@ -550,8 +566,8 @@ export const MonacoDiffEditor = memo<MonacoDiffEditorProps>(
550566

551567
useEffect(() => {
552568
if (!diffEditor.current) return;
553-
const lang = language || 'plaintext';
554-
const prevOriginal = originalModel.current;
569+
const lang = resolveLanguage(language, path);
570+
const prevOriginal = originalModel.current;
555571
const prevModified = modifiedModel.current;
556572
const original = monaco.editor.createModel(
557573
originalValue,

src/utils/string.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export const getFileType = (path: string): string => {
1515
return 'html';
1616
case 'json':
1717
return 'json';
18+
case 'md':
19+
case 'markdown':
20+
return 'markdown';
21+
case 'mdx':
22+
return 'mdx';
1823
default:
1924
return 'plaintext';
2025
}

0 commit comments

Comments
 (0)