You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

to-markdown.min.js 8.9KB

1
  1. !function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.toMarkdown=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={"exports":{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({"1":[function(a,b,c){"use strict";function d(a){return a.replace(/^[ \r\n\t]+|[ \r\n\t]+$/g,"")}function e(a){return-1!==x.indexOf(a.nodeName.toLowerCase())}function f(a){return-1!==y.indexOf(a.nodeName.toLowerCase())}function g(){var a=w.DOMParser,b=!1;try{(new a).parseFromString("","text/html")&&(b=!0)}catch(c){}return b}function h(){var a=function(){};return a.prototype.parseFromString=function(a){var b=s.implementation.createHTMLDocument("");return a.toLowerCase().indexOf("<!doctype")>-1?b.documentElement.innerHTML=a:b.body.innerHTML=a,b},a}function i(a){var b=(new z).parseFromString(a,"text/html");return v(b,e),b}function j(a){for(var b,c,d,e=[a],f=[];e.length>0;)for(b=e.shift(),f.push(b),c=b.childNodes,d=0;d<c.length;d++)1===c[d].nodeType&&e.push(c[d]);return f.shift(),f}function k(a){for(var b="",c=0;c<a.childNodes.length;c++)if(1===a.childNodes[c].nodeType)b+=a.childNodes[c]._replacement;else{if(3!==a.childNodes[c].nodeType)continue;b+=a.childNodes[c].data}return b}function l(a,b){return a.cloneNode(!1).outerHTML.replace("><",">"+b+"<")}function m(a,b){if("string"==typeof b)return b===a.nodeName.toLowerCase();if(Array.isArray(b))return-1!==b.indexOf(a.nodeName.toLowerCase());if("function"==typeof b)return b.call(q,a);throw new TypeError("`filter` needs to be a string, array, or function")}function n(a,b){var c,d,f;return"left"===a?(c=b.previousSibling,d=/ $/):(c=b.nextSibling,d=/^ /),c&&(3===c.nodeType?f=d.test(c.nodeValue):1!==c.nodeType||e(c)||(f=d.test(c.textContent))),f}function o(a){var b="",c="";if(!e(a)){var d=/^[ \r\n\t]/.test(a.innerHTML),f=/[ \r\n\t]$/.test(a.innerHTML);d&&!n("left",a)&&(b=" "),f&&!n("right",a)&&(c=" ")}return{"leading":b,"trailing":c}}function p(a){var b,c=k(a);if(!f(a)&&!/A/.test(a.nodeName)&&/^\s*$/i.test(c))return void(a._replacement="");for(var e=0;e<r.length;e++){var g=r[e];if(m(a,g.filter)){if("function"!=typeof g.replacement)throw new TypeError("`replacement` needs to be a function that returns a string");var h=o(a);(h.leading||h.trailing)&&(c=d(c)),b=h.leading+g.replacement.call(q,c,a)+h.trailing;break}}a._replacement=b}var q,r,s,t=a("./lib/md-converters"),u=a("./lib/gfm-converters"),v=a("collapse-whitespace"),w="undefined"!=typeof window?window:this;s="undefined"==typeof document?a("jsdom").jsdom():document;var x=["address","article","aside","audio","blockquote","body","canvas","center","dd","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frameset","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","isindex","li","main","menu","nav","noframes","noscript","ol","output","p","pre","section","table","tbody","td","tfoot","th","thead","tr","ul"],y=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],z=g()?w.DOMParser:h();q=function(a,b){if(b=b||{},"string"!=typeof a)throw new TypeError(a+" is not a string");a=a.replace(/(\d+)\. /g,"$1\\. ");var c,d=i(a).body,e=j(d);r=t.slice(0),b.gfm&&(r=u.concat(r)),b.converters&&(r=b.converters.concat(r));for(var f=e.length-1;f>=0;f--)p(e[f]);return c=k(d),c.replace(/^[\t\r\n]+|[\t\r\n\s]+$/g,"").replace(/\n\s+\n/g,"\n\n").replace(/\n{3,}/g,"\n\n")},q.isBlock=e,q.isVoid=f,q.trim=d,q.outer=l,b.exports=q},{"./lib/gfm-converters":2,"./lib/md-converters":3,"collapse-whitespace":4,"jsdom":7}],"2":[function(a,b,c){"use strict";function d(a,b){var c=Array.prototype.indexOf.call(b.parentNode.childNodes,b),d=" ";return 0===c&&(d="| "),d+a+" |"}var e=/highlight highlight-(\S+)/;b.exports=[{"filter":"br","replacement":function(){return"\n"}},{"filter":["del","s","strike"],"replacement":function(a){return"~~"+a+"~~"}},{"filter":function(a){return"checkbox"===a.type&&"LI"===a.parentNode.nodeName},"replacement":function(a,b){return(b.checked?"[x]":"[ ]")+" "}},{"filter":["th","td"],"replacement":function(a,b){return d(a,b)}},{"filter":"tr","replacement":function(a,b){var c="",e={"left":":--","right":"--:","center":":-:"};if("THEAD"===b.parentNode.nodeName)for(var f=0;f<b.childNodes.length;f++){var g=b.childNodes[f].attributes.align,h="---";g&&(h=e[g.value]||h),c+=d(h,b.childNodes[f])}return"\n"+a+(c?"\n"+c:"")}},{"filter":"table","replacement":function(a){return"\n\n"+a+"\n\n"}},{"filter":["thead","tbody","tfoot"],"replacement":function(a){return a}},{"filter":function(a){return"PRE"===a.nodeName&&a.firstChild&&"CODE"===a.firstChild.nodeName},"replacement":function(a,b){return"\n\n```\n"+b.firstChild.textContent+"\n```\n\n"}},{"filter":function(a){return"PRE"===a.nodeName&&"DIV"===a.parentNode.nodeName&&e.test(a.parentNode.className)},"replacement":function(a,b){var c=b.parentNode.className.match(e)[1];return"\n\n```"+c+"\n"+b.textContent+"\n```\n\n"}},{"filter":function(a){return"DIV"===a.nodeName&&e.test(a.className)},"replacement":function(a){return"\n\n"+a+"\n\n"}}]},{}],"3":[function(a,b,c){"use strict";b.exports=[{"filter":"p","replacement":function(a){return"\n\n"+a+"\n\n"}},{"filter":"br","replacement":function(){return" \n"}},{"filter":["h1","h2","h3","h4","h5","h6"],"replacement":function(a,b){for(var c=b.nodeName.charAt(1),d="",e=0;c>e;e++)d+="#";return"\n\n"+d+" "+a+"\n\n"}},{"filter":"hr","replacement":function(){return"\n\n* * *\n\n"}},{"filter":["em","i"],"replacement":function(a){return"_"+a+"_"}},{"filter":["strong","b"],"replacement":function(a){return"**"+a+"**"}},{"filter":function(a){var b=a.previousSibling||a.nextSibling,c="PRE"===a.parentNode.nodeName&&!b;return"CODE"===a.nodeName&&!c},"replacement":function(a){return"`"+a+"`"}},{"filter":function(a){return"A"===a.nodeName&&a.getAttribute("href")},"replacement":function(a,b){var c=b.title?' "'+b.title+'"':"";return"["+a+"]("+b.getAttribute("href")+c+")"}},{"filter":"img","replacement":function(a,b){var c=b.alt||"",d=b.getAttribute("src")||"",e=b.title||"",f=e?' "'+e+'"':"";return d?"!["+c+"]("+d+f+")":""}},{"filter":function(a){return"PRE"===a.nodeName&&"CODE"===a.firstChild.nodeName},"replacement":function(a,b){return"\n\n "+b.firstChild.textContent.replace(/\n/g,"\n ")+"\n\n"}},{"filter":"blockquote","replacement":function(a){return a=this.trim(a),a=a.replace(/\n{3,}/g,"\n\n"),a=a.replace(/^/gm,"> "),"\n\n"+a+"\n\n"}},{"filter":"li","replacement":function(a,b){a=a.replace(/^\s+/,"").replace(/\n/gm,"\n ");var c="* ",d=b.parentNode,e=Array.prototype.indexOf.call(d.children,b)+1;return c=/ol/i.test(d.nodeName)?e+". ":"* ",c+a}},{"filter":["ul","ol"],"replacement":function(a,b){for(var c=[],d=0;d<b.childNodes.length;d++)c.push(b.childNodes[d]._replacement);return/li/i.test(b.parentNode.nodeName)?"\n"+c.join("\n"):"\n\n"+c.join("\n")+"\n\n"}},{"filter":function(a){return this.isBlock(a)},"replacement":function(a,b){return"\n\n"+this.outer(b,a)+"\n\n"}},{"filter":function(){return!0},"replacement":function(a,b){return this.outer(b,a)}}]},{}],"4":[function(a,b,c){"use strict";function d(a){return!(!a||!j[a.nodeName])}function e(a){return!(!a||!i[a.nodeName])}function f(a,b){if(a.firstChild&&"PRE"!==a.nodeName){"function"!=typeof b&&(b=d);for(var c=null,f=!1,i=null,j=h(i,a);j!==a;){if(3===j.nodeType){var k=j.data.replace(/[ \r\n\t]+/g," ");if(c&&!/ $/.test(c.data)||f||" "!==k[0]||(k=k.substr(1)),!k){j=g(j);continue}j.data=k,c=j}else{if(1!==j.nodeType){j=g(j);continue}b(j)||"BR"===j.nodeName?(c&&(c.data=c.data.replace(/ $/,"")),c=null,f=!1):e(j)&&(c=null,f=!0)}var l=h(i,j);i=j,j=l}c&&(c.data=c.data.replace(/ $/,""),c.data||g(c))}}function g(a){var b=a.nextSibling||a.parentNode;return a.parentNode.removeChild(a),b}function h(a,b){return a&&a.parentNode===b||"PRE"===b.nodeName?b.nextSibling||b.parentNode:b.firstChild||b.nextSibling||b.parentNode}var i=a("void-elements");Object.keys(i).forEach(function(a){i[a.toUpperCase()]=1});var j={};a("block-elements").forEach(function(a){j[a.toUpperCase()]=1}),b.exports=f},{"block-elements":5,"void-elements":6}],"5":[function(a,b,c){b.exports=["address","article","aside","audio","blockquote","canvas","dd","div","dl","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","main","nav","noscript","ol","output","p","pre","section","table","tfoot","ul","video"]},{}],"6":[function(a,b,c){b.exports={"area":!0,"base":!0,"br":!0,"col":!0,"embed":!0,"hr":!0,"img":!0,"input":!0,"keygen":!0,"link":!0,"menuitem":!0,"meta":!0,"param":!0,"source":!0,"track":!0,"wbr":!0}},{}],"7":[function(a,b,c){},{}]},{},[1])(1)});