diff --git a/src/shared/utils/prismLanguageMapper.spec.ts b/src/shared/utils/prismLanguageMapper.spec.ts index 1fbc6898e6..6d7c68c716 100644 --- a/src/shared/utils/prismLanguageMapper.spec.ts +++ b/src/shared/utils/prismLanguageMapper.spec.ts @@ -22,14 +22,26 @@ describe('prismLanguageMapper', () => { { extension: 'rss', expected: 'markup' }, { extension: 'sh', expected: 'bash' }, { extension: 'c', expected: 'c' }, - { extension: 'h', expected: 'clike' }, + { extension: 'h', expected: 'c' }, { extension: 'cc', expected: 'cpp' }, { extension: 'cpp', expected: 'cpp' }, + { extension: 'hpp', expected: 'cpp' }, + { extension: 'cs', expected: 'csharp' }, + { extension: 'cshtml', expected: 'cshtml' }, { extension: 'css', expected: 'css' }, + { extension: 'dart', expected: 'dart' }, + { extension: 'f', expected: 'fortran' }, + { extension: 'fpp', expected: 'fortran' }, + { extension: 'f90', expected: 'fortran' }, + { extension: 'fs', expected: 'fsharp' }, + { extension: 'java', expected: 'java' }, + { extension: 'jl', expected: 'julia' }, { extension: 'js', expected: 'javascript' }, { extension: 'cjs', expected: 'javascript' }, { extension: 'mjs', expected: 'javascript' }, { extension: 'jsx', expected: 'jsx' }, + { extension: 'kt', expected: 'kotlin' }, + { extension: 'kts', expected: 'kotlin' }, { extension: 'go', expected: 'go' }, { extension: 'gql', expected: 'graphql' }, { extension: 'graphql', expected: 'graphql' }, @@ -37,15 +49,31 @@ describe('prismLanguageMapper', () => { { extension: 'less', expected: 'less' }, { extension: 'objc', expected: 'objectivec' }, { extension: 'ocaml', expected: 'ocaml' }, + { extension: 'php', expected: 'php' }, { extension: 'py', expected: 'python' }, + { extension: 'r', expected: 'r' }, + { extension: 'ps1', expected: 'powershell' }, + { extension: 'psm1', expected: 'powershell' }, + { extension: 'razor', expected: 'cshtml' }, + { extension: 'rb', expected: 'ruby' }, { extension: 'reason', expected: 'reason' }, + { extension: 'rs', expected: 'rust' }, { extension: 'sass', expected: 'sass' }, + { extension: 'scala', expected: 'scala' }, { extension: 'scss', expected: 'scss' }, + { extension: 'sol', expected: 'solidity' }, { extension: 'sql', expected: 'sql' }, + { extension: 'swift', expected: 'swift' }, + { extension: 'svelte', expected: 'markup' }, { extension: 'ts', expected: 'typescript' }, { extension: 'tsx', expected: 'tsx' }, + { extension: 'vb', expected: 'visual-basic' }, + { extension: 'vba', expected: 'visual-basic' }, + { extension: 'vbs', expected: 'visual-basic' }, + { extension: 'vue', expected: 'markup' }, { extension: 'wasm', expected: 'wasm' }, { extension: 'yaml', expected: 'yaml' }, + { extension: 'zig', expected: 'zig' }, ] it.each(testCases)( diff --git a/src/shared/utils/prismLanguageMapper.ts b/src/shared/utils/prismLanguageMapper.ts index 2e0eeb50de..c6d9c9679d 100644 --- a/src/shared/utils/prismLanguageMapper.ts +++ b/src/shared/utils/prismLanguageMapper.ts @@ -17,6 +17,9 @@ import Prism from 'prism-react-renderer/prism' */ require('prismjs/components/prism-csharp') require('prismjs/components/prism-dart') +require('prismjs/components/prism-cshtml') +require('prismjs/components/prism-fortran') +require('prismjs/components/prism-fsharp') require('prismjs/components/prism-java') require('prismjs/components/prism-julia') require('prismjs/components/prism-kotlin') @@ -25,6 +28,12 @@ require('prismjs/components/prism-r') require('prismjs/components/prism-ruby') require('prismjs/components/prism-rust') require('prismjs/components/prism-scala') +require('prismjs/components/prism-powershell') +require('prismjs/components/prism-ruby') +require('prismjs/components/prism-rust') +require('prismjs/components/prism-solidity') +require('prismjs/components/prism-swift') +require('prismjs/components/prism-visual-basic') require('prismjs/components/prism-zig') const prismSupportedLanguages = new Map([ @@ -37,12 +46,18 @@ const prismSupportedLanguages = new Map([ ['rss', 'markup'], ['sh', 'bash'], ['c', 'c'], - ['h', 'clike'], + ['h', 'c'], ['cc', 'cpp'], ['cpp', 'cpp'], + ['hpp', 'cpp'], ['cs', 'csharp'], + ['cshtml', 'cshtml'], ['css', 'css'], ['dart', 'dart'], + ['f', 'fortran'], + ['fpp', 'fortran'], + ['f90', 'fortran'], + ['fs', 'fsharp'], ['java', 'java'], ['jl', 'julia'], ['js', 'javascript'], @@ -60,17 +75,30 @@ const prismSupportedLanguages = new Map([ ['ocaml', 'ocaml'], ['php', 'php'], ['py', 'python'], - ['R', 'r'], ['r', 'r'], + ['ps1', 'powershell'], + ['psm1', 'powershell'], + ['razor', 'cshtml'], ['rb', 'ruby'], ['reason', 'reason'], ['rs', 'rust'], ['sass', 'sass'], ['scala', 'scala'], ['scss', 'scss'], + ['sol', 'solidity'], ['sql', 'sql'], + ['swift', 'swift'], + // svelte does not have full support yet - may look into this third party + // https://github.com/PrismJS/prism/issues/2090 + ['svelte', 'markup'], ['ts', 'typescript'], ['tsx', 'tsx'], + ['vb', 'visual-basic'], + ['vba', 'visual-basic'], + ['vbs', 'visual-basic'], + // vue does not have full support yet + // https://github.com/PrismJS/prism/issues/1665 + ['vue', 'markup'], ['wasm', 'wasm'], ['yaml', 'yaml'], ['zig', 'zig'], @@ -81,7 +109,10 @@ const DEFAULT_LANGUAGE_TYPE: Language = 'markup' export function prismLanguageMapper(fileName: string): Language { const fileExtension = fileName.split('.').pop() ?? '' - const supportedLanguage = prismSupportedLanguages.get(fileExtension) + // casting this to lower, as in Sentry I've seen some file extensions in uppercase + const supportedLanguage = prismSupportedLanguages.get( + fileExtension.toLowerCase() + ) // we need to cast this, because we're adding in extra languages that aren't in the prism-react-renderer package if (supportedLanguage) return supportedLanguage as Language