From 2d622f17e4f6d746e8f4fa211c7f6b7ccb3f27b4 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Mon, 12 Nov 2018 20:12:44 +0100 Subject: [PATCH 1/4] Show invisibles inside tokens --- .../show-invisibles/prism-show-invisibles.css | 4 +- .../show-invisibles/prism-show-invisibles.js | 99 +++++++++++++++---- .../prism-show-invisibles.min.js | 2 +- 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/plugins/show-invisibles/prism-show-invisibles.css b/plugins/show-invisibles/prism-show-invisibles.css index c57be58812..16583b31d9 100644 --- a/plugins/show-invisibles/prism-show-invisibles.css +++ b/plugins/show-invisibles/prism-show-invisibles.css @@ -9,8 +9,8 @@ .token.cr:before, .token.lf:before, .token.space:before { - color: inherit; - opacity: 0.4; + color: #888; + opacity: 0.6; position: absolute; } diff --git a/plugins/show-invisibles/prism-show-invisibles.js b/plugins/show-invisibles/prism-show-invisibles.js index f3d120a9e8..3b67c7782b 100644 --- a/plugins/show-invisibles/prism-show-invisibles.js +++ b/plugins/show-invisibles/prism-show-invisibles.js @@ -1,21 +1,80 @@ -(function(){ - -if ( - typeof self !== 'undefined' && !self.Prism || - typeof global !== 'undefined' && !global.Prism -) { - return; -} - -Prism.hooks.add('before-highlight', function(env) { - var tokens = env.grammar; - - if (!tokens) return; - - tokens.tab = /\t/g; - tokens.crlf = /\r\n/g; - tokens.lf = /\n/g; - tokens.cr = /\r/g; - tokens.space = / /g; -}); +(function () { + + if ( + typeof self !== 'undefined' && !self.Prism || + typeof global !== 'undefined' && !global.Prism + ) { + return; + } + + + var invisibles = { + 'tab': /\t/, + 'crlf': /\r\n/, + 'lf': /\n/, + 'cr': /\r/, + 'space': / / + }; + + + /** + * Handles the recursive calling of `addInvisibles` for one token. + * + * @param {Object|Array} tokens The grammar or array which contains the token. + * @param {string|number} name The name or index of the token in `tokens`. + */ + function handleToken(tokens, name) { + var value = tokens[name]; + + var type = Prism.util.type(value); + switch (type) { + case 'RegExp': + var inside = {}; + tokens[name] = { + pattern: value, + inside: inside + }; + addInvisibles(inside); + break; + + case 'Array': + for (var i = 0, l = value.length; i < l; i++) + handleToken(value, i); + break; + + default: // 'Object' + var inside = value.inside || (value.inside = {}); + addInvisibles(inside); + break; + } + } + + /** + * Recursively adds patterns to match invisible characters to the given grammar (if not added already). + * + * @param {Object} grammar + */ + function addInvisibles(grammar) { + if (!grammar || grammar['tab']) + return; + + // assign invisibles here to "mark" the grammar in case of self references + for (var name in invisibles) { + if (invisibles.hasOwnProperty(name)) + grammar[name] = invisibles[name]; + } + + for (var name in grammar) { + if (grammar.hasOwnProperty(name) && !invisibles[name]) { + if (name === 'rest') + addInvisibles(grammar['rest']); + else + handleToken(grammar, name); + } + } + } + + Prism.hooks.add('before-highlight', function (env) { + addInvisibles(env.grammar); + }); })(); diff --git a/plugins/show-invisibles/prism-show-invisibles.min.js b/plugins/show-invisibles/prism-show-invisibles.min.js index 9df7258c89..32de8f2b8f 100644 --- a/plugins/show-invisibles/prism-show-invisibles.min.js +++ b/plugins/show-invisibles/prism-show-invisibles.min.js @@ -1 +1 @@ -!function(){"undefined"!=typeof self&&!self.Prism||"undefined"!=typeof global&&!global.Prism||Prism.hooks.add("before-highlight",function(e){var f=e.grammar;f&&(f.tab=/\t/g,f.crlf=/\r\n/g,f.lf=/\n/g,f.cr=/\r/g,f.space=/ /g)})}(); \ No newline at end of file +!function(){function r(a,i){var n=a[i],t=Prism.util.type(n);switch(t){case"RegExp":var f={};a[i]={pattern:n,inside:f},e(f);break;case"Array":for(var s=0,o=n.length;o>s;s++)r(n,s);break;default:var f=n.inside||(n.inside={});e(f)}}function e(i){if(i&&!i.tab){for(var n in a)a.hasOwnProperty(n)&&(i[n]=a[n]);for(var n in i)i.hasOwnProperty(n)&&!a[n]&&("rest"===n?e(i.rest):r(i,n))}}if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var a={tab:/\t/,crlf:/\r\n/,lf:/\n/,cr:/\r/,space:/ /};Prism.hooks.add("before-highlight",function(r){e(r.grammar)})}}(); \ No newline at end of file From 7a2d153b9be3edd7b54be37cdf47b06276fa2861 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Mon, 12 Nov 2018 20:14:19 +0100 Subject: [PATCH 2/4] Revert "Show invisibles inside tokens" This reverts commit 2d622f17e4f6d746e8f4fa211c7f6b7ccb3f27b4. --- .../show-invisibles/prism-show-invisibles.css | 4 +- .../show-invisibles/prism-show-invisibles.js | 99 ++++--------------- .../prism-show-invisibles.min.js | 2 +- 3 files changed, 23 insertions(+), 82 deletions(-) diff --git a/plugins/show-invisibles/prism-show-invisibles.css b/plugins/show-invisibles/prism-show-invisibles.css index 16583b31d9..c57be58812 100644 --- a/plugins/show-invisibles/prism-show-invisibles.css +++ b/plugins/show-invisibles/prism-show-invisibles.css @@ -9,8 +9,8 @@ .token.cr:before, .token.lf:before, .token.space:before { - color: #888; - opacity: 0.6; + color: inherit; + opacity: 0.4; position: absolute; } diff --git a/plugins/show-invisibles/prism-show-invisibles.js b/plugins/show-invisibles/prism-show-invisibles.js index 3b67c7782b..f3d120a9e8 100644 --- a/plugins/show-invisibles/prism-show-invisibles.js +++ b/plugins/show-invisibles/prism-show-invisibles.js @@ -1,80 +1,21 @@ -(function () { - - if ( - typeof self !== 'undefined' && !self.Prism || - typeof global !== 'undefined' && !global.Prism - ) { - return; - } - - - var invisibles = { - 'tab': /\t/, - 'crlf': /\r\n/, - 'lf': /\n/, - 'cr': /\r/, - 'space': / / - }; - - - /** - * Handles the recursive calling of `addInvisibles` for one token. - * - * @param {Object|Array} tokens The grammar or array which contains the token. - * @param {string|number} name The name or index of the token in `tokens`. - */ - function handleToken(tokens, name) { - var value = tokens[name]; - - var type = Prism.util.type(value); - switch (type) { - case 'RegExp': - var inside = {}; - tokens[name] = { - pattern: value, - inside: inside - }; - addInvisibles(inside); - break; - - case 'Array': - for (var i = 0, l = value.length; i < l; i++) - handleToken(value, i); - break; - - default: // 'Object' - var inside = value.inside || (value.inside = {}); - addInvisibles(inside); - break; - } - } - - /** - * Recursively adds patterns to match invisible characters to the given grammar (if not added already). - * - * @param {Object} grammar - */ - function addInvisibles(grammar) { - if (!grammar || grammar['tab']) - return; - - // assign invisibles here to "mark" the grammar in case of self references - for (var name in invisibles) { - if (invisibles.hasOwnProperty(name)) - grammar[name] = invisibles[name]; - } - - for (var name in grammar) { - if (grammar.hasOwnProperty(name) && !invisibles[name]) { - if (name === 'rest') - addInvisibles(grammar['rest']); - else - handleToken(grammar, name); - } - } - } - - Prism.hooks.add('before-highlight', function (env) { - addInvisibles(env.grammar); - }); +(function(){ + +if ( + typeof self !== 'undefined' && !self.Prism || + typeof global !== 'undefined' && !global.Prism +) { + return; +} + +Prism.hooks.add('before-highlight', function(env) { + var tokens = env.grammar; + + if (!tokens) return; + + tokens.tab = /\t/g; + tokens.crlf = /\r\n/g; + tokens.lf = /\n/g; + tokens.cr = /\r/g; + tokens.space = / /g; +}); })(); diff --git a/plugins/show-invisibles/prism-show-invisibles.min.js b/plugins/show-invisibles/prism-show-invisibles.min.js index 32de8f2b8f..9df7258c89 100644 --- a/plugins/show-invisibles/prism-show-invisibles.min.js +++ b/plugins/show-invisibles/prism-show-invisibles.min.js @@ -1 +1 @@ -!function(){function r(a,i){var n=a[i],t=Prism.util.type(n);switch(t){case"RegExp":var f={};a[i]={pattern:n,inside:f},e(f);break;case"Array":for(var s=0,o=n.length;o>s;s++)r(n,s);break;default:var f=n.inside||(n.inside={});e(f)}}function e(i){if(i&&!i.tab){for(var n in a)a.hasOwnProperty(n)&&(i[n]=a[n]);for(var n in i)i.hasOwnProperty(n)&&!a[n]&&("rest"===n?e(i.rest):r(i,n))}}if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var a={tab:/\t/,crlf:/\r\n/,lf:/\n/,cr:/\r/,space:/ /};Prism.hooks.add("before-highlight",function(r){e(r.grammar)})}}(); \ No newline at end of file +!function(){"undefined"!=typeof self&&!self.Prism||"undefined"!=typeof global&&!global.Prism||Prism.hooks.add("before-highlight",function(e){var f=e.grammar;f&&(f.tab=/\t/g,f.crlf=/\r\n/g,f.lf=/\n/g,f.cr=/\r/g,f.space=/ /g)})}(); \ No newline at end of file From 17018b45404060ae01e64c18cdea1091c55a992d Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Wed, 21 Nov 2018 13:12:34 +0100 Subject: [PATCH 3/4] Displayed aliases for Download and Index --- download.js | 14 +++++++++++++- index.html | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/download.js b/download.js index 494b6e38e1..44a7065a21 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 = []; + for (var alias in lang.aliasTitles) + if (lang.aliasTitles.hasOwnProperty(alias)) + titles.push(lang.aliasTitles[alias]); + return lang.title + " + " + 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 2d6b430582..50be230c2e 100644 --- a/index.html +++ b/index.html @@ -273,21 +273,40 @@

Credits

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', { From 5b4baa28560b91254b66a68eb00a6ba79faf1eb2 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Wed, 21 Nov 2018 13:18:26 +0100 Subject: [PATCH 4/4] Small change --- download.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/download.js b/download.js index 44a7065a21..054da79d33 100644 --- a/download.js +++ b/download.js @@ -181,11 +181,11 @@ for (var category in components) { if (!lang.aliasTitles) return lang.title; - var titles = []; + var titles = [lang.title]; for (var alias in lang.aliasTitles) if (lang.aliasTitles.hasOwnProperty(alias)) titles.push(lang.aliasTitles[alias]); - return lang.title + " + " + titles.join(" + "); + return titles.join(" + "); } var label = $u.element.create('label', {