From d62e613891e58313122928217a22ce6a2e90366a Mon Sep 17 00:00:00 2001 From: Mehdi Date: Thu, 30 Mar 2023 17:22:54 +0300 Subject: [PATCH 1/7] feat: latex --- index.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/index.js b/index.js index 4d5542c..1632e8f 100644 --- a/index.js +++ b/index.js @@ -1265,6 +1265,29 @@ diff_match_patch.prototype.diff_prettyHtml = function(diffs) { }; +/** + * Convert a diff array into a pretty HTML report. + * @param {!Array.} diffs Array of diff tuples. + * @return {string} HTML representation. + */ +diff_match_patch.prototype.diff_latex = function(diffs) { + const latex = []; + for (let x = 0; x < diffs.length; x++) { + const op = diffs[x][0]; // Operation (insert, delete, equal) + const data = diffs[x][1]; // Text of change. + switch (op) { + case DIFF_INSERT: + latex[x] = '\\colorbox{Green}{' + data + '}'; + break; + case DIFF_DELETE: + latex[x] = '\\st{\\colorbox{RedOrange}{' + data + '}}'; + break; + } + } + return latex.join(''); +}; + + /** * Compute and return the source text (all equalities and deletions). * @param {!Array.} diffs Array of diff tuples. From 12e7e5a8e15bf93af0e0000e32eadd6355cb1f99 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Thu, 30 Mar 2023 19:11:30 +0300 Subject: [PATCH 2/7] chore: documentation --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1632e8f..bcc7a3a 100644 --- a/index.js +++ b/index.js @@ -1266,9 +1266,9 @@ diff_match_patch.prototype.diff_prettyHtml = function(diffs) { /** - * Convert a diff array into a pretty HTML report. + * Convert a diff array into a LaTeX report. * @param {!Array.} diffs Array of diff tuples. - * @return {string} HTML representation. + * @return {string} LaTeX representation. */ diff_match_patch.prototype.diff_latex = function(diffs) { const latex = []; From 1a118a751ec610bdc9a0f380da197d2206d3bf86 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Thu, 4 May 2023 12:53:36 +0300 Subject: [PATCH 3/7] fix: don't remove equal part of text --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index bcc7a3a..7a517b5 100644 --- a/index.js +++ b/index.js @@ -1282,6 +1282,9 @@ diff_match_patch.prototype.diff_latex = function(diffs) { case DIFF_DELETE: latex[x] = '\\st{\\colorbox{RedOrange}{' + data + '}}'; break; + case DIFF_EQUAL: + latex[x] = text; + break; } } return latex.join(''); From 987bc8b1c1519bc05f17d7f6a48645ec99e07cee Mon Sep 17 00:00:00 2001 From: Mehdi Date: Thu, 4 May 2023 12:59:08 +0300 Subject: [PATCH 4/7] fix: diff_latex --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7a517b5..b68e380 100644 --- a/index.js +++ b/index.js @@ -1283,7 +1283,7 @@ diff_match_patch.prototype.diff_latex = function(diffs) { latex[x] = '\\st{\\colorbox{RedOrange}{' + data + '}}'; break; case DIFF_EQUAL: - latex[x] = text; + latex[x] = data; break; } } From 043a3b758a22e8c4005c975da71037a3ee5eb817 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Thu, 4 May 2023 14:39:13 +0300 Subject: [PATCH 5/7] feat: custom diff color --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b68e380..fe8e5a6 100644 --- a/index.js +++ b/index.js @@ -1270,17 +1270,17 @@ diff_match_patch.prototype.diff_prettyHtml = function(diffs) { * @param {!Array.} diffs Array of diff tuples. * @return {string} LaTeX representation. */ -diff_match_patch.prototype.diff_latex = function(diffs) { +diff_match_patch.prototype.diff_latex = function(diffs,insertColor = 'Green', deleteColor = 'RedOrange') { const latex = []; for (let x = 0; x < diffs.length; x++) { const op = diffs[x][0]; // Operation (insert, delete, equal) const data = diffs[x][1]; // Text of change. switch (op) { case DIFF_INSERT: - latex[x] = '\\colorbox{Green}{' + data + '}'; + latex[x] = `\\colorbox{${insertColor}{${data}}`; break; case DIFF_DELETE: - latex[x] = '\\st{\\colorbox{RedOrange}{' + data + '}}'; + latex[x] = `\\st{\\colorbox{${deleteColor}}${data}}`; break; case DIFF_EQUAL: latex[x] = data; From 2c94f11ef295fd0d22a5fae8ee2df0173ff81e55 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Thu, 4 May 2023 15:00:34 +0300 Subject: [PATCH 6/7] fix: latex --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fe8e5a6..ab4e548 100644 --- a/index.js +++ b/index.js @@ -1277,10 +1277,10 @@ diff_match_patch.prototype.diff_latex = function(diffs,insertColor = 'Green', de const data = diffs[x][1]; // Text of change. switch (op) { case DIFF_INSERT: - latex[x] = `\\colorbox{${insertColor}{${data}}`; + latex[x] = '\\colorbox{' + insertColor + '}{' + data + '}'; break; case DIFF_DELETE: - latex[x] = `\\st{\\colorbox{${deleteColor}}${data}}`; + latex[x] = '\\st{\\colorbox{' + deleteColor+ '}{' + data +'}'; break; case DIFF_EQUAL: latex[x] = data; From b8894d10b6c4c8983a60b439f54b56b8320a8384 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Thu, 18 May 2023 16:15:03 +0300 Subject: [PATCH 7/7] fix: latex-underline --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ab4e548..10e4cbc 100644 --- a/index.js +++ b/index.js @@ -1280,7 +1280,7 @@ diff_match_patch.prototype.diff_latex = function(diffs,insertColor = 'Green', de latex[x] = '\\colorbox{' + insertColor + '}{' + data + '}'; break; case DIFF_DELETE: - latex[x] = '\\st{\\colorbox{' + deleteColor+ '}{' + data +'}'; + latex[x] = '\\st{\\colorbox{' + deleteColor+ '}{' + data +'}}'; break; case DIFF_EQUAL: latex[x] = data;