yavsc/Yavsc/wwwroot/js/to-markdown.min.js

1 line
9.8 KiB
JavaScript

8 years ago
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.toMarkdown=e()}}(function(){return function e(t,n,r){function o(a,c){if(!n[a]){if(!t[a]){var l="function"==typeof require&&require;if(!c&&l)return l(a,!0);if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var f=n[a]={exports:{}};t[a][0].call(f.exports,function(e){var n=t[a][1][e];return o(n?n:e)},f,f.exports,e,t,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,n){"use strict";function r(e){return-1!==b.indexOf(e.nodeName.toLowerCase())}function o(e){return-1!==y.indexOf(e.nodeName.toLowerCase())}function i(e){var t=(new v).parseFromString(e,"text/html");return N(t.documentElement,r),t}function a(e){for(var t,n,r,o=[e],i=[];o.length>0;)for(t=o.shift(),i.push(t),n=t.childNodes,r=0;r<n.length;r++)1===n[r].nodeType&&o.push(n[r]);return i.shift(),i}function c(e){for(var t="",n=0;n<e.childNodes.length;n++)if(1===e.childNodes[n].nodeType)t+=e.childNodes[n]._replacement;else{if(3!==e.childNodes[n].nodeType)continue;t+=e.childNodes[n].data}return t}function l(e,t){return e.cloneNode(!1).outerHTML.replace("><",">"+t+"<")}function u(e,t){if("string"==typeof t)return t===e.nodeName.toLowerCase();if(Array.isArray(t))return-1!==t.indexOf(e.nodeName.toLowerCase());if("function"==typeof t)return t.call(p,e);throw new TypeError("`filter` needs to be a string, array, or function")}function f(e,t){var n,o,i;return"left"===e?(n=t.previousSibling,o=/ $/):(n=t.nextSibling,o=/^ /),n&&(3===n.nodeType?i=o.test(n.nodeValue):1!==n.nodeType||r(n)||(i=o.test(n.textContent))),i}function d(e,t){var n="",o="";if(!r(e)){var i=/^[ \r\n\t]/.test(t),a=/[ \r\n\t]$/.test(t);i&&!f("left",e)&&(n=" "),a&&!f("right",e)&&(o=" ")}return{leading:n,trailing:o}}function s(e){var t,n=c(e);if(!o(e)&&!/A|TH|TD/.test(e.nodeName)&&/^\s*$/i.test(n))return void(e._replacement="");for(var r=0;r<m.length;r++){var i=m[r];if(u(e,i.filter)){if("function"!=typeof i.replacement)throw new TypeError("`replacement` needs to be a function that returns a string");var a=d(e,n);(a.leading||a.trailing)&&(n=n.trim()),t=a.leading+i.replacement.call(p,n,e)+a.trailing;break}}e._replacement=t}var p,m,h=e("./lib/md-converters"),g=e("./lib/gfm-converters"),v=e("./lib/html-parser"),N=e("collapse-whitespace"),b=["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"];p=function(e,t){if(t=t||{},"string"!=typeof e)throw new TypeError(e+" is not a string");if(""===e)return"";e=e.replace(/(\d+)\. /g,"$1\\. ");var n,r=i(e).body,o=a(r);m=h.slice(0),t.gfm&&(m=g.concat(m)),t.converters&&(m=t.converters.concat(m));for(var l=o.length-1;l>=0;l--)s(o[l]);return n=c(r),n.replace(/^[\t\r\n]+|[\t\r\n\s]+$/g,"").replace(/\n\s+\n/g,"\n\n").replace(/\n{3,}/g,"\n\n")},p.isBlock=r,p.isVoid=o,p.outer=l,t.exports=p},{"./lib/gfm-converters":2,"./lib/html-parser":3,"./lib/md-converters":4,"collapse-whitespace":7}],2:[function(e,t,n){"use strict";function r(e,t){var n=Array.prototype.indexOf.call(t.parentNode.childNodes,t),r=" ";return 0===n&&(r="| "),r+e+" |"}var o=/highlight highlight-(\S+)/;t.exports=[{filter:"br",replacement:function(){return"\n"}},{filter:["del","s","strike"],replacement:function(e){return"~~"+e+"~~"}},{filter:function(e){return"checkbox"===e.type&&"LI"===e.parentNode.nodeName},replacement:function(e,t){return(t.checked?"[x]":"[ ]")+" "}},{filter:["th","td"],replacement:function(e,t){return r(e,