diff --git a/components/prism-diff.js b/components/prism-diff.js index 9dfc0e9153..7283e107ce 100644 --- a/components/prism-diff.js +++ b/components/prism-diff.js @@ -40,10 +40,17 @@ } Prism.languages.diff[name] = { - // pattern: /^(?:[_].*(?:\r\n?|\n|(?![\s\S])))+/m pattern: RegExp('^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm'), - alias: alias + alias: alias, + inside: { + 'line': { + pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/, + lookbehind: true + }, + 'prefix': /[\s\S]/ + } }; + }); // make prefixes available to Diff plugin diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js index 708a5a1dbc..8396cfa2b5 100644 --- a/components/prism-diff.min.js +++ b/components/prism-diff.min.js @@ -1 +1 @@ -!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 +!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],i=[];/^\w+$/.test(e)||i.push(/\w+/.exec(e)[0]),"diff"===e&&i.push("bold"),d.languages.diff[e]={pattern:RegExp("^(?:["+n+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:/[\s\S]/}}}),Object.defineProperty(d.languages.diff,"PREFIXES",{value:r})}(Prism); \ No newline at end of file diff --git a/tests/languages/diff/diff_feature.test b/tests/languages/diff/diff_feature.test index 4379e56d44..2dbba25c82 100644 --- a/tests/languages/diff/diff_feature.test +++ b/tests/languages/diff/diff_feature.test @@ -11,12 +11,12 @@ ---------------------------------------------------- [ - ["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"] + ["diff", [["prefix", "!"], ["line", " qt: core\r\n"]]], + ["unchanged", [["prefix", " "], ["line", " unchanged\r\n"]]], + ["deleted-sign", [["prefix", "-"], ["line", " qt: core\r\n"]]], + ["inserted-sign", [["prefix", "+"], ["line", " qt: core gui\r\n"]]], + ["deleted-arrow", [["prefix", "<"], ["line", " qt: core\r\n"]]], + ["inserted-arrow", [["prefix", ">"], ["line", " qt: core quick"]]] ] ----------------------------------------------------