From 5f0a8cf319eaceadb6843086d6ab70a10921295f Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 20 Aug 2024 08:03:34 -0300 Subject: [PATCH 1/5] add support for more languages --- src/shared/utils/prismLanguageMapper.ts | 34 +++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/shared/utils/prismLanguageMapper.ts b/src/shared/utils/prismLanguageMapper.ts index 2e0eeb50de..f4b962ea0e 100644 --- a/src/shared/utils/prismLanguageMapper.ts +++ b/src/shared/utils/prismLanguageMapper.ts @@ -17,6 +17,10 @@ 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-html') require('prismjs/components/prism-java') require('prismjs/components/prism-julia') require('prismjs/components/prism-kotlin') @@ -25,6 +29,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 +47,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'], @@ -62,15 +78,26 @@ const prismSupportedLanguages = new Map([ ['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'], ['ts', 'typescript'], ['tsx', 'tsx'], + ['vb', 'visual-basic'], + ['vba', 'visual-basic'], + ['vbs', 'visual-basic'], + // does not have full support yet + // https://github.com/PrismJS/prism/issues/1665 + ['vue', 'markup'], ['wasm', 'wasm'], ['yaml', 'yaml'], ['zig', 'zig'], @@ -81,7 +108,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 From 72a2027a2b8300c5bdb27455f141bb156363481f Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 20 Aug 2024 08:05:16 -0300 Subject: [PATCH 2/5] add svelte --- src/shared/utils/prismLanguageMapper.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shared/utils/prismLanguageMapper.ts b/src/shared/utils/prismLanguageMapper.ts index f4b962ea0e..0a85e4c273 100644 --- a/src/shared/utils/prismLanguageMapper.ts +++ b/src/shared/utils/prismLanguageMapper.ts @@ -90,12 +90,15 @@ const prismSupportedLanguages = new Map([ ['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'], - // does not have full support yet + // vue does not have full support yet // https://github.com/PrismJS/prism/issues/1665 ['vue', 'markup'], ['wasm', 'wasm'], From 94a8b4854f368d39fa1ca215ba67e7e1dce7497b Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 20 Aug 2024 08:06:28 -0300 Subject: [PATCH 3/5] remove html as it's not a thing --- src/shared/utils/prismLanguageMapper.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/shared/utils/prismLanguageMapper.ts b/src/shared/utils/prismLanguageMapper.ts index 0a85e4c273..9b12c67b34 100644 --- a/src/shared/utils/prismLanguageMapper.ts +++ b/src/shared/utils/prismLanguageMapper.ts @@ -20,7 +20,6 @@ require('prismjs/components/prism-dart') require('prismjs/components/prism-cshtml') require('prismjs/components/prism-fortran') require('prismjs/components/prism-fsharp') -require('prismjs/components/prism-html') require('prismjs/components/prism-java') require('prismjs/components/prism-julia') require('prismjs/components/prism-kotlin') From a4402c3c74a668d6ee898b26e7df3937e3458caf Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 20 Aug 2024 09:22:12 -0300 Subject: [PATCH 4/5] remove redundent R map becuase we send the string to lower case now --- src/shared/utils/prismLanguageMapper.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/shared/utils/prismLanguageMapper.ts b/src/shared/utils/prismLanguageMapper.ts index 9b12c67b34..c6d9c9679d 100644 --- a/src/shared/utils/prismLanguageMapper.ts +++ b/src/shared/utils/prismLanguageMapper.ts @@ -75,7 +75,6 @@ const prismSupportedLanguages = new Map([ ['ocaml', 'ocaml'], ['php', 'php'], ['py', 'python'], - ['R', 'r'], ['r', 'r'], ['ps1', 'powershell'], ['psm1', 'powershell'], From 477faaf1a923876c7bd527f77627cabe263ae534 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 20 Aug 2024 09:22:27 -0300 Subject: [PATCH 5/5] update test cases --- src/shared/utils/prismLanguageMapper.spec.ts | 30 +++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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)(