From 99edee606c1a1c90f655b05bb66cffd2b1671fd9 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Tue, 14 May 2019 19:14:07 +0200 Subject: [PATCH 01/11] Improved Diff --- components/prism-diff.js | 126 +++++++++++++++++++++---- components/prism-diff.min.js | 2 +- examples/prism-diff.html | 10 +- tests/languages/diff/diff_feature.test | 15 +-- 4 files changed, 125 insertions(+), 28 deletions(-) diff --git a/components/prism-diff.js b/components/prism-diff.js index a6116a4b4b..3060a0a832 100644 --- a/components/prism-diff.js +++ b/components/prism-diff.js @@ -1,20 +1,106 @@ -Prism.languages.diff = { - 'coord': [ - // Match all kinds of coord lines (prefixed by "+++", "---" or "***"). - /^(?:\*{3}|-{3}|\+{3}).*$/m, - // Match "@@ ... @@" coord lines in unified diff. - /^@@.*@@$/m, - // Match coord lines in normal diff (starts with a number). - /^\d+.*$/m - ], - - // Match inserted and deleted lines. Support both +/- and >/< styles. - 'deleted': /^[-<].*$/m, - 'inserted': /^[+>].*$/m, - - // Match "different" lines (prefixed with "!") in context diff. - 'diff': { - 'pattern': /^!(?!!).+$/m, - 'alias': 'important' - } -}; +(function (Prism) { + var prefixes = { + 'deleted-sign': '-', + 'deleted-arrow': '<', + 'inserted-sign': '+', + 'inserted-arrow': '>', + 'unchanged': ' ', + 'diff': '!', + }; + + Prism.languages.diff = { + 'coord': [ + // Match all kinds of coord lines (prefixed by "+++", "---" or "***"). + /^(?:\*{3}|-{3}|\+{3}).*$/m, + // Match "@@ ... @@" coord lines in unified diff. + /^@@.*@@$/m, + // Match coord lines in normal diff (starts with a number). + /^\d+.*$/m + ] + + // deleted, inserted, unchanged, diff + }; + + Object.keys(prefixes).forEach(function (name) { + var prefix = prefixes[name]; + + var alias = []; + if (!/^\w+$/.test(name)) { // "deleted-sign" -> "deleted" + alias.push(/\w+/.exec(name)[0]); + } + if (name === "diff") { + alias.push("bold"); + } + + Prism.languages.diff[name] = { + // pattern: /^(?:[_].*(?:\r\n?|\n|(?![\s\S])))+/m + pattern: RegExp('^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm'), + alias: alias + }; + }); + + + + var LANGUAGE_REGEX = /diff-([\w-]+)/i; + + Prism.hooks.add('before-sanity-check', function (env) { + var lang = env.language; + if (LANGUAGE_REGEX.test(lang)) { + env.grammar = Prism.languages[lang] = Prism.languages.diff; + } + }) + + Prism.hooks.add('wrap', function (env) { + var diffLanguage, diffGrammar; + + if (env.language !== 'diff') { + var langMatch = LANGUAGE_REGEX.exec(env.language); + if (!langMatch) { + return; // not a language specific diff + } + + diffLanguage = langMatch[1]; + diffGrammar = Prism.languages[diffLanguage]; + } + + // one of the diff tokens without any nested tokens + if (env.type in prefixes && env.content.indexOf('<') === -1) { + /** @type {string} */ + var decoded = env.content.replace(/&/g, '&').replace(/</g, '<'); + + // remove any one-character prefix + var code = decoded.replace(/(^|[\r\n])./g, '$1'); + + // highlight, if possible + var highlighted; + if (diffGrammar) { + highlighted = Prism.highlight(code, diffGrammar, diffLanguage); + } else { + highlighted = Prism.util.encode(code); + } + + // get the HTML source of the prefix token + var prefixToken = new Prism.Token('prefix', prefixes[env.type], [/\w+/.exec(env.type)[0]]); + var prefix = Prism.Token.stringify(prefixToken, env.language); + + // the highlighted code might contain tags which contain a line break. + // This will NOT be handled correctly, so I just kinda hope that it doesn't happen. + + // add prefix + var lines = highlighted.split(/^/gm); // split lines like so: "a\n\b\nc" -> ["a\n", "b\n", "c"] + for (var i = lines.length - 1; i >= 0; i--) { + lines[i] = prefix + lines[i]; + } + if (/(?:^|[\r\n]).$/.test(decoded)) { + // because both "+a\n+" and "+a\n" will map to "a\n" after the prefix is removed + lines.push(prefix); + } + env.content = lines.join(''); + + if (diffGrammar) { + env.classes.push('language-' + diffLanguage); + } + } + }); + +}(Prism)); diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js index 9653de67a8..ab794d1177 100644 --- a/components/prism-diff.min.js +++ b/components/prism-diff.min.js @@ -1 +1 @@ -Prism.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m],deleted:/^[-<].*$/m,inserted:/^[+>].*$/m,diff:{pattern:/^!(?!!).+$/m,alias:"important"}}; \ No newline at end of file +!function(o){var c={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};o.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]},Object.keys(c).forEach(function(e){var a=c[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),o.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var u=/diff-([\w-]+)/i;o.hooks.add("before-sanity-check",function(e){var a=e.language;u.test(a)&&(e.grammar=o.languages[a]=o.languages.diff)}),o.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var t=u.exec(e.language);if(!t)return;a=t[1],n=o.languages[a]}if(e.type in c&&-1===e.content.indexOf("<")){var g,r=e.content.replace(/&/g,"&").replace(/</g,"<"),i=r.replace(/(^|[\r\n])./g,"$1");g=n?o.highlight(i,n,a):o.util.encode(i);for(var s=new o.Token("prefix",c[e.type],[/\w+/.exec(e.type)[0]]),f=o.Token.stringify(s,e.language),d=g.split(/^/gm),l=d.length-1;0<=l;l--)d[l]=f+d[l];/(?:^|[\r\n]).$/.test(r)&&d.push(f),e.content=d.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file diff --git a/examples/prism-diff.html b/examples/prism-diff.html index b9229a1740..4d565d62d6 100644 --- a/examples/prism-diff.html +++ b/examples/prism-diff.html @@ -30,4 +30,12 @@

Unified Diff

headers: "src/*.h" - qt: core + qt: core gui - public_headers: "src/*.h" \ No newline at end of file + public_headers: "src/*.h" + +

Language specific Diff

+

Using the language-diff-xxxx class for your code elements will enable language specific highlighting for your diffs.

+
@@ -4,6 +4,5 @@
+-    const foo = bar.baz([1, 2, 3]);
+-    foo = foo + 1;
++    const f = bar.baz([1, 2, 3]) + 1;
+     console.log(`f: ${f}`);
diff --git a/tests/languages/diff/diff_feature.test b/tests/languages/diff/diff_feature.test index 0e53490016..4379e56d44 100644 --- a/tests/languages/diff/diff_feature.test +++ b/tests/languages/diff/diff_feature.test @@ -1,5 +1,7 @@ ! qt: core + unchanged + - qt: core + qt: core gui @@ -9,13 +11,14 @@ ---------------------------------------------------- [ - ["diff", "! qt: core"], - ["deleted", "- qt: core"], - ["inserted", "+ qt: core gui"], - ["deleted", "< qt: core"], - ["inserted", "> qt: core quick"] + ["diff", "! qt: core\r\n"], + ["unchanged", " unchanged\r\n"], + ["deleted-sign", "- qt: core\r\n"], + ["inserted-sign", "+ qt: core gui\r\n"], + ["deleted-arrow", "< qt: core\r\n"], + ["inserted-arrow", "> qt: core quick"] ] ---------------------------------------------------- -Checks for deleted, inserted and different lines. \ No newline at end of file +Checks for deleted, inserted and different lines. From cd952c5b15adaa60c2ef622074f5ea0813b9bda3 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Tue, 14 May 2019 19:55:51 +0200 Subject: [PATCH 02/11] Better example --- examples/prism-diff.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/prism-diff.html b/examples/prism-diff.html index 4d565d62d6..46b42a9c9b 100644 --- a/examples/prism-diff.html +++ b/examples/prism-diff.html @@ -35,7 +35,7 @@

Unified Diff

Language specific Diff

Using the language-diff-xxxx class for your code elements will enable language specific highlighting for your diffs.

@@ -4,6 +4,5 @@
--    const foo = bar.baz([1, 2, 3]);
+-    let foo = bar.baz([1, 2, 3]);
 -    foo = foo + 1;
-+    const f = bar.baz([1, 2, 3]) + 1;
-     console.log(`f: ${f}`);
++ const foo = bar.baz([1, 2, 3]) + 1; + console.log(`foo: ${foo}`); From 5682cdc559f9bb1568e1e505092fa33bc2833dc6 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Tue, 14 May 2019 19:56:07 +0200 Subject: [PATCH 03/11] Fixed line splitting bug with \r\n --- components/prism-diff.js | 7 ++++--- components/prism-diff.min.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/prism-diff.js b/components/prism-diff.js index 3060a0a832..6f99458c96 100644 --- a/components/prism-diff.js +++ b/components/prism-diff.js @@ -87,9 +87,10 @@ // This will NOT be handled correctly, so I just kinda hope that it doesn't happen. // add prefix - var lines = highlighted.split(/^/gm); // split lines like so: "a\n\b\nc" -> ["a\n", "b\n", "c"] - for (var i = lines.length - 1; i >= 0; i--) { - lines[i] = prefix + lines[i]; + var lines = [], m; + var linePattern = /.*(?:\r\n?|\n|.(?!.))/g + while (m = linePattern.exec(highlighted)) { + lines.push(prefix + m[0]); } if (/(?:^|[\r\n]).$/.test(decoded)) { // because both "+a\n+" and "+a\n" will map to "a\n" after the prefix is removed diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js index ab794d1177..30ebccc449 100644 --- a/components/prism-diff.min.js +++ b/components/prism-diff.min.js @@ -1 +1 @@ -!function(o){var c={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};o.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]},Object.keys(c).forEach(function(e){var a=c[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),o.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var u=/diff-([\w-]+)/i;o.hooks.add("before-sanity-check",function(e){var a=e.language;u.test(a)&&(e.grammar=o.languages[a]=o.languages.diff)}),o.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var t=u.exec(e.language);if(!t)return;a=t[1],n=o.languages[a]}if(e.type in c&&-1===e.content.indexOf("<")){var g,r=e.content.replace(/&/g,"&").replace(/</g,"<"),i=r.replace(/(^|[\r\n])./g,"$1");g=n?o.highlight(i,n,a):o.util.encode(i);for(var s=new o.Token("prefix",c[e.type],[/\w+/.exec(e.type)[0]]),f=o.Token.stringify(s,e.language),d=g.split(/^/gm),l=d.length-1;0<=l;l--)d[l]=f+d[l];/(?:^|[\r\n]).$/.test(r)&&d.push(f),e.content=d.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file +!function(u){var l={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};u.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]},Object.keys(l).forEach(function(e){var n=l[e],a=[];/^\w+$/.test(e)||a.push(/\w+/.exec(e)[0]),"diff"===e&&a.push("bold"),u.languages.diff[e]={pattern:RegExp("^(?:["+n+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:a}});var p=/diff-([\w-]+)/i;u.hooks.add("before-sanity-check",function(e){var n=e.language;p.test(n)&&(e.grammar=u.languages[n]=u.languages.diff)}),u.hooks.add("wrap",function(e){var n,a;if("diff"!==e.language){var r=p.exec(e.language);if(!r)return;n=r[1],a=u.languages[n]}if(e.type in l&&-1===e.content.indexOf("<")){var g,t=e.content.replace(/&/g,"&").replace(/</g,"<"),i=t.replace(/(^|[\r\n])./g,"$1");g=a?u.highlight(i,a,n):u.util.encode(i);for(var s,f=new u.Token("prefix",l[e.type],[/\w+/.exec(e.type)[0]]),d=u.Token.stringify(f,e.language),o=[],c=/.*(?:\r\n?|\n|.(?!.))/g;s=c.exec(g);)o.push(d+s[0]);/(?:^|[\r\n]).$/.test(t)&&o.push(d),e.content=o.join(""),a&&e.classes.push("language-"+n)}})}(Prism); \ No newline at end of file From d84ef71995c26f35e21305d4c0d2b2e103bb157f Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Tue, 14 May 2019 20:03:45 +0200 Subject: [PATCH 04/11] Better alias creation --- components/prism-diff.js | 8 +++++++- components/prism-diff.min.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/prism-diff.js b/components/prism-diff.js index 6f99458c96..f63e914c93 100644 --- a/components/prism-diff.js +++ b/components/prism-diff.js @@ -45,10 +45,16 @@ Prism.hooks.add('before-sanity-check', function (env) { var lang = env.language; - if (LANGUAGE_REGEX.test(lang)) { + if (LANGUAGE_REGEX.test(lang) && !env.grammar) { env.grammar = Prism.languages[lang] = Prism.languages.diff; } }) + Prism.hooks.add('before-tokenize', function (env) { + var lang = env.language; + if (LANGUAGE_REGEX.test(lang) && !Prism.languages[lang]) { + Prism.languages[lang] = Prism.languages.diff; + } + }) Prism.hooks.add('wrap', function (env) { var diffLanguage, diffGrammar; diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js index 30ebccc449..99bc2ed6dc 100644 --- a/components/prism-diff.min.js +++ b/components/prism-diff.min.js @@ -1 +1 @@ -!function(u){var l={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};u.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]},Object.keys(l).forEach(function(e){var n=l[e],a=[];/^\w+$/.test(e)||a.push(/\w+/.exec(e)[0]),"diff"===e&&a.push("bold"),u.languages.diff[e]={pattern:RegExp("^(?:["+n+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:a}});var p=/diff-([\w-]+)/i;u.hooks.add("before-sanity-check",function(e){var n=e.language;p.test(n)&&(e.grammar=u.languages[n]=u.languages.diff)}),u.hooks.add("wrap",function(e){var n,a;if("diff"!==e.language){var r=p.exec(e.language);if(!r)return;n=r[1],a=u.languages[n]}if(e.type in l&&-1===e.content.indexOf("<")){var g,t=e.content.replace(/&/g,"&").replace(/</g,"<"),i=t.replace(/(^|[\r\n])./g,"$1");g=a?u.highlight(i,a,n):u.util.encode(i);for(var s,f=new u.Token("prefix",l[e.type],[/\w+/.exec(e.type)[0]]),d=u.Token.stringify(f,e.language),o=[],c=/.*(?:\r\n?|\n|.(?!.))/g;s=c.exec(g);)o.push(d+s[0]);/(?:^|[\r\n]).$/.test(t)&&o.push(d),e.content=o.join(""),a&&e.classes.push("language-"+n)}})}(Prism); \ No newline at end of file +!function(l){var c={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};l.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]},Object.keys(c).forEach(function(e){var a=c[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),l.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var p=/diff-([\w-]+)/i;l.hooks.add("before-sanity-check",function(e){var a=e.language;p.test(a)&&!e.grammar&&(e.grammar=l.languages[a]=l.languages.diff)}),l.hooks.add("before-tokenize",function(e){var a=e.language;p.test(a)&&!l.languages[a]&&(l.languages[a]=l.languages.diff)}),l.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var g=p.exec(e.language);if(!g)return;a=g[1],n=l.languages[a]}if(e.type in c&&-1===e.content.indexOf("<")){var r,t=e.content.replace(/&/g,"&").replace(/</g,"<"),i=t.replace(/(^|[\r\n])./g,"$1");r=n?l.highlight(i,n,a):l.util.encode(i);for(var s,f=new l.Token("prefix",c[e.type],[/\w+/.exec(e.type)[0]]),o=l.Token.stringify(f,e.language),u=[],d=/.*(?:\r\n?|\n|.(?!.))/g;s=d.exec(r);)u.push(o+s[0]);/(?:^|[\r\n]).$/.test(t)&&u.push(o),e.content=u.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file From dccdf9f33fc5acb1109f48b754b3d0924e2b91da Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Wed, 15 May 2019 13:52:12 +0200 Subject: [PATCH 05/11] More doc --- components/prism-diff.js | 22 ++++++++++++++-------- components/prism-diff.min.js | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/components/prism-diff.js b/components/prism-diff.js index f63e914c93..f0e014e75d 100644 --- a/components/prism-diff.js +++ b/components/prism-diff.js @@ -1,12 +1,4 @@ (function (Prism) { - var prefixes = { - 'deleted-sign': '-', - 'deleted-arrow': '<', - 'inserted-sign': '+', - 'inserted-arrow': '>', - 'unchanged': ' ', - 'diff': '!', - }; Prism.languages.diff = { 'coord': [ @@ -21,6 +13,20 @@ // deleted, inserted, unchanged, diff }; + /** + * A map from the name of a block to its line prefix. + * + * @type {Object} + */ + var prefixes = { + 'deleted-sign': '-', + 'deleted-arrow': '<', + 'inserted-sign': '+', + 'inserted-arrow': '>', + 'unchanged': ' ', + 'diff': '!', + }; + Object.keys(prefixes).forEach(function (name) { var prefix = prefixes[name]; diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js index 99bc2ed6dc..4019785aaf 100644 --- a/components/prism-diff.min.js +++ b/components/prism-diff.min.js @@ -1 +1 @@ -!function(l){var c={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};l.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]},Object.keys(c).forEach(function(e){var a=c[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),l.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var p=/diff-([\w-]+)/i;l.hooks.add("before-sanity-check",function(e){var a=e.language;p.test(a)&&!e.grammar&&(e.grammar=l.languages[a]=l.languages.diff)}),l.hooks.add("before-tokenize",function(e){var a=e.language;p.test(a)&&!l.languages[a]&&(l.languages[a]=l.languages.diff)}),l.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var g=p.exec(e.language);if(!g)return;a=g[1],n=l.languages[a]}if(e.type in c&&-1===e.content.indexOf("<")){var r,t=e.content.replace(/&/g,"&").replace(/</g,"<"),i=t.replace(/(^|[\r\n])./g,"$1");r=n?l.highlight(i,n,a):l.util.encode(i);for(var s,f=new l.Token("prefix",c[e.type],[/\w+/.exec(e.type)[0]]),o=l.Token.stringify(f,e.language),u=[],d=/.*(?:\r\n?|\n|.(?!.))/g;s=d.exec(r);)u.push(o+s[0]);/(?:^|[\r\n]).$/.test(t)&&u.push(o),e.content=u.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file +!function(l){l.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]};var c={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(c).forEach(function(e){var a=c[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),l.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var p=/diff-([\w-]+)/i;l.hooks.add("before-sanity-check",function(e){var a=e.language;p.test(a)&&!e.grammar&&(e.grammar=l.languages[a]=l.languages.diff)}),l.hooks.add("before-tokenize",function(e){var a=e.language;p.test(a)&&!l.languages[a]&&(l.languages[a]=l.languages.diff)}),l.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var g=p.exec(e.language);if(!g)return;a=g[1],n=l.languages[a]}if(e.type in c&&-1===e.content.indexOf("<")){var r,t=e.content.replace(/&/g,"&").replace(/</g,"<"),i=t.replace(/(^|[\r\n])./g,"$1");r=n?l.highlight(i,n,a):l.util.encode(i);for(var s,f=new l.Token("prefix",c[e.type],[/\w+/.exec(e.type)[0]]),o=l.Token.stringify(f,e.language),u=[],d=/.*(?:\r\n?|\n|.(?!.))/g;s=d.exec(r);)u.push(o+s[0]);/(?:^|[\r\n]).$/.test(t)&&u.push(o),e.content=u.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file From 70c21578340b80b2f637b52450ed3a39a014b4dc Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Wed, 15 May 2019 14:26:57 +0200 Subject: [PATCH 06/11] HTML aware line splitting --- components/prism-diff.js | 21 ++++++++++++--------- components/prism-diff.min.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/components/prism-diff.js b/components/prism-diff.js index f0e014e75d..721d1d3537 100644 --- a/components/prism-diff.js +++ b/components/prism-diff.js @@ -27,6 +27,7 @@ 'diff': '!', }; + // add a token for each prefix Object.keys(prefixes).forEach(function (name) { var prefix = prefixes[name]; @@ -46,8 +47,10 @@ }); - var LANGUAGE_REGEX = /diff-([\w-]+)/i; + var HTML_TAG = /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi; + //this will match a line plus the line break while ignoring the line breaks HTML tags may contain. + var HTML_LINE = RegExp(/(?:__|[^\r\n<])*(?:\r\n?|\n|(?:__|[^\r\n<])(?![^\r\n]))/.source.replace(/__/g, HTML_TAG.source), 'gi'); Prism.hooks.add('before-sanity-check', function (env) { var lang = env.language; @@ -76,9 +79,12 @@ } // one of the diff tokens without any nested tokens - if (env.type in prefixes && env.content.indexOf('<') === -1) { + if (env.type in prefixes) { + /** @type {string} */ + var content = env.content.replace(HTML_TAG, ''); // remove all HTML tags + /** @type {string} */ - var decoded = env.content.replace(/&/g, '&').replace(/</g, '<'); + var decoded = content.replace(/&/g, '&').replace(/</g, '<'); // remove any one-character prefix var code = decoded.replace(/(^|[\r\n])./g, '$1'); @@ -95,17 +101,14 @@ var prefixToken = new Prism.Token('prefix', prefixes[env.type], [/\w+/.exec(env.type)[0]]); var prefix = Prism.Token.stringify(prefixToken, env.language); - // the highlighted code might contain tags which contain a line break. - // This will NOT be handled correctly, so I just kinda hope that it doesn't happen. - // add prefix var lines = [], m; - var linePattern = /.*(?:\r\n?|\n|.(?!.))/g - while (m = linePattern.exec(highlighted)) { + HTML_LINE.lastIndex = 0; + while (m = HTML_LINE.exec(highlighted)) { lines.push(prefix + m[0]); } if (/(?:^|[\r\n]).$/.test(decoded)) { - // because both "+a\n+" and "+a\n" will map to "a\n" after the prefix is removed + // because both "+a\n+" and "+a\n" will map to "a\n" after the line prefixes are removed lines.push(prefix); } env.content = lines.join(''); diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js index 4019785aaf..c996e29cc0 100644 --- a/components/prism-diff.min.js +++ b/components/prism-diff.min.js @@ -1 +1 @@ -!function(l){l.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]};var c={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(c).forEach(function(e){var a=c[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),l.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var p=/diff-([\w-]+)/i;l.hooks.add("before-sanity-check",function(e){var a=e.language;p.test(a)&&!e.grammar&&(e.grammar=l.languages[a]=l.languages.diff)}),l.hooks.add("before-tokenize",function(e){var a=e.language;p.test(a)&&!l.languages[a]&&(l.languages[a]=l.languages.diff)}),l.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var g=p.exec(e.language);if(!g)return;a=g[1],n=l.languages[a]}if(e.type in c&&-1===e.content.indexOf("<")){var r,t=e.content.replace(/&/g,"&").replace(/</g,"<"),i=t.replace(/(^|[\r\n])./g,"$1");r=n?l.highlight(i,n,a):l.util.encode(i);for(var s,f=new l.Token("prefix",c[e.type],[/\w+/.exec(e.type)[0]]),o=l.Token.stringify(f,e.language),u=[],d=/.*(?:\r\n?|\n|.(?!.))/g;s=d.exec(r);)u.push(o+s[0]);/(?:^|[\r\n]).$/.test(t)&&u.push(o),e.content=u.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file +!function(u){u.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]};var d={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(d).forEach(function(e){var a=d[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),u.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var c=/diff-([\w-]+)/i,p=/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi,h=RegExp("(?:__|[^\r\\n<])*(?:\r\\n?|\n|(?:__|[^\r\\n<])(?![^\r\\n]))".replace(/__/g,p.source),"gi");u.hooks.add("before-sanity-check",function(e){var a=e.language;c.test(a)&&!e.grammar&&(e.grammar=u.languages[a]=u.languages.diff)}),u.hooks.add("before-tokenize",function(e){var a=e.language;c.test(a)&&!u.languages[a]&&(u.languages[a]=u.languages.diff)}),u.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var s=c.exec(e.language);if(!s)return;a=s[1],n=u.languages[a]}if(e.type in d){var g,r=e.content.replace(p,"").replace(/&/g,"&").replace(/</g,"<"),i=r.replace(/(^|[\r\n])./g,"$1");g=n?u.highlight(i,n,a):u.util.encode(i);var t,f=new u.Token("prefix",d[e.type],[/\w+/.exec(e.type)[0]]),l=u.Token.stringify(f,e.language),o=[];for(h.lastIndex=0;t=h.exec(g);)o.push(l+t[0]);/(?:^|[\r\n]).$/.test(r)&&o.push(l),e.content=o.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file From d44c1a4057e599d1988ce635a8be4f0919d36565 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Sat, 25 May 2019 14:04:27 +0200 Subject: [PATCH 07/11] Fixed HTML decoding --- components/prism-diff.js | 2 +- components/prism-diff.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/prism-diff.js b/components/prism-diff.js index 721d1d3537..6faa0f7462 100644 --- a/components/prism-diff.js +++ b/components/prism-diff.js @@ -84,7 +84,7 @@ var content = env.content.replace(HTML_TAG, ''); // remove all HTML tags /** @type {string} */ - var decoded = content.replace(/&/g, '&').replace(/</g, '<'); + var decoded = content.replace(/</g, '<').replace(/&/g, '&'); // remove any one-character prefix var code = decoded.replace(/(^|[\r\n])./g, '$1'); diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js index c996e29cc0..a6589e8a18 100644 --- a/components/prism-diff.min.js +++ b/components/prism-diff.min.js @@ -1 +1 @@ -!function(u){u.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]};var d={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(d).forEach(function(e){var a=d[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),u.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var c=/diff-([\w-]+)/i,p=/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi,h=RegExp("(?:__|[^\r\\n<])*(?:\r\\n?|\n|(?:__|[^\r\\n<])(?![^\r\\n]))".replace(/__/g,p.source),"gi");u.hooks.add("before-sanity-check",function(e){var a=e.language;c.test(a)&&!e.grammar&&(e.grammar=u.languages[a]=u.languages.diff)}),u.hooks.add("before-tokenize",function(e){var a=e.language;c.test(a)&&!u.languages[a]&&(u.languages[a]=u.languages.diff)}),u.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var s=c.exec(e.language);if(!s)return;a=s[1],n=u.languages[a]}if(e.type in d){var g,r=e.content.replace(p,"").replace(/&/g,"&").replace(/</g,"<"),i=r.replace(/(^|[\r\n])./g,"$1");g=n?u.highlight(i,n,a):u.util.encode(i);var t,f=new u.Token("prefix",d[e.type],[/\w+/.exec(e.type)[0]]),l=u.Token.stringify(f,e.language),o=[];for(h.lastIndex=0;t=h.exec(g);)o.push(l+t[0]);/(?:^|[\r\n]).$/.test(r)&&o.push(l),e.content=o.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file +!function(u){u.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]};var d={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(d).forEach(function(e){var a=d[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),u.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var c=/diff-([\w-]+)/i,p=/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi,h=RegExp("(?:__|[^\r\\n<])*(?:\r\\n?|\n|(?:__|[^\r\\n<])(?![^\r\\n]))".replace(/__/g,p.source),"gi");u.hooks.add("before-sanity-check",function(e){var a=e.language;c.test(a)&&!e.grammar&&(e.grammar=u.languages[a]=u.languages.diff)}),u.hooks.add("before-tokenize",function(e){var a=e.language;c.test(a)&&!u.languages[a]&&(u.languages[a]=u.languages.diff)}),u.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var s=c.exec(e.language);if(!s)return;a=s[1],n=u.languages[a]}if(e.type in d){var g,r=e.content.replace(p,"").replace(/</g,"<").replace(/&/g,"&"),i=r.replace(/(^|[\r\n])./g,"$1");g=n?u.highlight(i,n,a):u.util.encode(i);var t,f=new u.Token("prefix",d[e.type],[/\w+/.exec(e.type)[0]]),l=u.Token.stringify(f,e.language),o=[];for(h.lastIndex=0;t=h.exec(g);)o.push(l+t[0]);/(?:^|[\r\n]).$/.test(r)&&o.push(l),e.content=o.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file From 9d74276790a18efa4c6bd45684553cc084c1a80f Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Sun, 21 Jul 2019 23:17:36 +0200 Subject: [PATCH 08/11] Made it a plugin --- components.js | 2 +- components.json | 5 ++ components/prism-diff.js | 80 ++---------------- components/prism-diff.min.js | 2 +- plugins/diff-highlight/index.html | 81 ++++++++++++++++++ .../diff-highlight/prism-diff-highlight.css | 13 +++ .../diff-highlight/prism-diff-highlight.js | 83 +++++++++++++++++++ .../prism-diff-highlight.min.js | 1 + 8 files changed, 191 insertions(+), 76 deletions(-) create mode 100644 plugins/diff-highlight/index.html create mode 100644 plugins/diff-highlight/prism-diff-highlight.css create mode 100644 plugins/diff-highlight/prism-diff-highlight.js create mode 100644 plugins/diff-highlight/prism-diff-highlight.min.js diff --git a/components.js b/components.js index 3a5e71c68e..c987253d84 100644 --- a/components.js +++ b/components.js @@ -1,2 +1,2 @@ -var components = {"core":{"meta":{"path":"components/prism-core.js","option":"mandatory"},"core":"Core"},"themes":{"meta":{"path":"themes/{id}.css","link":"index.html?theme={id}","exclusive":true},"prism":{"title":"Default","option":"default"},"prism-dark":"Dark","prism-funky":"Funky","prism-okaidia":{"title":"Okaidia","owner":"ocodia"},"prism-twilight":{"title":"Twilight","owner":"remybach"},"prism-coy":{"title":"Coy","owner":"tshedor"},"prism-solarizedlight":{"title":"Solarized Light","owner":"hectormatos2011 "},"prism-tomorrow":{"title":"Tomorrow Night","owner":"Rosey"}},"languages":{"meta":{"path":"components/prism-{id}","noCSS":true,"examplesPath":"examples/prism-{id}","addCheckAll":true},"markup":{"title":"Markup","alias":["html","xml","svg","mathml"],"aliasTitles":{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML"},"option":"default"},"css":{"title":"CSS","option":"default","peerDependencies":"markup"},"clike":{"title":"C-like","option":"default","overrideExampleHeader":true},"javascript":{"title":"JavaScript","require":"clike","peerDependencies":"markup","alias":"js","option":"default"},"abap":{"title":"ABAP","owner":"dellagustin"},"abnf":{"title":"Augmented Backus–Naur form","owner":"RunDevelopment"},"actionscript":{"title":"ActionScript","require":"javascript","peerDependencies":"markup","owner":"Golmote"},"ada":{"title":"Ada","owner":"Lucretia"},"apacheconf":{"title":"Apache Configuration","owner":"GuiTeK"},"apl":{"title":"APL","owner":"ngn"},"applescript":{"title":"AppleScript","owner":"Golmote"},"arduino":{"title":"Arduino","require":"cpp","owner":"eisbehr-"},"arff":{"title":"ARFF","owner":"Golmote"},"asciidoc":{"alias":"adoc","title":"AsciiDoc","owner":"Golmote"},"asm6502":{"title":"6502 Assembly","owner":"kzurawel"},"aspnet":{"title":"ASP.NET (C#)","require":["markup","csharp"],"owner":"nauzilus"},"autohotkey":{"title":"AutoHotkey","owner":"aviaryan"},"autoit":{"title":"AutoIt","owner":"Golmote"},"bash":{"title":"Bash","alias":"shell","aliasTitles":{"shell":"Shell"},"owner":"zeitgeist87"},"basic":{"title":"BASIC","owner":"Golmote"},"batch":{"title":"Batch","owner":"Golmote"},"bison":{"title":"Bison","require":"c","owner":"Golmote"},"bnf":{"title":"Backus–Naur form","alias":"rbnf","aliasTitles":{"rbnf":"Routing Backus–Naur form"},"owner":"RunDevelopment"},"brainfuck":{"title":"Brainfuck","owner":"Golmote"},"bro":{"title":"Bro","owner":"wayward710"},"c":{"title":"C","require":"clike","owner":"zeitgeist87"},"csharp":{"title":"C#","require":"clike","alias":["cs","dotnet"],"owner":"mvalipour"},"cpp":{"title":"C++","require":"c","owner":"zeitgeist87"},"cil":{"title":"CIL","owner":"sbrl"},"coffeescript":{"title":"CoffeeScript","require":"javascript","alias":"coffee","owner":"R-osey"},"cmake":{"title":"CMake","owner":"mjrogozinski"},"clojure":{"title":"Clojure","owner":"troglotit"},"crystal":{"title":"Crystal","require":"ruby","owner":"MakeNowJust"},"csp":{"title":"Content-Security-Policy","owner":"ScottHelme"},"css-extras":{"title":"CSS Extras","require":"css","owner":"milesj"},"d":{"title":"D","require":"clike","owner":"Golmote"},"dart":{"title":"Dart","require":"clike","owner":"Golmote"},"diff":{"title":"Diff","owner":"uranusjr"},"django":{"title":"Django/Jinja2","require":"markup-templating","alias":"jinja2","owner":"romanvm"},"dns-zone-file":{"title":"DNS zone file","owner":"RunDevelopment","alias":"dns-zone"},"docker":{"title":"Docker","alias":"dockerfile","owner":"JustinBeckwith"},"ebnf":{"title":"Extended Backus–Naur form","owner":"RunDevelopment"},"eiffel":{"title":"Eiffel","owner":"Conaclos"},"ejs":{"title":"EJS","require":["javascript","markup-templating"],"owner":"RunDevelopment"},"elixir":{"title":"Elixir","owner":"Golmote"},"elm":{"title":"Elm","owner":"zwilias"},"erb":{"title":"ERB","require":["ruby","markup-templating"],"owner":"Golmote"},"erlang":{"title":"Erlang","owner":"Golmote"},"fsharp":{"title":"F#","require":"clike","owner":"simonreynolds7"},"flow":{"title":"Flow","require":"javascript","owner":"Golmote"},"fortran":{"title":"Fortran","owner":"Golmote"},"gcode":{"title":"G-code","owner":"RunDevelopment"},"gedcom":{"title":"GEDCOM","owner":"Golmote"},"gherkin":{"title":"Gherkin","owner":"hason"},"git":{"title":"Git","owner":"lgiraudel"},"glsl":{"title":"GLSL","require":"clike","owner":"Golmote"},"gml":{"title":"GameMaker Language","alias":"gamemakerlanguage","require":"clike","owner":"LiarOnce"},"go":{"title":"Go","require":"clike","owner":"arnehormann"},"graphql":{"title":"GraphQL","owner":"Golmote"},"groovy":{"title":"Groovy","require":"clike","owner":"robfletcher"},"haml":{"title":"Haml","require":"ruby","peerDependencies":["css","coffeescript","erb","javascript","less","markdown","ruby","scss","textile"],"owner":"Golmote"},"handlebars":{"title":"Handlebars","require":"markup-templating","owner":"Golmote"},"haskell":{"title":"Haskell","alias":"hs","owner":"bholst"},"haxe":{"title":"Haxe","require":"clike","owner":"Golmote"},"hcl":{"title":"HCL","owner":"outsideris"},"http":{"title":"HTTP","peerDependencies":["javascript","markup"],"owner":"danielgtaylor"},"hpkp":{"title":"HTTP Public-Key-Pins","owner":"ScottHelme"},"hsts":{"title":"HTTP Strict-Transport-Security","owner":"ScottHelme"},"ichigojam":{"title":"IchigoJam","owner":"BlueCocoa"},"icon":{"title":"Icon","owner":"Golmote"},"inform7":{"title":"Inform 7","owner":"Golmote"},"ini":{"title":"Ini","owner":"aviaryan"},"io":{"title":"Io","owner":"AlesTsurko"},"j":{"title":"J","owner":"Golmote"},"java":{"title":"Java","require":"clike","owner":"sherblot"},"javadoc":{"title":"JavaDoc","require":["markup","java","javadoclike"],"peerDependencies":["scala"],"owner":"RunDevelopment"},"javadoclike":{"title":"JavaDoc-like","peerDependencies":["java","javascript","php"],"owner":"RunDevelopment"},"javastacktrace":{"title":"Java stack trace","owner":"RunDevelopment"},"jolie":{"title":"Jolie","require":"clike","owner":"thesave"},"jq":{"title":"JQ","owner":"RunDevelopment"},"jsdoc":{"title":"JSDoc","require":["javascript","javadoclike"],"peerDependencies":["actionscript","coffeescript"],"owner":"RunDevelopment"},"js-extras":{"title":"JS Extras","require":"javascript","peerDependencies":["actionscript","coffeescript","flow","n4js","typescript"],"owner":"RunDevelopment"},"json":{"title":"JSON","owner":"CupOfTea696"},"jsonp":{"title":"JSONP","require":"json","owner":"RunDevelopment"},"json5":{"title":"JSON5","require":"json","owner":"RunDevelopment"},"julia":{"title":"Julia","owner":"cdagnino"},"keyman":{"title":"Keyman","owner":"mcdurdin"},"kotlin":{"title":"Kotlin","require":"clike","owner":"Golmote"},"latex":{"title":"LaTeX","alias":["tex","context"],"aliasTitles":{"tex":"TeX","context":"ConTeXt"},"owner":"japborst"},"less":{"title":"Less","require":"css","owner":"Golmote"},"lilypond":{"title":"LilyPond","require":"scheme","alias":"ly","owner":"RunDevelopment"},"liquid":{"title":"Liquid","owner":"cinhtau"},"lisp":{"title":"Lisp","alias":["emacs","elisp","emacs-lisp"],"owner":"JuanCaicedo"},"livescript":{"title":"LiveScript","owner":"Golmote"},"lolcode":{"title":"LOLCODE","owner":"Golmote"},"lua":{"title":"Lua","owner":"Golmote"},"makefile":{"title":"Makefile","owner":"Golmote"},"markdown":{"title":"Markdown","require":"markup","alias":"md","owner":"Golmote"},"markup-templating":{"title":"Markup templating","require":"markup","owner":"Golmote"},"matlab":{"title":"MATLAB","owner":"Golmote"},"mel":{"title":"MEL","owner":"Golmote"},"mizar":{"title":"Mizar","owner":"Golmote"},"monkey":{"title":"Monkey","owner":"Golmote"},"n1ql":{"title":"N1QL","owner":"TMWilds"},"n4js":{"title":"N4JS","require":"javascript","peerDependencies":["jsdoc"],"alias":"n4jsd","owner":"bsmith-n4"},"nand2tetris-hdl":{"title":"Nand To Tetris HDL","owner":"stephanmax"},"nasm":{"title":"NASM","owner":"rbmj"},"nginx":{"title":"nginx","owner":"westonganger","require":"clike"},"nim":{"title":"Nim","owner":"Golmote"},"nix":{"title":"Nix","owner":"Golmote"},"nsis":{"title":"NSIS","owner":"idleberg"},"objectivec":{"title":"Objective-C","require":"c","owner":"uranusjr"},"ocaml":{"title":"OCaml","owner":"Golmote"},"opencl":{"title":"OpenCL","require":"cpp","peerDependencies":["c","cpp"],"overrideExampleHeader":true,"owner":"Milania1"},"oz":{"title":"Oz","owner":"Golmote"},"parigp":{"title":"PARI/GP","owner":"Golmote"},"parser":{"title":"Parser","require":"markup","owner":"Golmote"},"pascal":{"title":"Pascal","alias":"objectpascal","aliasTitles":{"objectpascal":"Object Pascal"},"owner":"Golmote"},"pascaligo":{"title":"Pascaligo","owner":"DefinitelyNotAGoat"},"pcaxis":{"title":"PC-Axis","alias":"px","owner":"RunDevelopment"},"perl":{"title":"Perl","owner":"Golmote"},"php":{"title":"PHP","require":["clike","markup-templating"],"owner":"milesj"},"phpdoc":{"title":"PHPDoc","require":["php","javadoclike"],"owner":"RunDevelopment"},"php-extras":{"title":"PHP Extras","require":"php","owner":"milesj"},"plsql":{"title":"PL/SQL","require":"sql","owner":"Golmote"},"powershell":{"title":"PowerShell","owner":"nauzilus"},"processing":{"title":"Processing","require":"clike","owner":"Golmote"},"prolog":{"title":"Prolog","owner":"Golmote"},"properties":{"title":".properties","owner":"Golmote"},"protobuf":{"title":"Protocol Buffers","require":"clike","owner":"just-boris"},"pug":{"title":"Pug","require":["markup","javascript"],"peerDependencies":["coffeescript","ejs","handlebars","less","livescript","markdown","scss","stylus","twig"],"owner":"Golmote"},"puppet":{"title":"Puppet","owner":"Golmote"},"pure":{"title":"Pure","peerDependencies":["c","cpp","fortran"],"owner":"Golmote"},"python":{"title":"Python","alias":"py","owner":"multipetros"},"q":{"title":"Q (kdb+ database)","owner":"Golmote"},"qore":{"title":"Qore","require":"clike","owner":"temnroegg"},"r":{"title":"R","owner":"Golmote"},"jsx":{"title":"React JSX","require":["markup","javascript"],"peerDependencies":["jsdoc","js-extras"],"owner":"vkbansal"},"tsx":{"title":"React TSX","require":["jsx","typescript"]},"renpy":{"title":"Ren'py","owner":"HyuchiaDiego"},"reason":{"title":"Reason","require":"clike","owner":"Golmote"},"regex":{"title":"Regex","peerDependencies":["actionscript","coffeescript","flow","javascript","typescript","vala"],"owner":"RunDevelopment"},"rest":{"title":"reST (reStructuredText)","owner":"Golmote"},"rip":{"title":"Rip","owner":"ravinggenius"},"roboconf":{"title":"Roboconf","owner":"Golmote"},"ruby":{"title":"Ruby","require":"clike","alias":"rb","owner":"samflores"},"rust":{"title":"Rust","owner":"Golmote"},"sas":{"title":"SAS","owner":"Golmote"},"sass":{"title":"Sass (Sass)","require":"css","owner":"Golmote"},"scss":{"title":"Sass (Scss)","require":"css","owner":"MoOx"},"scala":{"title":"Scala","require":"java","owner":"jozic"},"scheme":{"title":"Scheme","owner":"bacchus123"},"shell-session":{"title":"Shell session","require":"bash","owner":"RunDevelopment"},"smalltalk":{"title":"Smalltalk","owner":"Golmote"},"smarty":{"title":"Smarty","require":"markup-templating","owner":"Golmote"},"soy":{"title":"Soy (Closure Template)","require":"markup-templating","owner":"Golmote"},"splunk-spl":{"title":"Splunk SPL","owner":"RunDevelopment"},"sql":{"title":"SQL","owner":"multipetros"},"stylus":{"title":"Stylus","owner":"vkbansal"},"swift":{"title":"Swift","require":"clike","owner":"chrischares"},"tap":{"title":"TAP","owner":"isaacs","require":"yaml"},"tcl":{"title":"Tcl","owner":"PeterChaplin"},"textile":{"title":"Textile","require":"markup","peerDependencies":"css","owner":"Golmote"},"toml":{"title":"TOML","owner":"RunDevelopment"},"tt2":{"title":"Template Toolkit 2","require":["clike","markup-templating"],"owner":"gflohr"},"twig":{"title":"Twig","require":"markup","owner":"brandonkelly"},"typescript":{"title":"TypeScript","require":"javascript","alias":"ts","owner":"vkbansal"},"t4-cs":{"title":"T4 Text Templates (C#)","require":["t4-templating","csharp"],"alias":"t4","owner":"RunDevelopment"},"t4-vb":{"title":"T4 Text Templates (VB)","require":["t4-templating","visual-basic"],"owner":"RunDevelopment"},"t4-templating":{"title":"T4 templating","owner":"RunDevelopment"},"vala":{"title":"Vala","require":"clike","owner":"TemplarVolk"},"vbnet":{"title":"VB.Net","require":"basic","owner":"Bigsby"},"velocity":{"title":"Velocity","require":"markup","owner":"Golmote"},"verilog":{"title":"Verilog","owner":"a-rey"},"vhdl":{"title":"VHDL","owner":"a-rey"},"vim":{"title":"vim","owner":"westonganger"},"visual-basic":{"title":"Visual Basic","alias":"vb","owner":"Golmote"},"wasm":{"title":"WebAssembly","owner":"Golmote"},"wiki":{"title":"Wiki markup","require":"markup","owner":"Golmote"},"xeora":{"title":"Xeora","require":"markup","alias":"xeoracube","aliasTitles":{"xeoracube":"XeoraCube"},"owner":"freakmaxi"},"xojo":{"title":"Xojo (REALbasic)","owner":"Golmote"},"xquery":{"title":"XQuery","require":"markup","owner":"Golmote"},"yaml":{"title":"YAML","alias":"yml","owner":"hason"}},"plugins":{"meta":{"path":"plugins/{id}/prism-{id}","link":"plugins/{id}/"},"line-highlight":"Line Highlight","line-numbers":{"title":"Line Numbers","owner":"kuba-kubula"},"show-invisibles":{"title":"Show Invisibles","after":["autolinker","data-uri-highlight"]},"autolinker":"Autolinker","wpd":"WebPlatform Docs","custom-class":{"title":"Custom Class","owner":"dvkndn","noCSS":true},"file-highlight":{"title":"File Highlight","noCSS":true},"show-language":{"title":"Show Language","owner":"nauzilus","noCSS":true,"require":"toolbar"},"jsonp-highlight":{"title":"JSONP Highlight","noCSS":true,"owner":"nauzilus"},"highlight-keywords":{"title":"Highlight Keywords","owner":"vkbansal","noCSS":true},"remove-initial-line-feed":{"title":"Remove initial line feed","owner":"Golmote","noCSS":true},"previewers":{"title":"Previewers","owner":"Golmote"},"autoloader":{"title":"Autoloader","owner":"Golmote","noCSS":true},"keep-markup":{"title":"Keep Markup","owner":"Golmote","after":"normalize-whitespace","noCSS":true},"command-line":{"title":"Command Line","owner":"chriswells0"},"unescaped-markup":"Unescaped Markup","normalize-whitespace":{"title":"Normalize Whitespace","owner":"zeitgeist87","after":"unescaped-markup","noCSS":true},"data-uri-highlight":{"title":"Data-URI Highlight","owner":"Golmote","noCSS":true},"toolbar":{"title":"Toolbar","owner":"mAAdhaTTah"},"copy-to-clipboard":{"title":"Copy to Clipboard Button","owner":"mAAdhaTTah","require":"toolbar","noCSS":true}}}; +var components = {"core":{"meta":{"path":"components/prism-core.js","option":"mandatory"},"core":"Core"},"themes":{"meta":{"path":"themes/{id}.css","link":"index.html?theme={id}","exclusive":true},"prism":{"title":"Default","option":"default"},"prism-dark":"Dark","prism-funky":"Funky","prism-okaidia":{"title":"Okaidia","owner":"ocodia"},"prism-twilight":{"title":"Twilight","owner":"remybach"},"prism-coy":{"title":"Coy","owner":"tshedor"},"prism-solarizedlight":{"title":"Solarized Light","owner":"hectormatos2011 "},"prism-tomorrow":{"title":"Tomorrow Night","owner":"Rosey"}},"languages":{"meta":{"path":"components/prism-{id}","noCSS":true,"examplesPath":"examples/prism-{id}","addCheckAll":true},"markup":{"title":"Markup","alias":["html","xml","svg","mathml"],"aliasTitles":{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML"},"option":"default"},"css":{"title":"CSS","option":"default","peerDependencies":"markup"},"clike":{"title":"C-like","option":"default","overrideExampleHeader":true},"javascript":{"title":"JavaScript","require":"clike","peerDependencies":"markup","alias":"js","option":"default"},"abap":{"title":"ABAP","owner":"dellagustin"},"abnf":{"title":"Augmented Backus–Naur form","owner":"RunDevelopment"},"actionscript":{"title":"ActionScript","require":"javascript","peerDependencies":"markup","owner":"Golmote"},"ada":{"title":"Ada","owner":"Lucretia"},"apacheconf":{"title":"Apache Configuration","owner":"GuiTeK"},"apl":{"title":"APL","owner":"ngn"},"applescript":{"title":"AppleScript","owner":"Golmote"},"arduino":{"title":"Arduino","require":"cpp","owner":"eisbehr-"},"arff":{"title":"ARFF","owner":"Golmote"},"asciidoc":{"alias":"adoc","title":"AsciiDoc","owner":"Golmote"},"asm6502":{"title":"6502 Assembly","owner":"kzurawel"},"aspnet":{"title":"ASP.NET (C#)","require":["markup","csharp"],"owner":"nauzilus"},"autohotkey":{"title":"AutoHotkey","owner":"aviaryan"},"autoit":{"title":"AutoIt","owner":"Golmote"},"bash":{"title":"Bash","alias":"shell","aliasTitles":{"shell":"Shell"},"owner":"zeitgeist87"},"basic":{"title":"BASIC","owner":"Golmote"},"batch":{"title":"Batch","owner":"Golmote"},"bison":{"title":"Bison","require":"c","owner":"Golmote"},"bnf":{"title":"Backus–Naur form","alias":"rbnf","aliasTitles":{"rbnf":"Routing Backus–Naur form"},"owner":"RunDevelopment"},"brainfuck":{"title":"Brainfuck","owner":"Golmote"},"bro":{"title":"Bro","owner":"wayward710"},"c":{"title":"C","require":"clike","owner":"zeitgeist87"},"csharp":{"title":"C#","require":"clike","alias":["cs","dotnet"],"owner":"mvalipour"},"cpp":{"title":"C++","require":"c","owner":"zeitgeist87"},"cil":{"title":"CIL","owner":"sbrl"},"coffeescript":{"title":"CoffeeScript","require":"javascript","alias":"coffee","owner":"R-osey"},"cmake":{"title":"CMake","owner":"mjrogozinski"},"clojure":{"title":"Clojure","owner":"troglotit"},"crystal":{"title":"Crystal","require":"ruby","owner":"MakeNowJust"},"csp":{"title":"Content-Security-Policy","owner":"ScottHelme"},"css-extras":{"title":"CSS Extras","require":"css","owner":"milesj"},"d":{"title":"D","require":"clike","owner":"Golmote"},"dart":{"title":"Dart","require":"clike","owner":"Golmote"},"diff":{"title":"Diff","owner":"uranusjr"},"django":{"title":"Django/Jinja2","require":"markup-templating","alias":"jinja2","owner":"romanvm"},"dns-zone-file":{"title":"DNS zone file","owner":"RunDevelopment","alias":"dns-zone"},"docker":{"title":"Docker","alias":"dockerfile","owner":"JustinBeckwith"},"ebnf":{"title":"Extended Backus–Naur form","owner":"RunDevelopment"},"eiffel":{"title":"Eiffel","owner":"Conaclos"},"ejs":{"title":"EJS","require":["javascript","markup-templating"],"owner":"RunDevelopment"},"elixir":{"title":"Elixir","owner":"Golmote"},"elm":{"title":"Elm","owner":"zwilias"},"erb":{"title":"ERB","require":["ruby","markup-templating"],"owner":"Golmote"},"erlang":{"title":"Erlang","owner":"Golmote"},"fsharp":{"title":"F#","require":"clike","owner":"simonreynolds7"},"flow":{"title":"Flow","require":"javascript","owner":"Golmote"},"fortran":{"title":"Fortran","owner":"Golmote"},"gcode":{"title":"G-code","owner":"RunDevelopment"},"gedcom":{"title":"GEDCOM","owner":"Golmote"},"gherkin":{"title":"Gherkin","owner":"hason"},"git":{"title":"Git","owner":"lgiraudel"},"glsl":{"title":"GLSL","require":"clike","owner":"Golmote"},"gml":{"title":"GameMaker Language","alias":"gamemakerlanguage","require":"clike","owner":"LiarOnce"},"go":{"title":"Go","require":"clike","owner":"arnehormann"},"graphql":{"title":"GraphQL","owner":"Golmote"},"groovy":{"title":"Groovy","require":"clike","owner":"robfletcher"},"haml":{"title":"Haml","require":"ruby","peerDependencies":["css","coffeescript","erb","javascript","less","markdown","ruby","scss","textile"],"owner":"Golmote"},"handlebars":{"title":"Handlebars","require":"markup-templating","owner":"Golmote"},"haskell":{"title":"Haskell","alias":"hs","owner":"bholst"},"haxe":{"title":"Haxe","require":"clike","owner":"Golmote"},"hcl":{"title":"HCL","owner":"outsideris"},"http":{"title":"HTTP","peerDependencies":["javascript","markup"],"owner":"danielgtaylor"},"hpkp":{"title":"HTTP Public-Key-Pins","owner":"ScottHelme"},"hsts":{"title":"HTTP Strict-Transport-Security","owner":"ScottHelme"},"ichigojam":{"title":"IchigoJam","owner":"BlueCocoa"},"icon":{"title":"Icon","owner":"Golmote"},"inform7":{"title":"Inform 7","owner":"Golmote"},"ini":{"title":"Ini","owner":"aviaryan"},"io":{"title":"Io","owner":"AlesTsurko"},"j":{"title":"J","owner":"Golmote"},"java":{"title":"Java","require":"clike","owner":"sherblot"},"javadoc":{"title":"JavaDoc","require":["markup","java","javadoclike"],"peerDependencies":["scala"],"owner":"RunDevelopment"},"javadoclike":{"title":"JavaDoc-like","peerDependencies":["java","javascript","php"],"owner":"RunDevelopment"},"javastacktrace":{"title":"Java stack trace","owner":"RunDevelopment"},"jolie":{"title":"Jolie","require":"clike","owner":"thesave"},"jq":{"title":"JQ","owner":"RunDevelopment"},"jsdoc":{"title":"JSDoc","require":["javascript","javadoclike"],"peerDependencies":["actionscript","coffeescript"],"owner":"RunDevelopment"},"js-extras":{"title":"JS Extras","require":"javascript","peerDependencies":["actionscript","coffeescript","flow","n4js","typescript"],"owner":"RunDevelopment"},"json":{"title":"JSON","owner":"CupOfTea696"},"jsonp":{"title":"JSONP","require":"json","owner":"RunDevelopment"},"json5":{"title":"JSON5","require":"json","owner":"RunDevelopment"},"julia":{"title":"Julia","owner":"cdagnino"},"keyman":{"title":"Keyman","owner":"mcdurdin"},"kotlin":{"title":"Kotlin","require":"clike","owner":"Golmote"},"latex":{"title":"LaTeX","alias":["tex","context"],"aliasTitles":{"tex":"TeX","context":"ConTeXt"},"owner":"japborst"},"less":{"title":"Less","require":"css","owner":"Golmote"},"lilypond":{"title":"LilyPond","require":"scheme","alias":"ly","owner":"RunDevelopment"},"liquid":{"title":"Liquid","owner":"cinhtau"},"lisp":{"title":"Lisp","alias":["emacs","elisp","emacs-lisp"],"owner":"JuanCaicedo"},"livescript":{"title":"LiveScript","owner":"Golmote"},"lolcode":{"title":"LOLCODE","owner":"Golmote"},"lua":{"title":"Lua","owner":"Golmote"},"makefile":{"title":"Makefile","owner":"Golmote"},"markdown":{"title":"Markdown","require":"markup","alias":"md","owner":"Golmote"},"markup-templating":{"title":"Markup templating","require":"markup","owner":"Golmote"},"matlab":{"title":"MATLAB","owner":"Golmote"},"mel":{"title":"MEL","owner":"Golmote"},"mizar":{"title":"Mizar","owner":"Golmote"},"monkey":{"title":"Monkey","owner":"Golmote"},"n1ql":{"title":"N1QL","owner":"TMWilds"},"n4js":{"title":"N4JS","require":"javascript","peerDependencies":["jsdoc"],"alias":"n4jsd","owner":"bsmith-n4"},"nand2tetris-hdl":{"title":"Nand To Tetris HDL","owner":"stephanmax"},"nasm":{"title":"NASM","owner":"rbmj"},"nginx":{"title":"nginx","owner":"westonganger","require":"clike"},"nim":{"title":"Nim","owner":"Golmote"},"nix":{"title":"Nix","owner":"Golmote"},"nsis":{"title":"NSIS","owner":"idleberg"},"objectivec":{"title":"Objective-C","require":"c","owner":"uranusjr"},"ocaml":{"title":"OCaml","owner":"Golmote"},"opencl":{"title":"OpenCL","require":"cpp","peerDependencies":["c","cpp"],"overrideExampleHeader":true,"owner":"Milania1"},"oz":{"title":"Oz","owner":"Golmote"},"parigp":{"title":"PARI/GP","owner":"Golmote"},"parser":{"title":"Parser","require":"markup","owner":"Golmote"},"pascal":{"title":"Pascal","alias":"objectpascal","aliasTitles":{"objectpascal":"Object Pascal"},"owner":"Golmote"},"pascaligo":{"title":"Pascaligo","owner":"DefinitelyNotAGoat"},"pcaxis":{"title":"PC-Axis","alias":"px","owner":"RunDevelopment"},"perl":{"title":"Perl","owner":"Golmote"},"php":{"title":"PHP","require":["clike","markup-templating"],"owner":"milesj"},"phpdoc":{"title":"PHPDoc","require":["php","javadoclike"],"owner":"RunDevelopment"},"php-extras":{"title":"PHP Extras","require":"php","owner":"milesj"},"plsql":{"title":"PL/SQL","require":"sql","owner":"Golmote"},"powershell":{"title":"PowerShell","owner":"nauzilus"},"processing":{"title":"Processing","require":"clike","owner":"Golmote"},"prolog":{"title":"Prolog","owner":"Golmote"},"properties":{"title":".properties","owner":"Golmote"},"protobuf":{"title":"Protocol Buffers","require":"clike","owner":"just-boris"},"pug":{"title":"Pug","require":["markup","javascript"],"peerDependencies":["coffeescript","ejs","handlebars","less","livescript","markdown","scss","stylus","twig"],"owner":"Golmote"},"puppet":{"title":"Puppet","owner":"Golmote"},"pure":{"title":"Pure","peerDependencies":["c","cpp","fortran"],"owner":"Golmote"},"python":{"title":"Python","alias":"py","owner":"multipetros"},"q":{"title":"Q (kdb+ database)","owner":"Golmote"},"qore":{"title":"Qore","require":"clike","owner":"temnroegg"},"r":{"title":"R","owner":"Golmote"},"jsx":{"title":"React JSX","require":["markup","javascript"],"peerDependencies":["jsdoc","js-extras"],"owner":"vkbansal"},"tsx":{"title":"React TSX","require":["jsx","typescript"]},"renpy":{"title":"Ren'py","owner":"HyuchiaDiego"},"reason":{"title":"Reason","require":"clike","owner":"Golmote"},"regex":{"title":"Regex","peerDependencies":["actionscript","coffeescript","flow","javascript","typescript","vala"],"owner":"RunDevelopment"},"rest":{"title":"reST (reStructuredText)","owner":"Golmote"},"rip":{"title":"Rip","owner":"ravinggenius"},"roboconf":{"title":"Roboconf","owner":"Golmote"},"ruby":{"title":"Ruby","require":"clike","alias":"rb","owner":"samflores"},"rust":{"title":"Rust","owner":"Golmote"},"sas":{"title":"SAS","owner":"Golmote"},"sass":{"title":"Sass (Sass)","require":"css","owner":"Golmote"},"scss":{"title":"Sass (Scss)","require":"css","owner":"MoOx"},"scala":{"title":"Scala","require":"java","owner":"jozic"},"scheme":{"title":"Scheme","owner":"bacchus123"},"shell-session":{"title":"Shell session","require":"bash","owner":"RunDevelopment"},"smalltalk":{"title":"Smalltalk","owner":"Golmote"},"smarty":{"title":"Smarty","require":"markup-templating","owner":"Golmote"},"soy":{"title":"Soy (Closure Template)","require":"markup-templating","owner":"Golmote"},"splunk-spl":{"title":"Splunk SPL","owner":"RunDevelopment"},"sql":{"title":"SQL","owner":"multipetros"},"stylus":{"title":"Stylus","owner":"vkbansal"},"swift":{"title":"Swift","require":"clike","owner":"chrischares"},"tap":{"title":"TAP","owner":"isaacs","require":"yaml"},"tcl":{"title":"Tcl","owner":"PeterChaplin"},"textile":{"title":"Textile","require":"markup","peerDependencies":"css","owner":"Golmote"},"toml":{"title":"TOML","owner":"RunDevelopment"},"tt2":{"title":"Template Toolkit 2","require":["clike","markup-templating"],"owner":"gflohr"},"twig":{"title":"Twig","require":"markup","owner":"brandonkelly"},"typescript":{"title":"TypeScript","require":"javascript","alias":"ts","owner":"vkbansal"},"t4-cs":{"title":"T4 Text Templates (C#)","require":["t4-templating","csharp"],"alias":"t4","owner":"RunDevelopment"},"t4-vb":{"title":"T4 Text Templates (VB)","require":["t4-templating","visual-basic"],"owner":"RunDevelopment"},"t4-templating":{"title":"T4 templating","owner":"RunDevelopment"},"vala":{"title":"Vala","require":"clike","owner":"TemplarVolk"},"vbnet":{"title":"VB.Net","require":"basic","owner":"Bigsby"},"velocity":{"title":"Velocity","require":"markup","owner":"Golmote"},"verilog":{"title":"Verilog","owner":"a-rey"},"vhdl":{"title":"VHDL","owner":"a-rey"},"vim":{"title":"vim","owner":"westonganger"},"visual-basic":{"title":"Visual Basic","alias":"vb","owner":"Golmote"},"wasm":{"title":"WebAssembly","owner":"Golmote"},"wiki":{"title":"Wiki markup","require":"markup","owner":"Golmote"},"xeora":{"title":"Xeora","require":"markup","alias":"xeoracube","aliasTitles":{"xeoracube":"XeoraCube"},"owner":"freakmaxi"},"xojo":{"title":"Xojo (REALbasic)","owner":"Golmote"},"xquery":{"title":"XQuery","require":"markup","owner":"Golmote"},"yaml":{"title":"YAML","alias":"yml","owner":"hason"}},"plugins":{"meta":{"path":"plugins/{id}/prism-{id}","link":"plugins/{id}/"},"line-highlight":"Line Highlight","line-numbers":{"title":"Line Numbers","owner":"kuba-kubula"},"show-invisibles":{"title":"Show Invisibles","after":["autolinker","data-uri-highlight"]},"autolinker":"Autolinker","wpd":"WebPlatform Docs","custom-class":{"title":"Custom Class","owner":"dvkndn","noCSS":true},"file-highlight":{"title":"File Highlight","noCSS":true},"show-language":{"title":"Show Language","owner":"nauzilus","noCSS":true,"require":"toolbar"},"jsonp-highlight":{"title":"JSONP Highlight","noCSS":true,"owner":"nauzilus"},"highlight-keywords":{"title":"Highlight Keywords","owner":"vkbansal","noCSS":true},"remove-initial-line-feed":{"title":"Remove initial line feed","owner":"Golmote","noCSS":true},"previewers":{"title":"Previewers","owner":"Golmote"},"autoloader":{"title":"Autoloader","owner":"Golmote","noCSS":true},"keep-markup":{"title":"Keep Markup","owner":"Golmote","after":"normalize-whitespace","noCSS":true},"command-line":{"title":"Command Line","owner":"chriswells0"},"unescaped-markup":"Unescaped Markup","normalize-whitespace":{"title":"Normalize Whitespace","owner":"zeitgeist87","after":"unescaped-markup","noCSS":true},"data-uri-highlight":{"title":"Data-URI Highlight","owner":"Golmote","noCSS":true},"toolbar":{"title":"Toolbar","owner":"mAAdhaTTah"},"copy-to-clipboard":{"title":"Copy to Clipboard Button","owner":"mAAdhaTTah","require":"toolbar","noCSS":true},"diff-highlight":{"title":"Diff Highlight","owner":"RunDevelopment","require":"diff"}}}; if (typeof module !== 'undefined' && module.exports) { module.exports = components; } \ No newline at end of file diff --git a/components.json b/components.json index 13df40a858..ab2f253231 100644 --- a/components.json +++ b/components.json @@ -1064,6 +1064,11 @@ "owner": "mAAdhaTTah", "require": "toolbar", "noCSS": true + }, + "diff-highlight": { + "title": "Diff Highlight", + "owner": "RunDevelopment", + "require": "diff" } } } diff --git a/components/prism-diff.js b/components/prism-diff.js index 6faa0f7462..9dfc0e9153 100644 --- a/components/prism-diff.js +++ b/components/prism-diff.js @@ -18,7 +18,7 @@ * * @type {Object} */ - var prefixes = { + var PREFIXES = { 'deleted-sign': '-', 'deleted-arrow': '<', 'inserted-sign': '+', @@ -28,8 +28,8 @@ }; // add a token for each prefix - Object.keys(prefixes).forEach(function (name) { - var prefix = prefixes[name]; + Object.keys(PREFIXES).forEach(function (name) { + var prefix = PREFIXES[name]; var alias = []; if (!/^\w+$/.test(name)) { // "deleted-sign" -> "deleted" @@ -46,77 +46,9 @@ }; }); - - var LANGUAGE_REGEX = /diff-([\w-]+)/i; - var HTML_TAG = /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi; - //this will match a line plus the line break while ignoring the line breaks HTML tags may contain. - var HTML_LINE = RegExp(/(?:__|[^\r\n<])*(?:\r\n?|\n|(?:__|[^\r\n<])(?![^\r\n]))/.source.replace(/__/g, HTML_TAG.source), 'gi'); - - Prism.hooks.add('before-sanity-check', function (env) { - var lang = env.language; - if (LANGUAGE_REGEX.test(lang) && !env.grammar) { - env.grammar = Prism.languages[lang] = Prism.languages.diff; - } - }) - Prism.hooks.add('before-tokenize', function (env) { - var lang = env.language; - if (LANGUAGE_REGEX.test(lang) && !Prism.languages[lang]) { - Prism.languages[lang] = Prism.languages.diff; - } - }) - - Prism.hooks.add('wrap', function (env) { - var diffLanguage, diffGrammar; - - if (env.language !== 'diff') { - var langMatch = LANGUAGE_REGEX.exec(env.language); - if (!langMatch) { - return; // not a language specific diff - } - - diffLanguage = langMatch[1]; - diffGrammar = Prism.languages[diffLanguage]; - } - - // one of the diff tokens without any nested tokens - if (env.type in prefixes) { - /** @type {string} */ - var content = env.content.replace(HTML_TAG, ''); // remove all HTML tags - - /** @type {string} */ - var decoded = content.replace(/</g, '<').replace(/&/g, '&'); - - // remove any one-character prefix - var code = decoded.replace(/(^|[\r\n])./g, '$1'); - - // highlight, if possible - var highlighted; - if (diffGrammar) { - highlighted = Prism.highlight(code, diffGrammar, diffLanguage); - } else { - highlighted = Prism.util.encode(code); - } - - // get the HTML source of the prefix token - var prefixToken = new Prism.Token('prefix', prefixes[env.type], [/\w+/.exec(env.type)[0]]); - var prefix = Prism.Token.stringify(prefixToken, env.language); - - // add prefix - var lines = [], m; - HTML_LINE.lastIndex = 0; - while (m = HTML_LINE.exec(highlighted)) { - lines.push(prefix + m[0]); - } - if (/(?:^|[\r\n]).$/.test(decoded)) { - // because both "+a\n+" and "+a\n" will map to "a\n" after the line prefixes are removed - lines.push(prefix); - } - env.content = lines.join(''); - - if (diffGrammar) { - env.classes.push('language-' + diffLanguage); - } - } + // make prefixes available to Diff plugin + Object.defineProperty(Prism.languages.diff, 'PREFIXES', { + value: PREFIXES }); }(Prism)); diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js index a6589e8a18..708a5a1dbc 100644 --- a/components/prism-diff.min.js +++ b/components/prism-diff.min.js @@ -1 +1 @@ -!function(u){u.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]};var d={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(d).forEach(function(e){var a=d[e],n=[];/^\w+$/.test(e)||n.push(/\w+/.exec(e)[0]),"diff"===e&&n.push("bold"),u.languages.diff[e]={pattern:RegExp("^(?:["+a+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:n}});var c=/diff-([\w-]+)/i,p=/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi,h=RegExp("(?:__|[^\r\\n<])*(?:\r\\n?|\n|(?:__|[^\r\\n<])(?![^\r\\n]))".replace(/__/g,p.source),"gi");u.hooks.add("before-sanity-check",function(e){var a=e.language;c.test(a)&&!e.grammar&&(e.grammar=u.languages[a]=u.languages.diff)}),u.hooks.add("before-tokenize",function(e){var a=e.language;c.test(a)&&!u.languages[a]&&(u.languages[a]=u.languages.diff)}),u.hooks.add("wrap",function(e){var a,n;if("diff"!==e.language){var s=c.exec(e.language);if(!s)return;a=s[1],n=u.languages[a]}if(e.type in d){var g,r=e.content.replace(p,"").replace(/</g,"<").replace(/&/g,"&"),i=r.replace(/(^|[\r\n])./g,"$1");g=n?u.highlight(i,n,a):u.util.encode(i);var t,f=new u.Token("prefix",d[e.type],[/\w+/.exec(e.type)[0]]),l=u.Token.stringify(f,e.language),o=[];for(h.lastIndex=0;t=h.exec(g);)o.push(l+t[0]);/(?:^|[\r\n]).$/.test(r)&&o.push(l),e.content=o.join(""),n&&e.classes.push("language-"+a)}})}(Prism); \ No newline at end of file +!function(d){d.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m]};var r={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(r).forEach(function(e){var n=r[e],a=[];/^\w+$/.test(e)||a.push(/\w+/.exec(e)[0]),"diff"===e&&a.push("bold"),d.languages.diff[e]={pattern:RegExp("^(?:["+n+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:a}}),Object.defineProperty(d.languages.diff,"PREFIXES",{value:r})}(Prism); \ No newline at end of file diff --git a/plugins/diff-highlight/index.html b/plugins/diff-highlight/index.html new file mode 100644 index 0000000000..1ed65fc2a0 --- /dev/null +++ b/plugins/diff-highlight/index.html @@ -0,0 +1,81 @@ + + + + + + + Data-URI Highlight ▲ Prism plugins + + + + + + + + + + + + +
+
+ +

Diff Highlight

+

Highlights the code inside diff blocks.

+
+ +
+

How to use

+ +

Replace the language-diff of your code block with a language-diff-xxxx class to enable syntax highlighting for diff blocks.

+ +

Optional:
+ You can add the diff-highlight class to your code block to indicate changes using the background color of a line rather than the color of the text.
+ This is not compatible with the Funky theme.

+
+ +
+

Example

+ +

Using class="language-diff":

+ +
 function add(a, b) {
+-    return a - b;
++    return a + b;
+ }
+ +

Using class="language-diff diff-highlight":

+ +
 function add(a, b) {
+-    return a - b;
++    return a + b;
+ }
+ +

Using class="language-diff-javascript":

+ +
 function add(a, b) {
+-    return a - b;
++    return a + b;
+ }
+ +

Using class="language-diff-javascript diff-highlight":

+ +
 function add(a, b) {
+-    return a - b;
++    return a + b;
+ }
+ +
+ +
+ + + + + + + + + + + diff --git a/plugins/diff-highlight/prism-diff-highlight.css b/plugins/diff-highlight/prism-diff-highlight.css new file mode 100644 index 0000000000..0d9eb0c52b --- /dev/null +++ b/plugins/diff-highlight/prism-diff-highlight.css @@ -0,0 +1,13 @@ +pre.diff-highlight > code .token.deleted:not(.prefix), +pre > code.diff-highlight .token.deleted:not(.prefix) { + background-color: rgba(255, 0, 0, .1); + color: inherit; + display: block; +} + +pre.diff-highlight > code .token.inserted:not(.prefix), +pre > code.diff-highlight .token.inserted:not(.prefix) { + background-color: rgba(0, 255, 128, .1); + color: inherit; + display: block; +} diff --git a/plugins/diff-highlight/prism-diff-highlight.js b/plugins/diff-highlight/prism-diff-highlight.js new file mode 100644 index 0000000000..1eb62139ef --- /dev/null +++ b/plugins/diff-highlight/prism-diff-highlight.js @@ -0,0 +1,83 @@ +(function () { + + if (typeof Prism === 'undefined' || !Prism.languages['diff']) { + return; + } + + + var LANGUAGE_REGEX = /diff-([\w-]+)/i; + var HTML_TAG = /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi; + //this will match a line plus the line break while ignoring the line breaks HTML tags may contain. + var HTML_LINE = RegExp(/(?:__|[^\r\n<])*(?:\r\n?|\n|(?:__|[^\r\n<])(?![^\r\n]))/.source.replace(/__/g, HTML_TAG.source), 'gi'); + + var PREFIXES = Prism.languages.diff.PREFIXES; + + + Prism.hooks.add('before-sanity-check', function (env) { + var lang = env.language; + if (LANGUAGE_REGEX.test(lang) && !env.grammar) { + env.grammar = Prism.languages[lang] = Prism.languages['diff']; + } + }); + Prism.hooks.add('before-tokenize', function (env) { + var lang = env.language; + if (LANGUAGE_REGEX.test(lang) && !Prism.languages[lang]) { + Prism.languages[lang] = Prism.languages['diff']; + } + }); + + Prism.hooks.add('wrap', function (env) { + var diffLanguage, diffGrammar; + + if (env.language !== 'diff') { + var langMatch = LANGUAGE_REGEX.exec(env.language); + if (!langMatch) { + return; // not a language specific diff + } + + diffLanguage = langMatch[1]; + diffGrammar = Prism.languages[diffLanguage]; + } + + // one of the diff tokens without any nested tokens + if (env.type in PREFIXES) { + /** @type {string} */ + var content = env.content.replace(HTML_TAG, ''); // remove all HTML tags + + /** @type {string} */ + var decoded = content.replace(/</g, '<').replace(/&/g, '&'); + + // remove any one-character prefix + var code = decoded.replace(/(^|[\r\n])./g, '$1'); + + // highlight, if possible + var highlighted; + if (diffGrammar) { + highlighted = Prism.highlight(code, diffGrammar, diffLanguage); + } else { + highlighted = Prism.util.encode(code); + } + + // get the HTML source of the prefix token + var prefixToken = new Prism.Token('prefix', PREFIXES[env.type], [/\w+/.exec(env.type)[0]]); + var prefix = Prism.Token.stringify(prefixToken, env.language); + + // add prefix + var lines = [], m; + HTML_LINE.lastIndex = 0; + while (m = HTML_LINE.exec(highlighted)) { + lines.push(prefix + m[0]); + } + if (/(?:^|[\r\n]).$/.test(decoded)) { + // because both "+a\n+" and "+a\n" will map to "a\n" after the line prefixes are removed + lines.push(prefix); + } + env.content = lines.join(''); + + if (diffGrammar) { + env.classes.push('language-' + diffLanguage); + } + } + }); + +}()); diff --git a/plugins/diff-highlight/prism-diff-highlight.min.js b/plugins/diff-highlight/prism-diff-highlight.min.js new file mode 100644 index 0000000000..d2950347a9 --- /dev/null +++ b/plugins/diff-highlight/prism-diff-highlight.min.js @@ -0,0 +1 @@ +!function(){if("undefined"!=typeof Prism&&Prism.languages.diff){var o=/diff-([\w-]+)/i,m=/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi,c=RegExp("(?:__|[^\r\\n<])*(?:\r\\n?|\n|(?:__|[^\r\\n<])(?![^\r\\n]))".replace(/__/g,m.source),"gi"),d=Prism.languages.diff.PREFIXES;Prism.hooks.add("before-sanity-check",function(e){var a=e.language;o.test(a)&&!e.grammar&&(e.grammar=Prism.languages[a]=Prism.languages.diff)}),Prism.hooks.add("before-tokenize",function(e){var a=e.language;o.test(a)&&!Prism.languages[a]&&(Prism.languages[a]=Prism.languages.diff)}),Prism.hooks.add("wrap",function(e){var a,s;if("diff"!==e.language){var r=o.exec(e.language);if(!r)return;a=r[1],s=Prism.languages[a]}if(e.type in d){var n,i=e.content.replace(m,"").replace(/</g,"<").replace(/&/g,"&"),g=i.replace(/(^|[\r\n])./g,"$1");n=s?Prism.highlight(g,s,a):Prism.util.encode(g);var f,t=new Prism.Token("prefix",d[e.type],[/\w+/.exec(e.type)[0]]),u=Prism.Token.stringify(t,e.language),l=[];for(c.lastIndex=0;f=c.exec(n);)l.push(u+f[0]);/(?:^|[\r\n]).$/.test(i)&&l.push(u),e.content=l.join(""),s&&e.classes.push("language-"+a)}})}}(); \ No newline at end of file From b021ffef420978ce5e769fd7c66533f54fd8496a Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Sun, 21 Jul 2019 23:23:34 +0200 Subject: [PATCH 09/11] Updated examples --- examples/prism-diff.html | 8 ------- plugins/diff-highlight/index.html | 36 +++++++++++++++++-------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/examples/prism-diff.html b/examples/prism-diff.html index 46b42a9c9b..e753f7ff0f 100644 --- a/examples/prism-diff.html +++ b/examples/prism-diff.html @@ -31,11 +31,3 @@

Unified Diff

- qt: core + qt: core gui public_headers: "src/*.h" - -

Language specific Diff

-

Using the language-diff-xxxx class for your code elements will enable language specific highlighting for your diffs.

-
@@ -4,6 +4,5 @@
--    let foo = bar.baz([1, 2, 3]);
--    foo = foo + 1;
-+    const foo = bar.baz([1, 2, 3]) + 1;
-     console.log(`foo: ${foo}`);
diff --git a/plugins/diff-highlight/index.html b/plugins/diff-highlight/index.html index 1ed65fc2a0..a05ea1316d 100644 --- a/plugins/diff-highlight/index.html +++ b/plugins/diff-highlight/index.html @@ -39,31 +39,35 @@

Example

Using class="language-diff":

-
 function add(a, b) {
--    return a - b;
-+    return a + b;
- }
+
@@ -4,6 +4,5 @@
+-    let foo = bar.baz([1, 2, 3]);
+-    foo = foo + 1;
++    const foo = bar.baz([1, 2, 3]) + 1;
+     console.log(`foo: ${foo}`);

Using class="language-diff diff-highlight":

-
 function add(a, b) {
--    return a - b;
-+    return a + b;
- }
+
@@ -4,6 +4,5 @@
+-    let foo = bar.baz([1, 2, 3]);
+-    foo = foo + 1;
++    const foo = bar.baz([1, 2, 3]) + 1;
+     console.log(`foo: ${foo}`);

Using class="language-diff-javascript":

-
 function add(a, b) {
--    return a - b;
-+    return a + b;
- }
+
@@ -4,6 +4,5 @@
+-    let foo = bar.baz([1, 2, 3]);
+-    foo = foo + 1;
++    const foo = bar.baz([1, 2, 3]) + 1;
+     console.log(`foo: ${foo}`);

Using class="language-diff-javascript diff-highlight":

-
 function add(a, b) {
--    return a - b;
-+    return a + b;
- }
+
@@ -4,6 +4,5 @@
+-    let foo = bar.baz([1, 2, 3]);
+-    foo = foo + 1;
++    const foo = bar.baz([1, 2, 3]) + 1;
+     console.log(`foo: ${foo}`);
From 04f2a9ccd6dd50c441dc92ed54d8435ab6a119fd Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Sun, 21 Jul 2019 23:56:54 +0200 Subject: [PATCH 10/11] Funky fix --- plugins/diff-highlight/index.html | 3 +-- themes/prism-funky.css | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/diff-highlight/index.html b/plugins/diff-highlight/index.html index a05ea1316d..20c45e8601 100644 --- a/plugins/diff-highlight/index.html +++ b/plugins/diff-highlight/index.html @@ -30,8 +30,7 @@

How to use

Replace the language-diff of your code block with a language-diff-xxxx class to enable syntax highlighting for diff blocks.

Optional:
- You can add the diff-highlight class to your code block to indicate changes using the background color of a line rather than the color of the text.
- This is not compatible with the Funky theme.

+ You can add the diff-highlight class to your code block to indicate changes using the background color of a line rather than the color of the text.

diff --git a/themes/prism-funky.css b/themes/prism-funky.css index 55b32551e5..8671ff3750 100644 --- a/themes/prism-funky.css +++ b/themes/prism-funky.css @@ -115,3 +115,16 @@ code[class*="language-"] { .token.deleted { color: red; } + +/* Plugin styles: Diff Highlight */ +pre.diff-highlight > code .token.deleted:not(.prefix), +pre > code.diff-highlight .token.deleted:not(.prefix) { + background-color: rgba(255, 0, 0, .3) !important; + display: inline !important; +} + +pre.diff-highlight > code .token.inserted:not(.prefix), +pre > code.diff-highlight .token.inserted:not(.prefix) { + background-color: rgba(0, 255, 128, .3) !important; + display: inline !important; +} From a8756fd05aa83ffe26edb6d8549b6ccf49f67558 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Mon, 22 Jul 2019 01:18:03 +0200 Subject: [PATCH 11/11] Used specifity instead of !important --- themes/prism-funky.css | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/themes/prism-funky.css b/themes/prism-funky.css index 8671ff3750..d30d91255c 100644 --- a/themes/prism-funky.css +++ b/themes/prism-funky.css @@ -117,14 +117,14 @@ code[class*="language-"] { } /* Plugin styles: Diff Highlight */ -pre.diff-highlight > code .token.deleted:not(.prefix), -pre > code.diff-highlight .token.deleted:not(.prefix) { - background-color: rgba(255, 0, 0, .3) !important; - display: inline !important; +pre.diff-highlight.diff-highlight > code .token.deleted:not(.prefix), +pre > code.diff-highlight.diff-highlight .token.deleted:not(.prefix) { + background-color: rgba(255, 0, 0, .3); + display: inline; } -pre.diff-highlight > code .token.inserted:not(.prefix), -pre > code.diff-highlight .token.inserted:not(.prefix) { - background-color: rgba(0, 255, 128, .3) !important; - display: inline !important; +pre.diff-highlight.diff-highlight > code .token.inserted:not(.prefix), +pre > code.diff-highlight.diff-highlight .token.inserted:not(.prefix) { + background-color: rgba(0, 255, 128, .3); + display: inline; }