diff --git a/moon/apps/web/components/CodeView/BlobView/CodeContent.tsx b/moon/apps/web/components/CodeView/BlobView/CodeContent.tsx index af5290839..e99512a8c 100644 --- a/moon/apps/web/components/CodeView/BlobView/CodeContent.tsx +++ b/moon/apps/web/components/CodeView/BlobView/CodeContent.tsx @@ -8,6 +8,30 @@ import { DotsHorizontal } from '@gitmono/ui'; import 'github-markdown-css/github-markdown-light.css'; import styles from './CodeContent.module.css'; +const suffixToLangMap: Record = { + '.jsx': 'jsx', + '.tsx': 'tsx', + '.kt': 'kotlin', + '.json': 'json', + '.md': 'markdown', + '.py': 'python', + '.rs': 'rust', + '.cpp': 'cpp', + '.h': 'cpp', + '.go': 'go', + '.yml': 'yaml', + '.yaml': 'yaml', +} + +function getLangFromFileName(fileName: string): string { + const lastPart = fileName.toLowerCase().match(/\.[^./\\]+$/); + + if(lastPart) { + return suffixToLangMap[lastPart[0].toLowerCase()] ?? "markdown"; + } + return "markdown"; +} + const CodeContent = ({ fileContent, path }: { fileContent: string, path?: string[] }) => { const [lfs, setLfs] = useState(false) const [selectedLine, setSelectedLine] = useState(null) @@ -163,7 +187,7 @@ const CodeContent = ({ fileContent, path }: { fileContent: string, path?: string {/*todo: Dynamic support for language types*/} - + {({ style, tokens, getLineProps, getTokenProps }) => (
 {
           const $from = state.doc.resolve(range.from)
           const type = state.schema.nodes[Mention.name]