Commit 654b527b3ff9dcbcb11c3aaed6e98de160ad317b

Michael Schmidt 2018-12-01T18:56:35

Display language aliases (#1626) Change the index and download page of the Prism website. The index page will now display the aliases (for `language-xxxx`) of languages and the download page will display all alias title of a language next to it.

diff --git a/download.js b/download.js
index 494b6e3..054da79 100644
--- a/download.js
+++ b/download.js
@@ -138,6 +138,7 @@ for (var category in components) {
 
 		var info = all[id] = {
 			title: all[id].title || all[id],
+			aliasTitles: all[id].aliasTitles,
 			noCSS: all[id].noCSS || all.meta.noCSS,
 			noJS: all[id].noJS || all.meta.noJS,
 			enabled: checked,
@@ -176,6 +177,17 @@ for (var category in components) {
 			info.files.dev.paths.push(cssFile);
 		}
 
+		function getLanguageTitle(lang) {
+			if (!lang.aliasTitles)
+				return lang.title;
+
+			var titles = [lang.title];
+			for (var alias in lang.aliasTitles)
+				if (lang.aliasTitles.hasOwnProperty(alias))
+					titles.push(lang.aliasTitles[alias]);
+			return titles.join(" + ");
+		}
+
 		var label = $u.element.create('label', {
 			attributes: {
 				'data-id': id
@@ -230,7 +242,7 @@ for (var category in components) {
 					properties: {
 						className: 'name'
 					},
-					contents: info.title
+					contents: getLanguageTitle(info)
 				},
 				' ',
 				all[id].owner? {
diff --git a/index.html b/index.html
index 2d6b430..50be230 100644
--- a/index.html
+++ b/index.html
@@ -273,21 +273,40 @@ var html = Prism.highlight(code, Prism.languages.haml, 'haml');</code></pre>
 			continue;
 		}
 		count++;
-		var name = languages[id].title || languages[id];
+
+		var lang = languages[id];
+		var name = lang.title || lang;
+
+		var contents = [
+			name,
+			' - ',
+			{
+				tag: 'code',
+				contents: id
+			}
+		];
+
+		var alias = lang.alias;
+		if (typeof alias === 'string')
+			alias = [alias];
+
+		if (alias) {
+			for (var i = 0, l = alias.length; i < l; i++) {
+				contents.push(
+					', ',
+					{
+						tag: 'code',
+						contents: alias[i]
+					});
+			}
+		}
 
 		languageItems.push({
 			tag: 'li',
 			attributes: {
 				'data-id': id
 			},
-			contents: [
-				name,
-				' - ',
-				{
-					tag: 'code',
-					contents: id
-				}
-			]
+			contents: contents
 		});
 	}
 	$u.element.create('ul', {