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

1 line
9.7 KiB
JavaScript

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).toMarkdown=e()}}(function(){return function i(a,c,l){function u(n,e){if(!c[n]){if(!a[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(f)return f(n,!0);var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}var o=c[n]={exports:{}};a[n][0].call(o.exports,function(e){var t=a[n][1][e];return u(t||e)},o,o.exports,i,a,c,l)}return c[n].exports}for(var f="function"==typeof require&&require,e=0;e<l.length;e++)u(l[e]);return u}({1:[function(e,t,n){"use strict";var a,c,l=e("./lib/md-converters"),u=e("./lib/gfm-converters"),f=e("./lib/html-parser"),d=e("collapse-whitespace"),r=["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"];function s(e){return-1!==r.indexOf(e.nodeName.toLowerCase())}var o=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"];function p(e){return-1!==o.indexOf(e.nodeName.toLowerCase())}function m(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 h(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(a,e);throw new TypeError("`filter` needs to be a string, array, or function")}function g(e,t){var n,r,o;return"left"===e?(n=t.previousSibling,r=/ $/):(n=t.nextSibling,r=/^ /),n&&(3===n.nodeType?o=r.test(n.nodeValue):1!==n.nodeType||s(n)||(o=r.test(n.textContent))),o}function v(e,t){var n="",r="";if(!s(e)){var o=/^[ \r\n\t]/.test(t),i=/[ \r\n\t]$/.test(t);o&&!g("left",e)&&(n=" "),i&&!g("right",e)&&(r=" ")}return{leading:n,trailing:r}}function N(e){var t,n=m(e);if(p(e)||/A|TH|TD/.test(e.nodeName)||!/^\s*$/i.test(n)){for(var r=0;r<c.length;r++){var o=c[r];if(h(e,o.filter)){if("function"!=typeof o.replacement)throw new TypeError("`replacement` needs to be a function that returns a string");var i=v(e,n);(i.leading||i.trailing)&&(n=n.trim()),t=i.leading+o.replacement.call(a,n,e)+i.trailing;break}}e._replacement=t}else e._replacement=""}(a=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,o=(n=e,r=(new f).parseFromString(n,"text/html"),d(r.documentElement,s),r).body,i=function(e){for(var t,n,r,o=[e],i=[];0<o.length;)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}(o);c=l.slice(0),t.gfm&&(c=u.concat(c)),t.converters&&(c=t.converters.concat(c));for(var a=i.length-1;0<=a;a--)N(i[a]);return m(o).replace(/^[\t\r\n]+|[\t\r\n\s]+$/g,"").replace(/\n\s+\n/g,"\n\n").replace(/\n{3,}/g,"\n\n")}).isBlock=s,a.isVoid=p,a.outer=function(e,t){return e.cloneNode(!1).outerHTML.replace("><",">"+t+"<")},t.exports=a},{"./lib/gfm-converters":2,"./lib/html-parser":3,"./lib/md-converters":4,"collapse-whitespace":7}],2:[function(e,t,n){"use strict";function c(e,t){var n=" ";return 0===Array.prototype.indexOf.call(t.parentNode.childNodes,t)&&(n="| "),n+e+" |"}var r=/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 c(e,t)}},{filter:"tr",replacement:function(e,t){var n="",r={left:":--",right:"--:",center:":-:"};if("THEAD"===t.parentNode.nodeName)for(var o=0;o<t.childNodes.length;o++){var i=t.childNodes[o].attributes.align,a="---";i&&(a=r[i.value]||a),n+=c(a,t.childNodes[o])}return"\n"+e+(n?"\n"+n:"")}},{filter:"table",replacement:function(e){return"\n\n"+e+"\n\n"}},{filter:["thead","tbody","tfoot"],replacement:function(e){return e}},{filter:function(e){return"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName},replacement:function(e,t){return"\n\n```\n"+t.firstChild.textContent+"\n```\n\n"}},{filter:function(e){return"PRE"===e.nodeName&&"DIV"===e.parentNode.nodeName&&r.test(e.parentNode.className)},replacement:function(e,t){return"\n\n```"+t.parentNode.className.match(r)[1]+"\n"+t.textContent+"\n```\n\n"}},{filter:function(e){return"DIV"===e.nodeName&&r.test(e.className)},replacement:function(e){return"\n\n"+e+"\n\n"}}]},{}],3:[function(n,e,t){var r="undefined"!=typeof window?window:this;e.exports=function(){var e=r.DOMParser,t=!1;try{(new e).parseFromString("","text/html")&&(t=!0)}catch(e){}return t}()?r.DOMParser:function(){var e=function(){};if("undefined"==typeof document){var t=n("jsdom");e.prototype.parseFromString=function(e){return t.jsdom(e,{features:{FetchExternalResources:[],ProcessExternalResources:!1}})}}else e.prototype.parseFromString=function(){var t=!1;try{document.implementation.createHTMLDocument("").open()}catch(e){window.ActiveXObject&&(t=!0)}return t}()?function(e){var t=new window.ActiveXObject("htmlfile");return t.designMode="on",t.open(),t.write(e),t.close(),t}:function(e){var t=document.implementation.createHTMLDocument("");return t.open(),t.write(e),t.close(),t};return e}()},{jsdom:6}],4:[function(e,t,n){"use strict";t.exports=[{filter:"p",replacement:function(e){return"\n\n"+e+"\n\n"}},{filter:"br",replacement:function(){return" \n"}},{filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,t){for(var n=t.nodeName.charAt(1),r="",o=0;o<n;o++)r+="#";return"\n\n"+r+" "+e+"\n\n"}},{filter:"hr",replacement:function(){return"\n\n* * *\n\n"}},{filter:["em","i"],replacement:function(e){return"_"+e+"_"}},{filter:["strong","b"],replacement:function(e){return"**"+e+"**"}},{filter:["u"],replacement:function(e){return"_"+e+"_"}},{filter:["del","s","strike"],replacement:function(e){return"~~"+e+"~~"}},{filter:"div",replacement:function(e){return e+"\n\n"}},{filter:function(e){var t=e.previousSibling||e.nextSibling,n="PRE"===e.parentNode.nodeName&&!t;return"CODE"===e.nodeName&&!n},replacement:function(e){return"`"+e+"`"}},{filter:function(e){return"A"===e.nodeName&&e.getAttribute("href")},replacement:function(e,t){var n=t.title?' "'+t.title+'"':"";return"["+e+"]("+t.getAttribute("href")+n+")"}},{filter:"video",replacement:function(e,t){for(var n,r=t.getAttribute("alt")||"",o=0;o<t.childNodes.length;o++)if("source"===t.childNodes[o].localName){n=t.childNodes[o].getAttribute("src");break}var i=t.title||"";return n?"![video:"+r+"]("+n+(i?' "'+i+'"':"")+")":""}},{filter:"audio",replacement:function(e,t){var n=t.getAttribute("alt")||"",r=t.getAttribute("src")||"";if(!r)for(var o=0;o<t.childNodes.length;o++)if("source"===t.childNodes[o].localName){r=t.childNodes[o].getAttribute("src");break}var i=t.title||"";return r?"![audio:"+n+"]("+r+(i?' "'+i+'"':"")+")":""}},{filter:"img",replacement:function(e,t){var n=t.alt||"",r=t.getAttribute("src")||"",o=t.title||"";return r?"!["+n+"]("+r+(o?' "'+o+'"':"")+")":""}},{filter:function(e){return"PRE"===e.nodeName&&"CODE"===e.firstChild.nodeName},replacement:function(e,t){return"\n\n "+t.firstChild.textContent.replace(/\n/g,"\n ")+"\n\n"}},{filter:"blockquote",replacement:function(e){return"\n\n"+(e=(e=(e=e.trim()).replace(/\n{3,}/g,"\n\n")).replace(/^/gm,"> "))+"\n\n"}},{filter:"li",replacement:function(e,t){e=e.replace(/^\s+/,"").replace(/\n/gm,"\n ");var n=t.parentNode,r=Array.prototype.indexOf.call(n.children,t)+1;return(/ol/i.test(n.nodeName)?r+". ":"* ")+e}},{filter:["ul","ol"],replacement:function(e,t){for(var n=[],r=0;r<t.childNodes.length;r++)n.push(t.childNodes[r]._replacement);return/li/i.test(t.parentNode.nodeName)?"\n"+n.join("\n"):"\n\n"+n.join("\n")+"\n\n"}},{filter:function(e){return this.isBlock(e)},replacement:function(e,t){return"\n\n"+this.outer(t,e)+"\n\n"}},{filter:function(){return!0},replacement:function(e,t){return this.outer(t,e)}}]},{}],5:[function(e,t,n){t.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(e,t,n){},{}],7:[function(e,t,n){"use strict";var u=e("void-elements");Object.keys(u).forEach(function(e){u[e.toUpperCase()]=1});var r={};function f(e){return!(!e||!r[e.nodeName])}function d(e){var t=e.nextSibling||e.parentNode;return e.parentNode.removeChild(e),t}function s(e,t){return e&&e.parentNode===t||"PRE"===t.nodeName?t.nextSibling||t.parentNode:t.firstChild||t.nextSibling||t.parentNode}e("block-elements").forEach(function(e){r[e.toUpperCase()]=1}),t.exports=function(e,t){if(e.firstChild&&"PRE"!==e.nodeName){"function"!=typeof t&&(t=f);for(var n,r=null,o=!1,i=null,a=s(i,e);a!==e;){if(3===a.nodeType){var c=a.data.replace(/[ \r\n\t]+/g," ");if(r&&!/ $/.test(r.data)||o||" "!==c[0]||(c=c.substr(1)),!c){a=d(a);continue}a.data=c,r=a}else{if(1!==a.nodeType){a=d(a);continue}t(a)||"BR"===a.nodeName?(r&&(r.data=r.data.replace(/ $/,"")),r=null,o=!1):(n=a)&&u[n.nodeName]&&(r=null,o=!0)}var l=s(i,a);i=a,a=l}r&&(r.data=r.data.replace(/ $/,""),r.data||d(r))}}},{"block-elements":5,"void-elements":8}],8:[function(e,t,n){t.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}},{}]},{},[1])(1)});