Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion moon/apps/web/components/CodeView/BlobView/CodeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
'.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<number | null>(null)
Expand Down Expand Up @@ -163,7 +187,7 @@ const CodeContent = ({ fileContent, path }: { fileContent: string, path?: string
</div>
</div>
{/*todo: Dynamic support for language types*/}
<Highlight theme={themes.github} code={fileContent} language='rust'>
<Highlight theme={themes.github} code={fileContent} language={getLangFromFileName(filename)}>
{({ style, tokens, getLineProps, getTokenProps }) => (
<pre
style={{
Expand Down
2 changes: 1 addition & 1 deletion moon/apps/web/components/MarkdownEditor/MentionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function MentionList({ editor, defaultMentions, modal }: Props) {
<SuggestionRoot
modal={modal}
editor={editor}
char='#'
char='$'
allow={({ state, range }) => {
const $from = state.doc.resolve(range.from)
const type = state.schema.nodes[Mention.name]
Expand Down