Code Highlight: Fix C# (#1888)

This commit is contained in:
Alexander Zinchuk 2022-05-30 15:40:30 +04:00
parent cad0c76d39
commit 706839953a

View File

@ -3,43 +3,42 @@ import { lowlight } from 'lowlight/lib/core';
import type { TeactNode } from '../lib/teact/teact'; import type { TeactNode } from '../lib/teact/teact';
import Teact from '../lib/teact/teact'; import Teact from '../lib/teact/teact';
// First element in alias array MUST BE a language package name const SUPPORTED_LANGUAGES: Record<string, string[]> = {
const SUPPORTED_LANGUAGES = { '1c': ['1с'], // Allow cyrillic
'1c': ['1c', '1с'], // Allow cyrillic bash: ['sh'],
bash: ['bash', 'sh'], c: ['h'],
c: ['c', 'h'], cpp: ['cc', 'c++', 'h++', 'hpp', 'hh', 'hxx', 'cxx'],
cpp: ['cpp', 'cc', 'c++', 'h++', 'hpp', 'hh', 'hxx', 'cxx'], csharp: ['cs', 'c#'],
csharp: ['chasp', 'cs', 'c#'], css: [],
css: ['css'], erlang: ['erl'],
erlang: ['erlang', 'erl'], elixir: ['ex', 'exs'],
elixir: ['elixir', 'ex', 'exs'], go: ['golang'],
go: ['go', 'golang'], handlebars: ['hbs', 'html.hbs', 'html.handlebars', 'htmlbars'],
handlebars: ['handlebars', 'hbs', 'html.hbs', 'html.handlebars', 'htmlbars'], haskell: ['hs'],
haskell: ['haskell', 'hs'], ini: ['toml'],
ini: ['ini', 'toml'], java: ['jsp'],
java: ['java', 'jsp'], javascript: ['js', 'jsx', 'mjs', 'cjs'],
javascript: ['javascript', 'js', 'jsx', 'mjs', 'cjs'], json: [],
json: ['json'], kotlin: ['kt', 'kts'],
kotlin: ['kotlin', 'kt', 'kts'], lisp: [],
lisp: ['lisp'], lua: [],
lua: ['lua'], makefile: ['mk', 'mak', 'make'],
makefile: ['makefile', 'mk', 'mak', 'make'], markdown: ['md', 'mkdown', 'mkd'],
markdown: ['markdown', 'md', 'mkdown', 'mkd'], matlab: [],
matlab: ['matlab'], objectivec: ['mm', 'objc', 'obj-c', 'obj-c++', 'objective-c++'],
objectivec: ['objectivec', 'mm', 'objc', 'obj-c', 'obj-c++', 'objective-c++'], perl: ['pl', 'pm'],
perl: ['perl', 'pl', 'pm'], php: [],
php: ['php'], python: ['py', 'gyp', 'ipython'],
python: ['python', 'py', 'gyp', 'ipython'], r: [],
r: ['r'], ruby: ['rb', 'gemspec', 'podspec', 'thor', 'irb'],
ruby: ['ruby', 'rb', 'gemspec', 'podspec', 'thor', 'irb'], rust: ['rs'],
rust: ['rust', 'rs'], scss: [],
scss: ['scss'], sql: [],
sql: ['sql'], swift: [],
swift: ['swift'], twig: ['craftcms'],
twig: ['twig', 'craftcms'], typescript: ['ts', 'tsx'],
typescript: ['typescript', 'ts', 'tsx'], xml: ['html', 'xhtml', 'rss', 'atom', 'xjb', 'xsd', 'xsl', 'plist', 'wsf', 'svg'],
xml: ['xml', 'html', 'xhtml', 'rss', 'atom', 'xjb', 'xsd', 'xsl', 'plist', 'wsf', 'svg'], yaml: [],
yaml: ['yaml', 'yml'],
}; };
const languagePromises = new Map<string, Promise<void>>(); const languagePromises = new Map<string, Promise<void>>();
@ -53,7 +52,8 @@ export default async function highlightCode(text: string, language: string) {
} }
function getLanguageName(alias: string) { function getLanguageName(alias: string) {
return Object.values(SUPPORTED_LANGUAGES).find((codes) => codes.includes(alias))?.[0]; return Object.entries(SUPPORTED_LANGUAGES)
.find(([langName, aliases]) => langName === alias || aliases.includes(alias))?.[0];
} }
async function ensureLanguage(language: string) { async function ensureLanguage(language: string) {