mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-15 20:46:40 +00:00
Update getProgrammingLanguageName.ts
This commit is contained in:
parent
020da18f6b
commit
887d30200d
1 changed files with 8 additions and 1 deletions
|
|
@ -9,15 +9,22 @@ const SOL = ['solidity', 'sol'];
|
||||||
const LANGS = [JS, SH, PY, SOL];
|
const LANGS = [JS, SH, PY, SOL];
|
||||||
|
|
||||||
export const getProgrammingLanguageName = (code: string) => {
|
export const getProgrammingLanguageName = (code: string) => {
|
||||||
|
// If `code` argument matches any of the above, return the first value for the language
|
||||||
for (const lang of LANGS) {
|
for (const lang of LANGS) {
|
||||||
if (lang.includes(code.toLowerCase())) return lang[0];
|
if (lang.includes(code.toLowerCase())) return lang[0];
|
||||||
}
|
}
|
||||||
|
// Check if `code` argument starts with the CLASSNAME_PREFIX
|
||||||
const hasLanguageNameProperty = code.startsWith(CLASSNAME_PREFIX);
|
const hasLanguageNameProperty = code.startsWith(CLASSNAME_PREFIX);
|
||||||
|
// If no matched so far, return default code formatting type
|
||||||
if (!hasLanguageNameProperty) return DEFAULT;
|
if (!hasLanguageNameProperty) return DEFAULT;
|
||||||
|
// `code` starts with the CLASSNAME_PREFIX, so we need to extract the language name
|
||||||
const newCode = code.replace(CLASSNAME_PREFIX, '').toLowerCase();
|
const newCode = code.replace(CLASSNAME_PREFIX, '').toLowerCase();
|
||||||
|
// If declared to be `terminal`, return the DEFAULT
|
||||||
if (newCode === TERMINAL) return DEFAULT;
|
if (newCode === TERMINAL) return DEFAULT;
|
||||||
|
// If `newCode` argument matches any of the above, return the first value for the language
|
||||||
for (const lang of LANGS) {
|
for (const lang of LANGS) {
|
||||||
if (lang.includes(code.toLowerCase())) return lang[0];
|
if (lang.includes(newCode.toLowerCase())) return lang[0];
|
||||||
}
|
}
|
||||||
|
// If no match from above, simply return the extracted language name
|
||||||
return newCode;
|
return newCode;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue