From 26fe1b7c0adb64b7bfdbe166f358478d56b06dfd Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 21 Jul 2023 22:48:05 +0300 Subject: [PATCH 1/5] Add simple file extension mapping to highlighted lang (cherry picked from commit 6cd29f1ef8107c2efc4374bbd223f79216d34f14) --- script.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index ffc152a..8bda337 100644 --- a/script.js +++ b/script.js @@ -54,7 +54,7 @@ const initLangSelector = () => { // Set lang selector const l = new URLSearchParams(window.location.search).get('l'); - select.set(l ? decodeURIComponent(l) : shorten('Plain Text')); + select.set(l ? decodeURIComponent(fileExtToLang(l)) : shorten('Plain Text')); }; const initCode = () => { @@ -271,6 +271,19 @@ const hash = function (str, seed = 0) { return h.toString(36).substr(0, 4).toUpperCase(); }; +const fileExtToLang = function (str) { + const mapping = new Map(); + mapping.set("shll", ["sh", "bash", "zsh"]); + mapping.set("pwll", ["ps1"]); + mapping.set("perl", ["pl"]); + for (const [lang, fileExt] of mapping.entries()) { + if (fileExt.includes(str)) { + return lang; + } + } + return str; +} + // Only for tests purposes const testAllModes = () => { for (const [index, language] of Object.entries(CodeMirror.modeInfo)) { From e6edffd83ae6668184344b14fc3edec87afddfb1 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 24 Jul 2023 13:15:05 +0300 Subject: [PATCH 2/5] Move file extension mapping rules to external resource file --- index.html | 9 ++++++ resources/file-extension-to-lang.json | 16 ++++++++++ script.js | 42 ++++++++++++++++++++------- 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 resources/file-extension-to-lang.json diff --git a/index.html b/index.html index e26d1a9..35c04ea 100644 --- a/index.html +++ b/index.html @@ -163,6 +163,15 @@

Because of this design:

+