Diff-Bugfix: Newlines and split paragraphs

This commit is contained in:
Tobias Hößl 2019-02-17 19:39:05 +01:00
parent 29b8a8b2ac
commit 0e6bdf9fbc
No known key found for this signature in database
GPG Key ID: 1D780C7599C2D2A2
2 changed files with 20 additions and 2 deletions

View File

@ -809,6 +809,24 @@ describe('DiffService', () => {
);
}));
it('does not like splitting paragraphs too much, but respects line breaks between paragraphs', inject(
[DiffService],
(service: DiffService) => {
const before =
'<P>Bavaria ipsum dolor sit amet oha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher. Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>',
after =
'<p>Bavaria ipsum dolor sit amet oha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher.</p>\n<p>Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.';
const diff = service.diff(before, after);
expect(diff).toBe(
'<P class="delete">Bavaria ipsum dolor sit amet oha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher. Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>' +
'<P class="insert">Bavaria ipsum dolor sit amet oha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher.</P>' +
'<INS>\n</INS>' +
'<P class="insert">Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>'
);
}
));
it('does not repeat the last word (1)', inject([DiffService], (service: DiffService) => {
const before = '<P>sem. Nulla consequat massa quis enim. </P>',
after = '<p>sem. Nulla consequat massa quis enim. TEST<br>\nTEST</p>';

View File

@ -940,8 +940,8 @@ export class DiffService {
private diffDetectBrokenDiffHtml(html: string): boolean {
// If other HTML tags are contained within INS/DEL (e.g. "<ins>Test</p></ins>"), let's better be cautious
// The "!!(found=...)"-construction is only used to make jshint happy :)
const findDel = /<del>(.*?)<\/del>/gi,
findIns = /<ins>(.*?)<\/ins>/gi;
const findDel = /<del>([\s\S]*?)<\/del>/gi,
findIns = /<ins>([\s\S]*?)<\/ins>/gi;
let found, inner;
while (!!(found = findDel.exec(html))) {
inner = found[1].replace(/<br[^>]*>/gi, '');