Skip to content

Commit

Permalink
Display language aliases (#1626)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Dec 1, 2018
1 parent 1b75da9 commit 654b527
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
14 changes: 13 additions & 1 deletion download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -230,7 +242,7 @@ for (var category in components) {
properties: {
className: 'name'
},
contents: info.title
contents: getLanguageTitle(info)
},
' ',
all[id].owner? {
Expand Down
37 changes: 28 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,40 @@ <h1>Credits</h1>
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', {
Expand Down

0 comments on commit 654b527

Please sign in to comment.