pyfedi/app/static/js/markdown/index.min.js

2 lines
11 KiB
JavaScript
Raw Normal View History

var easyMarkdown=function(){"use strict";var t=new RegExp("^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:/\\S*)?$","i"),e=new RegExp("^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:/\\S*)?(?:jpg|gif|png)$","i");function i(t){var e=[];for(var i in t){var n=document.createElement(t[i].type);for(var l in t[i].attrs)n.setAttribute(l,t[i].attrs[l]);t[i].text&&n.appendChild(document.createTextNode(t[i].text)),e[i]=n,void 0!==t[i].childrenOf&&e[t[i].childrenOf].appendChild(n)}return e[0]}function n(t,e,i){var n=document.createElement(t);for(var l in e)n.setAttribute(l,e[l]);return i&&n.appendChild(document.createTextNode(i)),n}function l(t){for(var e,i,n=1;n<arguments.length;n+=1)for(i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}function s(t,e){return new c(t,e)}function r(i,n,r){return this.element=i,this.options=n,this.locale=l({},s.locale,s.locale[n.locale]||{}),this.buttons={header:{title:this.locale.header.title,text:"header",group:0,callback:function(t){var e,i,n=t.getSelection(),l=t.getContent();e=0===n.length?t.locale.header.description+"\n":n.text+"\n";for(var s=0,r="",o=n.start-1,a=n.start,c=l.substring(o,a);/^\s+$|^#+$/.test(c);)/^#+$/.test(c)&&(r+="#"),s+=1,c=l.substring(o-s,a-s);if(r.length>0){var d,p=l.indexOf("\n",n.start);r.length>2?(r="#",d=l.indexOf("\n",n.start-5),t.setSelection(d,p+1),t.replaceSelection("\n"+r+" "+e),i=d+3):(r+="#",d=l.indexOf("\n",n.start-(r.length+1)),t.setSelection(d,p+1),t.replaceSelection("\n"+r+" "+e),i=n.start+1)}else r="#",t.replaceSelection("\n"+r+" "+e),i=n.start+3;return t.setSelection(i,i+e.length-1),!1}},bold:{title:this.locale.bold.title,text:"bold",group:0,callback:function(t){var e,i,n=t.getSelection(),l=t.getContent();e=0===n.length?t.locale.bold.description:n.text,"**"===l.substr(n.start-2,2)&&"**"===l.substr(n.end,2)?(t.setSelection(n.start-2,n.end+2),t.replaceSelection(e),i=n.start-2):(t.replaceSelection("**"+e+"**"),i=n.start+2),t.setSelection(i,i+e.length)}},italic:{title:this.locale.italic.title,text:"italic",group:0,callback:function(t){var e,i,n=t.getSelection(),l=t.getContent();e=0===n.length?t.locale.italic.description:n.text,"_"===l.substr(n.start-1,1)&&"_"===l.substr(n.end,1)?(t.setSelection(n.start-1,n.end+1),t.replaceSelection(e),i=n.start-1):(t.replaceSelection("_"+e+"_"),i=n.start+1),t.setSelection(i,i+e.length)}},image:{title:this.locale.image.title,text:"image",group:1,callback:function(t){var i,n,l,s=t.getSelection();return i=0===s.length?t.locale.image.description:s.text,l=prompt(t.locale.image.title,"http://"),e.test(l)&&(t.replaceSelection("!["+i+"]("+l+' "'+t.locale.image.description+'")'),n=s.start+2,t.setSelection(n,n+i.length)),!1}},link:{title:this.locale.link.title,text:"link",group:1,callback:function(e){var i,n,l,s=e.getSelection();return i=0===s.length?e.locale.link.description:s.text,l=prompt(e.locale.link.title,"http://"),t.test(l)&&(e.replaceSelection("["+i+"]("+l+")"),n=s.start+1,e.setSelection(n,n+i.length)),!1}},ol:{title:this.locale.ol.title,text:"ol",group:2,callback:function(t){var e,i,n=t.getSelection();if(0===n.length)e=t.locale.ol.description,t.replaceSelection("1. "+e),i=n.start+3;else if(n.text.indexOf("\n")<0)e=n.text,t.replaceSelection("1. "+e),i=n.start+3