gosora/pubnot/trumbowyg/plugins/cleanpaste/trumbowyg.cleanpaste.min.js

1 line
1.7 KiB
JavaScript
Raw Normal View History

!function(r){"use strict";function e(r){for(var e="",t=r.length-1;t>=0;t-=1)e+=r.charAt(t);return e}function t(r){var e=r;return e=e.replace(/<[^> ]*/g,function(r){return r.toLowerCase()}),e=e.replace(/<[^>]*>/g,function(r){return r=r.replace(/ [^=]+=/g,function(r){return r.toLowerCase()})}),e=e.replace(/<[^>]*>/g,function(r){return r=r.replace(/( [^=]+=)([^"][^ >]*)/g,'$1"$2"')})}function n(r,n){var a,c,i,l="",s="";for(a=0;n.charAt(a)===r.charAt(a);a+=1)l+=n.charAt(a);for(var u=a;u>=0;u-=1){if("<"===r.charAt(u)){a=u,l=r.substring(0,a);break}if(">"===r.charAt(u))break}for(n=e(n),r=e(r),c=0;n.charAt(c)===r.charAt(c);c+=1)s+=n.charAt(c);for(var g=c;g>=0;g-=1){if(">"===r.charAt(g)){c=g,s=r.substring(0,c);break}if("<"===r.charAt(g))break}if(s=e(s),a===n.length-c)return!1;for(n=e(n),i=n.substring(a,n.length-c),i=t(i),i=i.replace(/<b(\s+|>)/g,"<strong$1"),i=i.replace(/<\/b(\s+|>)/g,"</strong$1"),i=i.replace(/<i(\s+|>)/g,"<em$1"),i=i.replace(/<\/i(\s+|>)/g,"</em$1"),i=i.replace(/<!(?:--[\s\S]*?--\s*)?>\s*/g,""),i=i.replace(/&nbsp;/gi," "),i=i.replace(/ <\//gi,"</");-1!==i.indexOf(" ");){var o=i.split(" ");i=o.join(" ")}return i=i.replace(/^\s*|\s*$/g,""),i=i.replace(/<[^>]*>/g,function(r){return r=r.replace(/ ([^=]+)="[^"]*"/g,function(r,e){return-1!==["alt","href","src","title"].indexOf(e)?r:""})}),i=i.replace(/<\?xml[^>]*>/g,""),i=i.replace(/<[^ >]+:[^>]*>/g,""),i=i.replace(/<\/[^ >]+:[^>]*>/g,""),i=i.replace(/<(div|span|style|meta|link){1}.*?>/gi,""),n=l+i+s}r.extend(!0,r.trumbowyg,{plugins:{cleanPaste:{init:function(r){r.pasteHandlers.push(function(){try{var e=r.$ed.html();setTimeout(function(){var t=r.$ed.html();t=n(e,t),r.$ed.html(t)},0)}catch(t){}})}}}})}(jQuery);