diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse2/Browse2OpDefCode.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse2/Browse2OpDefCode.tsx index 38aa07823d8..87b3c8339d8 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse2/Browse2OpDefCode.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse2/Browse2OpDefCode.tsx @@ -6,6 +6,23 @@ import React, {FC} from 'react'; import {Alert} from '../../../Alert'; import {useWFHooks} from '../Browse3/pages/wfReactInterface/context'; +function detectLanguage(uri: string, code: string) { + // Simple language detection based on file extension or content + if (uri.endsWith('.py')) { + return 'python'; + } + if (uri.endsWith('.js') || uri.endsWith('.ts')) { + return 'javascript'; + } + if (code.includes('def ') || code.includes('import ')) { + return 'python'; + } + if (code.includes('function ') || code.includes('const ')) { + return 'javascript'; + } + return 'plaintext'; +} + export const Browse2OpDefCode: FC<{uri: string; maxRowsInView?: number}> = ({ uri, maxRowsInView, @@ -37,10 +54,12 @@ export const Browse2OpDefCode: FC<{uri: string; maxRowsInView?: number}> = ({ ); } + const detectedLanguage = detectLanguage(uri, text.result ?? ''); + const inner = (