mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-07-18 21:50:55 +00:00
fix: highlight extensionless workspace code files
(cherry picked from commit 3e61de7a73)
This commit is contained in:
@@ -594,7 +594,15 @@ const _PRISM_LANG_MAP={
|
||||
diff:'diff',patch:'diff',
|
||||
txt:'',log:'',csv:'',tsv:'',
|
||||
};
|
||||
const _PRISM_BASENAME_LANG_MAP={
|
||||
'dockerfile':'docker','makefile':'makefile','gnumakefile':'makefile',
|
||||
'cmakelists.txt':'cmake',
|
||||
'.gitignore':'ignore','.dockerignore':'ignore',
|
||||
};
|
||||
function _prismLanguageForPath(path){
|
||||
const base=String(path||'').split(/[\\/]/).pop().toLowerCase();
|
||||
if(base.startsWith('dockerfile.')) return 'docker';
|
||||
if(_PRISM_BASENAME_LANG_MAP[base]!==undefined) return _PRISM_BASENAME_LANG_MAP[base];
|
||||
const ext=fileExt(path).replace(/^\./,'');
|
||||
return _PRISM_LANG_MAP[ext]!==undefined?_PRISM_LANG_MAP[ext]:'plaintext';
|
||||
}
|
||||
|
||||
@@ -33,6 +33,25 @@ def test_prism_language_map_covers_common_extensions():
|
||||
assert "txt:''" in WORKSPACE_JS
|
||||
|
||||
|
||||
def test_prism_language_path_fallback_covers_extensionless_code_filenames():
|
||||
"""Common code/config filenames without useful extensions should still
|
||||
activate Prism grammar selection in workspace previews (#3365).
|
||||
"""
|
||||
assert "_PRISM_BASENAME_LANG_MAP" in WORKSPACE_JS
|
||||
expected = {
|
||||
"Dockerfile": "docker",
|
||||
"Makefile": "makefile",
|
||||
"makefile": "makefile",
|
||||
"GNUmakefile": "makefile",
|
||||
"CMakeLists.txt": "cmake",
|
||||
".gitignore": "ignore",
|
||||
".dockerignore": "ignore",
|
||||
}
|
||||
for filename, language in expected.items():
|
||||
assert f"{filename.lower()!r}:{language!r}" in WORKSPACE_JS
|
||||
assert "base.startsWith('dockerfile.')" in WORKSPACE_JS
|
||||
|
||||
|
||||
def test_plain_text_files_do_not_inherit_prior_file_highlighting():
|
||||
"""Cross-file leak fix: a plain-text preview after a code preview must not
|
||||
inherit the previous file's language. Two guards make this hold:
|
||||
|
||||
Reference in New Issue
Block a user