Skip to content

Commit

Permalink
change Diff to output <ins>, <del>
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaundry committed Aug 31, 2023
1 parent 6ed9d45 commit efda16b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/operations/Diff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ class Diff extends Operation {

for (let i = 0; i < diff.length; i++) {
if (diff[i].added) {
if (showAdded) output += "<span class='hl5'>" + Utils.escapeHtml(diff[i].value) + "</span>";
if (showAdded) output += "<ins>" + Utils.escapeHtml(diff[i].value) + "</ins>";
} else if (diff[i].removed) {
if (showRemoved) output += "<span class='hl3'>" + Utils.escapeHtml(diff[i].value) + "</span>";
if (showRemoved) output += "<del>" + Utils.escapeHtml(diff[i].value) + "</del>";
} else if (!showSubtraction) {
output += Utils.escapeHtml(diff[i].value);
}
Expand Down
1 change: 1 addition & 0 deletions src/web/stylesheets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
@import "./layout/_structure.css";

/* Operations */
@import "./operations/diff.css";
@import "./operations/json.css";
8 changes: 8 additions & 0 deletions src/web/stylesheets/operations/diff.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
del {
background-color: var(--hl3);
}

ins {
text-decoration: underline; /* shouldn't be needed, but Chromium doesn't copy to clipboard without it */
background-color: var(--hl5);
}
6 changes: 3 additions & 3 deletions tests/operations/tests/StrUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TestRegister.addTests([
{
name: "Diff, basic usage",
input: "testing23\n\ntesting123",
expectedOutput: "testing<span class='hl5'>1</span>23",
expectedOutput: "testing<ins>1</ins>23",
recipeConfig: [
{
"op": "Diff",
Expand All @@ -22,7 +22,7 @@ TestRegister.addTests([
{
name: "Diff added with subtraction, basic usage",
input: "testing23\n\ntesting123",
expectedOutput: "<span class='hl5'>1</span>",
expectedOutput: "<ins>1</ins>",
recipeConfig: [
{
"op": "Diff",
Expand All @@ -33,7 +33,7 @@ TestRegister.addTests([
{
name: "Diff removed with subtraction, basic usage",
input: "testing123\n\ntesting3",
expectedOutput: "<span class='hl3'>12</span>",
expectedOutput: "<del>12</del>",
recipeConfig: [
{
"op": "Diff",
Expand Down

0 comments on commit efda16b

Please sign in to comment.