You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
angular-diff/angular-diff.min.js

1 line
1.6 KiB
JavaScript

"use strict";angular.module("diff",[]).filter("diff",["$sce",function(t){function r(t){var r=t;return r=r.replace(/&/g,"&amp;"),r=r.replace(/</g,"&lt;"),r=r.replace(/>/g,"&gt;"),r=r.replace(/'/g,"&quot;")}function e(t,e){t=t.replace(/\s+$/,""),e=e.replace(/\s+$/,"");var n,l=o(""===t?[]:t.split(/\s+/),""===e?[]:e.split(/\s+/)),s="",w=t.match(/\s+/g);null===w?w=["\n"]:w.push("\n");var u=e.match(/\s+/g);if(null===u?u=["\n"]:u.push("\n"),0===l.n.length)for(n=0;n<l.o.length;n++)s+="<del>"+r(l.o[n])+w[n]+"</del>";else{if(null===l.n[0].text)for(e=0;e<l.o.length&&null===l.o[e].text;e++)s+="<del>"+r(l.o[e])+w[e]+"</del>";for(n=0;n<l.n.length;n++)if(l.n[n].text){var f="";for(e=l.n[n].row+1;e<l.o.length&&!l.o[e].text;e++)f+="<del>"+r(l.o[e])+w[e]+"</del>";s+=" "+l.n[n].text+u[n]+f}else s+="<ins>"+r(l.n[n])+u[n]+"</ins>"}return s}function o(t,r){var e,o={},n={};for(e=0;e<r.length;e++)o[r[e]]||(o[r[e]]={rows:[],o:null}),o[r[e]].rows.push(e);for(e=0;e<t.length;e++)n[t[e]]||(n[t[e]]={rows:[],n:null}),n[t[e]].rows.push(e);for(e in o)1===o[e].rows.length&&"undefined"!=typeof n[e]&&1===n[e].rows.length&&(r[o[e].rows[0]]={text:r[o[e].rows[0]],row:n[e].rows[0]},t[n[e].rows[0]]={text:t[n[e].rows[0]],row:o[e].rows[0]});for(e=0;e<r.length-1;e++)null!==r[e].text&&null===r[e+1].text&&r[e].row+1<t.length&&!t[r[e].row+1].text&&r[e+1]===t[r[e].row+1]&&(r[e+1]={text:r[e+1],row:r[e].row+1},t[r[e].row+1]={text:t[r[e].row+1],row:e+1});for(e=r.length-1;e>0;e--)r[e].text&&!r[e-1].text&&r[e].row>0&&!t[r[e].row-1].text&&r[e-1]===t[r[e].row-1]&&(r[e-1]={text:r[e-1],row:r[e].row-1},t[r[e].row-1]={text:t[r[e].row-1],row:e-1});return{o:t,n:r}}return function(r,o){return t.trustAsHtml(e(r,o))}}]);