Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gulp: JSON formatting for partly generated files #1933

Merged
merged 9 commits into from
Jun 8, 2019
10 changes: 7 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ function languagePlugins(cb) {
}
}

const jsonLanguagesMap = JSON.stringify(languagesMap);
const jsonDependenciesMap = JSON.stringify(dependenciesMap);
const jsonAliasMap = JSON.stringify(aliasMap);
function formattedStringify(json) {
return JSON.stringify(json, null, '\t').replace(/\n/g, '\n\t');
}

const jsonLanguagesMap = formattedStringify(languagesMap);
const jsonDependenciesMap = formattedStringify(dependenciesMap);
const jsonAliasMap = formattedStringify(aliasMap);

const tasks = [
{
Expand Down
148 changes: 146 additions & 2 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,153 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*dependencies_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":["markup","csharp"],"bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup-templating","ejs":["javascript","markup-templating"],"erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","gml":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","javadoc":["markup","java","javadoclike"],"jolie":"clike","jsdoc":["javascript","javadoclike"],"js-extras":"javascript","jsonp":"json","json5":"json","kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"phpdoc":["php","javadoclike"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":["markup","javascript"],"qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","soy":"markup-templating","swift":"clike","tap":"yaml","textile":"markup","tt2":["clike","markup-templating"],"twig":"markup","typescript":"javascript","t4-cs":["t4-templating","csharp"],"t4-vb":["t4-templating","visual-basic"],"vala":"clike","vbnet":"basic","velocity":"markup","wiki":"markup","xeora":"markup","xquery":"markup"}/*]*/;
var lang_dependencies = /*dependencies_placeholder[*/{
"javascript": "clike",
"actionscript": "javascript",
"arduino": "cpp",
"aspnet": [
"markup",
"csharp"
],
"bison": "c",
"c": "clike",
"csharp": "clike",
"cpp": "c",
"coffeescript": "javascript",
"crystal": "ruby",
"css-extras": "css",
"d": "clike",
"dart": "clike",
"django": "markup-templating",
"ejs": [
"javascript",
"markup-templating"
],
"erb": [
"ruby",
"markup-templating"
],
"fsharp": "clike",
"flow": "javascript",
"glsl": "clike",
"gml": "clike",
"go": "clike",
"groovy": "clike",
"haml": "ruby",
"handlebars": "markup-templating",
"haxe": "clike",
"java": "clike",
"javadoc": [
"markup",
"java",
"javadoclike"
],
"jolie": "clike",
"jsdoc": [
"javascript",
"javadoclike"
],
"js-extras": "javascript",
"jsonp": "json",
"json5": "json",
"kotlin": "clike",
"less": "css",
"markdown": "markup",
"markup-templating": "markup",
"n4js": "javascript",
"nginx": "clike",
"objectivec": "c",
"opencl": "cpp",
"parser": "markup",
"php": [
"clike",
"markup-templating"
],
"phpdoc": [
"php",
"javadoclike"
],
"php-extras": "php",
"plsql": "sql",
"processing": "clike",
"protobuf": "clike",
"pug": [
"markup",
"javascript"
],
"qore": "clike",
"jsx": [
"markup",
"javascript"
],
"tsx": [
"jsx",
"typescript"
],
"reason": "clike",
"ruby": "clike",
"sass": "css",
"scss": "css",
"scala": "java",
"smarty": "markup-templating",
"soy": "markup-templating",
"swift": "clike",
"tap": "yaml",
"textile": "markup",
"tt2": [
"clike",
"markup-templating"
],
"twig": "markup",
"typescript": "javascript",
"t4-cs": [
"t4-templating",
"csharp"
],
"t4-vb": [
"t4-templating",
"visual-basic"
],
"vala": "clike",
"vbnet": "basic",
"velocity": "markup",
"wiki": "markup",
"xeora": "markup",
"xquery": "markup"
}/*]*/;

var lang_aliases = /*aliases_placeholder[*/{"html":"markup","xml":"markup","svg":"markup","mathml":"markup","js":"javascript","adoc":"asciidoc","shell":"bash","rbnf":"bnf","cs":"csharp","dotnet":"csharp","coffee":"coffeescript","jinja2":"django","dockerfile":"docker","gamemakerlanguage":"gml","hs":"haskell","tex":"latex","context":"latex","emacs":"lisp","elisp":"lisp","emacs-lisp":"lisp","md":"markdown","n4jsd":"n4js","objectpascal":"pascal","py":"python","rb":"ruby","ts":"typescript","t4":"t4-cs","vb":"visual-basic","xeoracube":"xeora","yml":"yaml"}/*]*/;
var lang_aliases = /*aliases_placeholder[*/{
"html": "markup",
"xml": "markup",
"svg": "markup",
"mathml": "markup",
"js": "javascript",
"adoc": "asciidoc",
"shell": "bash",
"rbnf": "bnf",
"cs": "csharp",
"dotnet": "csharp",
"coffee": "coffeescript",
"jinja2": "django",
"dockerfile": "docker",
"gamemakerlanguage": "gml",
"hs": "haskell",
"tex": "latex",
"context": "latex",
"emacs": "lisp",
"elisp": "lisp",
"emacs-lisp": "lisp",
"md": "markdown",
"n4jsd": "n4js",
"objectpascal": "pascal",
"py": "python",
"rb": "ruby",
"ts": "typescript",
"t4": "t4-cs",
"vb": "visual-basic",
"xeoracube": "xeora",
"yml": "yaml"
}/*]*/;

var lang_data = {};

Expand Down
191 changes: 157 additions & 34 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,169 @@
(function(){
(function () {

if (typeof self === 'undefined' || !self.Prism || !self.document) {
return;
}

if (!Prism.plugins.toolbar) {
console.warn('Show Languages plugin loaded before Toolbar plugin.');

return;
}
if (typeof self === 'undefined' || !self.Prism || !self.document) {
return;
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","js":"JavaScript","abap":"ABAP","abnf":"Augmented Backus–Naur form","apacheconf":"Apache Configuration","apl":"APL","arff":"ARFF","asciidoc":"AsciiDoc","adoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Bash","basic":"BASIC","bnf":"Backus–Naur form","rbnf":"Routing Backus–Naur form","csharp":"C#","cs":"C#","dotnet":"C#","cpp":"C++","cil":"CIL","coffee":"CoffeeScript","cmake":"CMake","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","jinja2":"Django/Jinja2","dockerfile":"Docker","ebnf":"Extended Backus–Naur form","ejs":"EJS","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","gamemakerlanguage":"GameMaker Language","graphql":"GraphQL","hs":"Haskell","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javadoc":"JavaDoc","javadoclike":"JavaDoc-like","javastacktrace":"Java stack trace","jq":"JQ","jsdoc":"JSDoc","js-extras":"JS Extras","json":"JSON","jsonp":"JSONP","json5":"JSON5","latex":"LaTeX","tex":"TeX","context":"ConTeXt","emacs":"Lisp","elisp":"Lisp","emacs-lisp":"Lisp","lolcode":"LOLCODE","md":"Markdown","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n1ql":"N1QL","n4js":"N4JS","n4jsd":"N4JS","nand2tetris-hdl":"Nand To Tetris HDL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","phpdoc":"PHPDoc","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","py":"Python","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","rb":"Ruby","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","ts":"TypeScript","t4-cs":"T4 Text Templates (C#)","t4":"T4 Text Templates (C#)","t4-vb":"T4 Text Templates (VB)","t4-templating":"T4 templating","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","vb":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML","yml":"YAML"}/*]*/;
if (!Prism.plugins.toolbar) {
console.warn('Show Languages plugin loaded before Toolbar plugin.');

Prism.plugins.toolbar.registerButton('show-language', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
return;
}

/**
* Tries to guess the name of a language given its id.
*
* @param {string} id The language id.
* @returns {string}
*/
function guessTitle(id) {
if (!id) {
return id;
// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{
"html": "HTML",
"xml": "XML",
"svg": "SVG",
"mathml": "MathML",
"css": "CSS",
"clike": "C-like",
"js": "JavaScript",
"abap": "ABAP",
"abnf": "Augmented Backus–Naur form",
"apacheconf": "Apache Configuration",
"apl": "APL",
"arff": "ARFF",
"asciidoc": "AsciiDoc",
"adoc": "AsciiDoc",
"asm6502": "6502 Assembly",
"aspnet": "ASP.NET (C#)",
"autohotkey": "AutoHotkey",
"autoit": "AutoIt",
"shell": "Bash",
"basic": "BASIC",
"bnf": "Backus–Naur form",
"rbnf": "Routing Backus–Naur form",
"csharp": "C#",
"cs": "C#",
"dotnet": "C#",
"cpp": "C++",
"cil": "CIL",
"coffee": "CoffeeScript",
"cmake": "CMake",
"csp": "Content-Security-Policy",
"css-extras": "CSS Extras",
"django": "Django/Jinja2",
"jinja2": "Django/Jinja2",
"dockerfile": "Docker",
"ebnf": "Extended Backus–Naur form",
"ejs": "EJS",
"erb": "ERB",
"fsharp": "F#",
"gcode": "G-code",
"gedcom": "GEDCOM",
"glsl": "GLSL",
"gml": "GameMaker Language",
"gamemakerlanguage": "GameMaker Language",
"graphql": "GraphQL",
"hs": "Haskell",
"hcl": "HCL",
"http": "HTTP",
"hpkp": "HTTP Public-Key-Pins",
"hsts": "HTTP Strict-Transport-Security",
"ichigojam": "IchigoJam",
"inform7": "Inform 7",
"javadoc": "JavaDoc",
"javadoclike": "JavaDoc-like",
"javastacktrace": "Java stack trace",
"jq": "JQ",
"jsdoc": "JSDoc",
"js-extras": "JS Extras",
"json": "JSON",
"jsonp": "JSONP",
"json5": "JSON5",
"latex": "LaTeX",
"tex": "TeX",
"context": "ConTeXt",
"emacs": "Lisp",
"elisp": "Lisp",
"emacs-lisp": "Lisp",
"lolcode": "LOLCODE",
"md": "Markdown",
"markup-templating": "Markup templating",
"matlab": "MATLAB",
"mel": "MEL",
"n1ql": "N1QL",
"n4js": "N4JS",
"n4jsd": "N4JS",
"nand2tetris-hdl": "Nand To Tetris HDL",
"nasm": "NASM",
"nginx": "nginx",
"nsis": "NSIS",
"objectivec": "Objective-C",
"ocaml": "OCaml",
"opencl": "OpenCL",
"parigp": "PARI/GP",
"objectpascal": "Object Pascal",
"php": "PHP",
"phpdoc": "PHPDoc",
"php-extras": "PHP Extras",
"plsql": "PL/SQL",
"powershell": "PowerShell",
"properties": ".properties",
"protobuf": "Protocol Buffers",
"py": "Python",
"q": "Q (kdb+ database)",
"jsx": "React JSX",
"tsx": "React TSX",
"renpy": "Ren'py",
"rest": "reST (reStructuredText)",
"rb": "Ruby",
"sas": "SAS",
"sass": "Sass (Sass)",
"scss": "Sass (Scss)",
"sql": "SQL",
"soy": "Soy (Closure Template)",
"tap": "TAP",
"toml": "TOML",
"tt2": "Template Toolkit 2",
"ts": "TypeScript",
"t4-cs": "T4 Text Templates (C#)",
"t4": "T4 Text Templates (C#)",
"t4-vb": "T4 Text Templates (VB)",
"t4-templating": "T4 templating",
"vbnet": "VB.Net",
"vhdl": "VHDL",
"vim": "vim",
"visual-basic": "Visual Basic",
"vb": "Visual Basic",
"wasm": "WebAssembly",
"wiki": "Wiki markup",
"xeoracube": "XeoraCube",
"xojo": "Xojo (REALbasic)",
"xquery": "XQuery",
"yaml": "YAML",
"yml": "YAML"
}/*]*/;

Prism.plugins.toolbar.registerButton('show-language', function (env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
return;
}
return (id.substring(0, 1).toUpperCase() + id.substring(1)).replace(/s(?=cript)/, 'S');
}

var language = pre.getAttribute('data-language') || Languages[env.language] || guessTitle(env.language);
/**
* Tries to guess the name of a language given its id.
*
* @param {string} id The language id.
* @returns {string}
*/
function guessTitle(id) {
if (!id) {
return id;
}
return (id.substring(0, 1).toUpperCase() + id.substring(1)).replace(/s(?=cript)/, 'S');
}

if(!language) {
return;
}
var element = document.createElement('span');
element.textContent = language;
var language = pre.getAttribute('data-language') || Languages[env.language] || guessTitle(env.language);

if (!language) {
return;
}
var element = document.createElement('span');
element.textContent = language;

return element;
});
return element;
});

})();