markup-tools
Version:
Utility to format markup
1 lines • 4.96 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mtools=e():t.mtools=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n={};n.links=r(1),n.images=r(2),n.text=r(3);var i={};i.links=r(4),i.images=r(5);var u={};u.mentions=r(6),u.hashtags=r(7),u.links=r(8),u.images=r(9),u.template=r(10),t.exports={format:n,parse:i,build:u}},function(t,e,r){"use strict";t.exports=function(t,e){var r=e||"";try{return String(t).replace(/([^\S]|^)(((https?\:\/\/)|(www\.))(\S+))/gi,r)}catch(t){return""}}},function(t,e,r){"use strict";t.exports=function(t,e,r){var n;if(e){if(e="."==e[0]?e.substr(1):e,-1==["jpeg","jpg","png","gif","svg","bmp","tif","tiff"].indexOf(e))return"";n=new RegExp("([a-z-_0-9/:.]*.("+e+"))","gi")}else n=/([a-z\-_0-9\/\:\.]*\.(jpe?g|bmp|svg|png|gif|tif|tiff))/gi;var i=r||"";try{return String(t).replace(n,i)}catch(t){return""}}},function(t,e,r){"use strict";t.exports=function(t,e){var r=e?Math.min(Number(e),160):null,n=String(t).replace(/<[^>]+>/g,"").replace(/([a-z\-_0-9\/\:\.]*\.(jpe?g|bmp|svg|png|gif|tif|tiff))/gi,"").replace(/([^\S]|^)(((https?\:\/\/)|(www\.))(\S+))/gi,"").replace(/\r?\n|\r/g," ");if(r){var i=n.trim();return i.length>e?i.substring(0,e)+"... ":i}return n}},function(t,e,r){"use strict";t.exports=function(t,e,r){var n,i,u="raw"==r||"href"==r?r:"raw",f=e||0;return"raw"==u?(n=/([^\S]|^)(((https?\:\/\/)|(www\.))(\S+))/gi,(i=String(t).match(n))?i[f]:""):"href"==u?(n=n=/<\s*a\s+[^>]*href\s*=\s*[\"']?([^\"' >]+)[\"' >]/gi,(i=String(t).match(n))&&(i=i.map(function(t){var e=t.split('"');return e[e.length-2]})),i?i[f]:""):void 0}},function(t,e,r){"use strict";t.exports=function(t,e,r,n){var i,u,f="raw"==n||"src"==n?n:"raw";r&&(r="."==r[0]?r.substring(1):r);var o=e||0;if("raw"==f){if(r){if(-1==["jpeg","jpg","png","gif","svg","bmp","tif","tiff"].indexOf(r))return"";i=new RegExp("([a-z-_0-9/:.]*.("+r+"))","gi")}else i=/([a-z\-_0-9\/\:\.]*\.(jpe?g|bmp|svg|png|gif|tif|tiff))/gi;return(u=String(t).match(i))?u[o]:""}if("src"==f)return i=/<\s*img(?:[^>]*)src\s*=\s*([\"\']([^\"\']+))/gi,(u=String(t).match(i))&&(u=u.map(function(t){var e=t.split('"');return e[e.length-1]})),r&&(u=u.filter(t=>~t.indexOf("."+r))),u?u[o]:""}},function(t,e,r){"use strict";t.exports=function(t,e){return String(t).replace(/(^|[^a-zA-Z0-9_!#$%&*@@\/]|(^|[^a-zA-Z0-9_+~.-\/#]))[@@]([a-z][-\.a-z\d]+[a-z\d])/gi,(t,r,n,i)=>{var u=i.toLowerCase(),f=u,o=e?e.replace(/\/$/,""):"/@",a=(r||"")+(n||"");return f?a+'<a target="_blank" href="'+o+("/@"==o?"":"/")+u+'">@'+i+"</a>":a+"@"+i})}},function(t,e,r){"use strict";t.exports=function(t,e){return String(t).replace(/(^|\s)(#[-a-z\d]+)/gi,t=>{if(/#[\d]+$/.test(t))return t;var r=/^\s/.test(t)?t[0]:"",n=t.trim().substring(1).toLowerCase();return r+'<a target="_blank" href="'+(e?e.replace(/\/$/,""):"/trending")+"/"+n+' ">'+t+" </a>"})}},function(t,e,r){"use strict";t.exports=function(t,e){return String(t||"").replace(/([^\S]|^)(((https?\:\/\/)|(www\.))(\S+))/gi,function(t,r,n){var i=n.split("<")[0];i.match("^https?://")||(i="http://"+i);var u={};if(u.video=!!e,u.width=u.video&&e.width||640,u.height=u.video&&e.height||360,u.frameborder=u.video&&e.frameborder||0,u.attributes=u.video&&e.attributes||"allowfullscreen> ",!u.video)return r+'<a href="'+i+'">'+n+"</a>";var f=i.match(/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/);if(!f||11!=f[2].length)return r+'<a href="'+i+'">'+n+"</a>";var o=f[2];return o?'<iframe width="'+u.width+'" height="'+u.height+'" src="https://www.youtube.com/embed/'+o+'" frameborder="'+u.frameborder+'" '+u.attributes+"</iframe>":void 0})}},function(t,e,r){"use strict";t.exports=function(t){return String(t).replace(/([a-z\-_0-9\/\:\.]*\.(jpg|jpeg|png|gif|bmp|svg|tif|tiff)(?!["\)]))/gi,t=>'<img src="'+t+'" /><br/>')}},function(t,e,r){"use strict";t.exports=function(t,e,r){var n=r||"";return String(t||"").replace(/{{\s*(.*?)\s*}}/gi,function(t,r,i){return e[r]||n})}}])});