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

fix bug with unneeded <br> between paragraphs #10

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions dist/html-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,7 @@ class HtmlDiff {
const s = this.newWords[pos];
if (this.config.isIsolatedDiffTagPlaceholder(s) && this.newIsolatedDiffTags[pos]) {
result.push(this.diffIsolatedPlaceholder(operation2, pos, s));
} else if (s === "\xB6") {
if (pos > operation2.startInNew && this.newWords[pos - 1] === "</p>" && pos < operation2.endInNew - 1 && this.newWords[pos + 1].startsWith("<p>")) {
result.push("<br>");
}
} else {
} else if (s !== "\xB6") {
result.push(s);
}
}
Expand Down
11 changes: 1 addition & 10 deletions src/html-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,7 @@ export default class HtmlDiff {
const s = this.newWords[pos];
if (this.config.isIsolatedDiffTagPlaceholder(s) && this.newIsolatedDiffTags[pos]) {
result.push(this.diffIsolatedPlaceholder(operation, pos, s));
} else if (s === '¶') {
if (
pos > operation.startInNew &&
this.newWords[pos - 1] === '</p>' &&
pos < operation.endInNew - 1 &&
this.newWords[pos + 1].startsWith('<p>')
) {
result.push('<br>');
}
} else {
} else if (s !== '¶') {
result.push(s);
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ test('works for basic example', () => {
);
});

test('does not add weird newlines', () => {
const result = HtmlDiff.create(
`<h1>AVVITES</h1><p>1. Ancient people who lived in villages near Gaza before they were largely destroyed by a Philistine invasion (<span id="bibleref-5f2e22f9-25cc-4a3c-ab3a-df6da89c9bb7" data-bntype="bibleReference" data-startverse="1005002023" data-endverse="1005002023" style="color: green" onclick="onBibleReferenceClick('bibleref-5f2e22f9-25cc-4a3c-ab3a-df6da89c9bb7', '1005002023', '1005002023')">Dt 2:23</span>; <span id="bibleref-c0f7ab39-675f-45f6-8a3d-8509920adf64" data-bntype="bibleReference" data-startverse="1006013003" data-endverse="1006013003" style="color: green" onclick="onBibleReferenceClick('bibleref-c0f7ab39-675f-45f6-8a3d-8509920adf64', '1006013003', '1006013003')">Jos 13:3</span>).</p><p>2. Designation for the inhabitants of the Syrian district of Avva who were relocated by Shalmaneser of Assyria in Samaria after its conquest in 722 BC (<span id="bibleref-80211c41-a973-4a19-b9ad-a7396374e778" data-bntype="bibleReference" data-startverse="1012017031" data-endverse="1012017031" style="color: green" onclick="onBibleReferenceClick('bibleref-80211c41-a973-4a19-b9ad-a7396374e778', '1012017031', '1012017031')">2&nbsp;Kgs 17:31</span>). <em>See</em> <span data-bntype="resourceReference" data-resourceid="3057" data-resourcetype="tyndaleBibleDictionary" style="color: blue">Avva</span>.</p>`,
`<h1>AVVITESs</h1><p>1. Ancient people who lived in villages near Gaza before they were largely destroyed by a Philistine invasion (<span id="bibleref-4101396f-1723-49c3-bf5b-b7d81c0f5cf0" data-bntype="bibleReference" data-startverse="1005002023" data-endverse="1005002023" style="color: green" onclick="onBibleReferenceClick('bibleref-4101396f-1723-49c3-bf5b-b7d81c0f5cf0', '1005002023', '1005002023')">Dt 2:23</span>; <span id="bibleref-d5c2d5d6-f199-407c-98a2-594af0a3e8d7" data-bntype="bibleReference" data-startverse="1006013003" data-endverse="1006013003" style="color: green" onclick="onBibleReferenceClick('bibleref-d5c2d5d6-f199-407c-98a2-594af0a3e8d7', '1006013003', '1006013003')">Jos 13:3</span>).</p><p>2. Designation for the inhabitants of the Syrian district of Avva who were relocated by Shalmaneser of Assyria in Samaria after its conquest in 722 BC (<span id="bibleref-c4ea9367-7db6-44de-bf42-35a8e751cb26" data-bntype="bibleReference" data-startverse="1012017031" data-endverse="1012017031" style="color: green" onclick="onBibleReferenceClick('bibleref-c4ea9367-7db6-44de-bf42-35a8e751cb26', '1012017031', '1012017031')">2&nbsp;Kgs 17:31</span>). <em>See</em> <span data-bntype="resourceReference" data-resourceid="3057" data-resourcetype="tyndaleBibleDictionary" style="color: blue">Avva</span>.</p>`
).build();

expect(result).toBe(
`<h1><del class="diffmod">AVVITES</del><ins class="diffmod">AVVITESs</ins></h1><p>1. Ancient people who lived in villages near Gaza before they were largely destroyed by a Philistine invasion (<span id="bibleref-4101396f-1723-49c3-bf5b-b7d81c0f5cf0" data-bntype="bibleReference" data-startverse="1005002023" data-endverse="1005002023" style="color: green" onclick="onBibleReferenceClick('bibleref-4101396f-1723-49c3-bf5b-b7d81c0f5cf0', '1005002023', '1005002023')">Dt 2:23</span>; <span id="bibleref-d5c2d5d6-f199-407c-98a2-594af0a3e8d7" data-bntype="bibleReference" data-startverse="1006013003" data-endverse="1006013003" style="color: green" onclick="onBibleReferenceClick('bibleref-d5c2d5d6-f199-407c-98a2-594af0a3e8d7', '1006013003', '1006013003')">Jos 13:3</span>).</p><p>2. Designation for the inhabitants of the Syrian district of Avva who were relocated by Shalmaneser of Assyria in Samaria after its conquest in 722 BC (<span id="bibleref-c4ea9367-7db6-44de-bf42-35a8e751cb26" data-bntype="bibleReference" data-startverse="1012017031" data-endverse="1012017031" style="color: green" onclick="onBibleReferenceClick('bibleref-c4ea9367-7db6-44de-bf42-35a8e751cb26', '1012017031', '1012017031')">2&nbsp;Kgs 17:31</span>). <em>See</em> <span data-bntype="resourceReference" data-resourceid="3057" data-resourcetype="tyndaleBibleDictionary" style="color: blue">Avva</span>.</p>`
);
});

test('works for link', () => {
const result = HtmlDiff.create(
`Testing <a href="http://google.com">Link Changes</a> And when the link <a href="http://samelink.com">stays the same</a>`,
Expand Down Expand Up @@ -54,6 +65,6 @@ test('works when deleting a paragraph', () => {
).build();

expect(result).toBe(
`<p>one two three four five six<del class=\"diffdel\">.<br><br>seven eight nine ten</del>.</p><br><p>eleven twelve thirteen.</p><br><p>fourteen fifteen sixteen.</p>`
`<p>one two three four five six<del class=\"diffdel\">.<br><br>seven eight nine ten</del>.</p><p>eleven twelve thirteen.</p><p>fourteen fifteen sixteen.</p>`
);
});
Loading