From 7d6fa7f8bffc7e9791b49ba1ba705abc96b84e55 Mon Sep 17 00:00:00 2001
From: Jazz <jazzzz@gmail.com>
Date: Fri, 13 Jan 2017 14:54:22 +0100
Subject: Register the same language aliases as Rouge (#5040)

This allows the use of the same aliases as GitLab.
---
 webapp/utils/syntax_highlighting.jsx | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

(limited to 'webapp/utils/syntax_highlighting.jsx')

diff --git a/webapp/utils/syntax_highlighting.jsx b/webapp/utils/syntax_highlighting.jsx
index 47ba5bd4e..73e1087cb 100644
--- a/webapp/utils/syntax_highlighting.jsx
+++ b/webapp/utils/syntax_highlighting.jsx
@@ -123,9 +123,9 @@ hlJS.registerLanguage('yaml', hljsYaml);
 const HighlightedLanguages = Constants.HighlightedLanguages;
 
 export function highlight(lang, code) {
-    const language = lang.toLowerCase();
+    const language = getLanguageFromNameOrAlias(lang);
 
-    if (HighlightedLanguages[language]) {
+    if (language) {
         try {
             return hlJS.highlight(language, code).value;
         } catch (e) {
@@ -147,13 +147,25 @@ export function getLanguageFromFileExtension(extension) {
 }
 
 export function canHighlight(language) {
-    return Boolean(HighlightedLanguages[language.toLowerCase()]);
+    return Boolean(getLanguageFromNameOrAlias(language));
 }
 
 export function getLanguageName(language) {
     if (canHighlight(language)) {
-        return HighlightedLanguages[language.toLowerCase()].name;
+        return HighlightedLanguages[getLanguageFromNameOrAlias(language)].name;
     }
 
     return '';
-}
\ No newline at end of file
+}
+
+function getLanguageFromNameOrAlias(name) {
+    const langName = name.toLowerCase();
+    if (HighlightedLanguages[langName]) {
+        return langName;
+    }
+
+    return Object.keys(HighlightedLanguages).find((key) => {
+        const aliases = HighlightedLanguages[key].aliases;
+        return aliases && aliases.find((a) => a === langName);
+    });
+}
-- 
cgit v1.2.3-1-g7c22

