Highlight the differences between the two lines

If I have two long lines, VARCHAR2s, there is a simple method or algorithm that I can copy or transfer to PL / SQL to compare them by inserting markup (i.e. so that differences are highlighted when rendering on a web page).

For instance:

BEGIN DBMS_OUTPUT.put_line( markup_differences (in_old => 'Hello world, this is your captain speaking.' ,in_new => 'Hello WORLD, this is not your captain.' ,in_preins => '<ins>' ,in_postins => '</ins>' ,in_predel => '<del>' ,in_postdel => '</del>' )); END; 

Expected Result:

 Hello <del>world</del><ins>WORLD</ins>, this is <ins>not</ins> your captain <del>speaking</del>. 

Note that this indicates that the β€œworld” was changed to β€œWORLD”, that β€œnot” was inserted, and that the β€œspeaker” was deleted.

Background: My intention is to compare two basically similar snippets of HTML and mark them with highlights for display in the browser. Performance will not be a priority. This is for a one-time application, so I'm not after the perfect solution. Even if something hurts me, it will be better than nothing, and I have not promised anything to the client :)

Alternatively, a simple Javascript solution that I can easily incorporate into an Apex application might be acceptable.

+4
source share
1 answer

There is a really simple js-diff algorithm on the John Resigs blog: http://ejohn.org/projects/javascript-diff-algorithm/

Maybe this helps.

+2
source

Source: https://habr.com/ru/post/1435175/


All Articles