Skip to content

Commit 2ec82a7

Browse files
authored
ref(autofix): Reuse existing prism language map (#103476)
Prism has a map between file extension to language and we have a utility function where we've added a few extras. The full list of defaults can be seen here https://prismjs.com/#supported-languages
1 parent feef5a8 commit 2ec82a7

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

static/app/components/events/autofix/autofixDiff.tsx

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {DIFF_COLORS} from 'sentry/components/splitDiff';
1818
import {IconChevron, IconClose, IconDelete, IconEdit} from 'sentry/icons';
1919
import {t} from 'sentry/locale';
2020
import {space} from 'sentry/styles/space';
21+
import {getPrismLanguage} from 'sentry/utils/prism';
2122
import {useMutation, useQueryClient} from 'sentry/utils/queryClient';
2223
import useApi from 'sentry/utils/useApi';
2324
import useOrganization from 'sentry/utils/useOrganization';
@@ -85,37 +86,8 @@ function detectLanguageFromPath(filePath: string): string {
8586
return 'plaintext';
8687
}
8788

88-
// Map common file extensions to Prism language identifiers
89-
const extensionMap: Record<string, string> = {
90-
js: 'javascript',
91-
jsx: 'jsx',
92-
ts: 'typescript',
93-
tsx: 'tsx',
94-
py: 'python',
95-
rb: 'ruby',
96-
go: 'go',
97-
java: 'java',
98-
php: 'php',
99-
c: 'c',
100-
cpp: 'cpp',
101-
cs: 'csharp',
102-
html: 'html',
103-
css: 'css',
104-
scss: 'scss',
105-
json: 'json',
106-
md: 'markdown',
107-
yaml: 'yaml',
108-
yml: 'yaml',
109-
sh: 'bash',
110-
bash: 'bash',
111-
rs: 'rust',
112-
swift: 'swift',
113-
kt: 'kotlin',
114-
sql: 'sql',
115-
xml: 'xml',
116-
};
117-
118-
return extensionMap[extension] || 'plaintext';
89+
const language = getPrismLanguage(extension);
90+
return language || 'plaintext';
11991
}
12092

12193
const SyntaxHighlightedCode = styled('div')`

0 commit comments

Comments
 (0)