From 3bbfc64c40ed41f2bac743ecf795e51aab1e8202 Mon Sep 17 00:00:00 2001 From: Kyle Grinstead Date: Tue, 25 Jun 2024 10:58:02 -0600 Subject: [PATCH] fix bug with unneeded
between paragraphs --- dist/html-diff.js | 6 +----- src/html-diff.ts | 11 +---------- src/index.test.ts | 13 ++++++++++++- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/dist/html-diff.js b/dist/html-diff.js index e806a2f..ecb3af8 100644 --- a/dist/html-diff.js +++ b/dist/html-diff.js @@ -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] === "

" && pos < operation2.endInNew - 1 && this.newWords[pos + 1].startsWith("

")) { - result.push("
"); - } - } else { + } else if (s !== "\xB6") { result.push(s); } } diff --git a/src/html-diff.ts b/src/html-diff.ts index 464e51f..7af7c4c 100644 --- a/src/html-diff.ts +++ b/src/html-diff.ts @@ -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] === '

' && - pos < operation.endInNew - 1 && - this.newWords[pos + 1].startsWith('

') - ) { - result.push('
'); - } - } else { + } else if (s !== '¶') { result.push(s); } } diff --git a/src/index.test.ts b/src/index.test.ts index 96bfd05..a1d03cf 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -12,6 +12,17 @@ test('works for basic example', () => { ); }); +test('does not add weird newlines', () => { + const result = HtmlDiff.create( + `

AVVITES

1. Ancient people who lived in villages near Gaza before they were largely destroyed by a Philistine invasion (Dt 2:23; Jos 13:3).

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 (2 Kgs 17:31). See Avva.

`, + `

AVVITESs

1. Ancient people who lived in villages near Gaza before they were largely destroyed by a Philistine invasion (Dt 2:23; Jos 13:3).

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 (2 Kgs 17:31). See Avva.

` + ).build(); + + expect(result).toBe( + `

AVVITESAVVITESs

1. Ancient people who lived in villages near Gaza before they were largely destroyed by a Philistine invasion (Dt 2:23; Jos 13:3).

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 (2 Kgs 17:31). See Avva.

` + ); +}); + test('works for link', () => { const result = HtmlDiff.create( `Testing Link Changes And when the link stays the same`, @@ -54,6 +65,6 @@ test('works when deleting a paragraph', () => { ).build(); expect(result).toBe( - `

one two three four five six.

seven eight nine ten
.


eleven twelve thirteen.


fourteen fifteen sixteen.

` + `

one two three four five six.

seven eight nine ten
.

eleven twelve thirteen.

fourteen fifteen sixteen.

` ); });