Bugfix: inline diff for replaced text at end of paragraph
This commit is contained in:
parent
6800f99ef0
commit
e533fbad6d
@ -857,6 +857,21 @@ describe('DiffService', () => {
|
|||||||
);
|
);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('does handle insertions at the end of a paragraph correctly', inject(
|
||||||
|
[DiffService],
|
||||||
|
(service: DiffService) => {
|
||||||
|
const before =
|
||||||
|
'<p>Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.</p>\n<p>Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>',
|
||||||
|
after =
|
||||||
|
'<p>Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.</p>\n<p>Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, NEU NEU NEU.</p>';
|
||||||
|
const diff = service.diff(before, after);
|
||||||
|
|
||||||
|
expect(diff).toBe(
|
||||||
|
'<p>Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.</p>\n<p>Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, <del>augue velit cursus nunc,</del><ins>NEU NEU NEU.</ins></p>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
it('does not break when an insertion followes a beginning tag occuring twice', inject(
|
it('does not break when an insertion followes a beginning tag occuring twice', inject(
|
||||||
[DiffService],
|
[DiffService],
|
||||||
(service: DiffService) => {
|
(service: DiffService) => {
|
||||||
|
@ -2001,6 +2001,14 @@ export class DiffService {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// <del>deleted text</P></del><ins>inserted.</P></ins> => <del>deleted tet</del><ins>inserted.</ins></P>
|
||||||
|
diffUnnormalized = diffUnnormalized.replace(
|
||||||
|
/<del>([^<]*)<\/(p|div|blockquote|li)><\/del><ins>([^<]*)<\/\2><\/ins>\s*$/gi,
|
||||||
|
(whole: string, deleted: string, tag: string, inserted: string): string => {
|
||||||
|
return '<del>' + deleted + '</del><ins>' + inserted + '</ins></' + tag + '>';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// If larger inserted HTML text contains block elements, we separate the inserted text into
|
// If larger inserted HTML text contains block elements, we separate the inserted text into
|
||||||
// inline <ins> elements and "insert"-class-based block elements.
|
// inline <ins> elements and "insert"-class-based block elements.
|
||||||
// <ins>...<div>...</div>...</ins> => <ins>...</ins><div class="insert">...</div><ins>...</ins>
|
// <ins>...<div>...</div>...</ins> => <ins>...</ins><div class="insert">...</div><ins>...</ins>
|
||||||
|
Loading…
Reference in New Issue
Block a user