1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["to-mark"]=t():e.toMark=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([function(e,t,n){"use strict";var r=n(1),o=/\n$/g,i=/[ \xA0]+\n\n/g,a=/([ \xA0]+\n){2,}/g,u=/href\=\"(.*?)\"/,c=/^/gm,s=r.factory({TEXT_NODE:function(e){var t=this.trim(this.getSpaceCollapsedText(e.nodeValue));return this._isNeedEscapeBackSlash(t)&&(t=this.escapeTextBackSlash(t)),t=this.escapePairedCharacters(t),this._isNeedEscapeHtml(t)&&(t=this.escapeTextHtml(t)),this._isNeedEscape(t)&&(t=this.escapeText(t)),this.getSpaceControlled(t,e)},"CODE TEXT_NODE":function(e){return e.nodeValue},"EM, I":function(e,t){var n="";return this.isEmptyText(t)||(n="*"+t+"*"),n},"STRONG, B":function(e,t){var n="";return this.isEmptyText(t)||(n="**"+t+"**"),n},A:function(e,t){var n,r,o=t,i="";return n=u.exec(e.outerHTML),n&&(r=n[1].replace(/&/g,"&")),e.title&&(i=' "'+e.title+'"'),!this.isEmptyText(t)&&r&&(o="["+this.escapeTextForLink(t)+"]("+r+i+")"),o},IMG:function(e){var t="",n=e.getAttribute("src"),r=e.alt;return n&&(t="!["+this.escapeTextForLink(r)+"]("+n+")"),t},BR:function(){return" \n"},CODE:function(e,t){var n,r,o="";return this.isEmptyText(t)||(r=parseInt(e.getAttribute("data-backticks"),10),n=isNaN(r)?"`":Array(r+1).join("`"),o=n+t+n),o},P:function(e,t){var n="";return t=t.replace(a," \n"),this.isEmptyText(t)||(n="\n\n"+t+"\n\n"),n},"BLOCKQUOTE P":function(e,t){return t},"LI P":function(e,t){var n="";return this.isEmptyText(t)||(n=t),n},"H1, H2, H3, H4, H5, H6":function(e,t){for(var n="",r=parseInt(e.tagName.charAt(1),10);r;)n+="#",r-=1;return n+=" ",n+=t,"\n\n"+n+"\n\n"},"LI H1, LI H2, LI H3, LI H4, LI H5, LI H6":function(e,t){var n=parseInt(e.tagName.charAt(1),10);return Array(n+1).join("#")+" "+t},"UL, OL":function(e,t){return"\n\n"+t+"\n\n"},"LI OL, LI UL":function(e,t){var n,r;return r=t.replace(i,"\n"),r=r.replace(o,""),n=r.replace(c," "),"\n"+n},"UL LI":function(e,t){var n="";return t=t.replace(a," \n"),e.firstChild&&"P"===e.firstChild.tagName&&(n+="\n"),n+="* "+t+"\n"},"OL LI":function(e,t){for(var n="",r=parseInt(e.parentNode.getAttribute("start")||1,10);e.previousSibling;)e=e.previousSibling,1===e.nodeType&&"LI"===e.tagName&&(r+=1);return t=t.replace(a," \n"),e.firstChild&&"P"===e.firstChild.tagName&&(n+="\n"),n+=r+". "+t+"\n"},HR:function(){return"\n\n- - -\n\n"},BLOCKQUOTE:function(e,t){var n,r;return t=t.replace(a,"\n\n"),r=this.trim(t),n=r.replace(c,"> "),"\n\n"+n+"\n\n"},"PRE CODE":function(e,t){var n,r;return r=t.replace(o,""),n=r.replace(c," "),"\n\n"+n+"\n\n"}});e.exports=s},function(e,t,n){"use strict";function r(e,t,n){var r;n=n||null;for(r in e)if(e.hasOwnProperty(r)&&t.call(n,e[r],r,e)===!1)break}function o(e){this.rules={},e&&this.addRules(e)}function i(e){var t=e.tagName;return"S"===t||"B"===t||"I"===t||"EM"===t||"STRONG"===t||"A"===t||"IMG"===t||"CODE"===t}function a(e,t){var n=e.cloneNode(!1);return n.innerHTML=t,n.outerHTML}function u(e,t){r(t,function(t,n){"converter"!==n?(e[n]||(e[n]={}),u(e[n],t)):e[n]=t})}var c=/^\u0020/,s=/.+\u0020$/,p=/[\n\s\t]+/g,l=/^[\u0020\r\n\t]+|[\u0020\r\n\t]+$/g,f=/[\u0020]+/g,d=/[>(){}\[\]+-.!#|]/g,h=/[\[\]]/g,g=/!\[.*\]\(.*\)/g,x=3;o.prototype.lineFeedReplacement="",o.prototype.addRule=function(e,t){var n=e.split(", "),r=n.pop();for(t.fname=e;r;)this._setConverterWithSelector(r,t),r=n.pop()},o.prototype.addRules=function(e){r(e,function(e,t){this.addRule(t,e)},this)},o.prototype.getSpaceControlled=function(e,t){var n,r="",o="";return t.previousSibling&&(t.previousSibling.nodeType===x||i(t.previousSibling))&&(n=t.previousSibling.innerHTML||t.previousSibling.nodeValue,(s.test(n)||c.test(t.innerHTML||t.nodeValue))&&(r=" ")),t.nextSibling&&(t.nextSibling.nodeType===x||i(t.nextSibling))&&(n=t.nextSibling.innerHTML||t.nextSibling.nodeValue,(c.test(n)||s.test(t.innerHTML||t.nodeValue))&&(o=" ")),r+e+o},o.prototype.convert=function(e,t){var n,r=this._getConverter(e);return e&&e.nodeType===Node.ELEMENT_NODE&&e.hasAttribute("data-tomark-pass")?(e.removeAttribute("data-tomark-pass"),n=a(e,t)):r?n=r.call(this,e,t):e&&(n=this.getSpaceControlled(this._getInlineHtml(e,t),e)),n||""},o.prototype._getInlineHtml=function(e,t){var n=e.outerHTML,r=e.tagName,o=t.replace(/\$/g,"$$$$");return n.replace(new RegExp("(<"+r+" ?.*?>).*(</"+r+">)","i"),"$1"+o+"$2")},o.prototype._getConverter=function(e){for(var t,n=this.rules;e&&n;)n=this._getNextRule(n,this._getRuleNameFromNode(e)),e=this._getPrevNode(e),n&&n.converter&&(t=n.converter);return t},o.prototype._getNextRule=function(e,t){return e[t]},o.prototype._getRuleNameFromNode=function(e){return e.tagName||"TEXT_NODE"},o.prototype._getPrevNode=function(e){var t,n=e.parentNode;return n&&!n.__htmlRootByToMark&&(t=n),t},o.prototype._setConverterWithSelector=function(e,t){var n=this.rules;this._eachSelector(e,function(e){n[e]||(n[e]={}),n=n[e]}),n.converter=t},o.prototype._eachSelector=function(e,t){var n,r;for(n=e.split(" "),r=n.length-1;r>=0;)t(n[r]),r-=1},o.prototype.trim=function(e){return e.replace(l,"")},o.prototype.isEmptyText=function(e){return""===e.replace(p,"")},o.prototype.getSpaceCollapsedText=function(e){return e.replace(f," ")},o.prototype.escapeText=function(e){return e.replace(d,function(e){return"\\"+e})},o.prototype.escapeTextForLink=function(e){for(var t=[],n=g.exec(e);n;)t.push([n.index,n.index+n[0].length]),n=g.exec(e);return e.replace(h,function(e,n){var r=t.some(function(e){return n>e[0]&&n<e[1]});return r?e:"\\"+e})},o.prototype.escapeTextHtml=function(e){return e.replace(new RegExp(o.markdownTextToEscapeHtmlRx.source,"g"),function(e){return"\\"+e})},o.prototype.escapeTextBackSlash=function(e){return e.replace(new RegExp(o.markdownTextToEscapeBackSlashRx.source,"g"),function(e){return"\\"+e})},o.prototype.escapePairedCharacters=function(e){return e.replace(new RegExp(o.markdownTextToEscapePairedCharsRx.source,"g"),function(e){return"\\"+e})},o.markdownTextToEscapeRx={codeblock:/(^ {4}[^\n]+\n*)+/,hr:/^ *((\* *){3,}|(- *){3,} *|(_ *){3,}) */,heading:/^(#{1,6}) +[\s\S]+/,lheading:/^([^\n]+)\n *(=|-){2,} */,blockquote:/^( *>[^\n]+.*)+/,list:/^ *(\*+|-+|\d+\.) [\s\S]+/,def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? */,link:/!?\[.*\]\(.*\)/,reflink:/!?\[.*\]\s*\[([^\]]*)\]/,verticalBar:/\u007C/,codeblockGfm:/^(`{3,})/,codeblockTildes:/^(~{3,})/},o.markdownTextToEscapeHtmlRx=/<([a-zA-Z_][a-zA-Z0-9\-\._]*)(\s|[^\\\/>])*\/?>|<(\/)([a-zA-Z_][a-zA-Z0-9\-\._]*)\s*\/?>|<!--[^-]+-->|<([a-zA-Z_][a-zA-Z0-9\-\.:\/]*)>/,o.markdownTextToEscapeBackSlashRx=/\\[!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~\\]/,o.markdownTextToEscapePairedCharsRx=/[*_~`]/,o.prototype._isNeedEscape=function(e){var t,n=!1,r=o.markdownTextToEscapeRx;for(t in r)if(r.hasOwnProperty(t)&&r[t].test(e)){n=!0;break}return n},o.prototype._isNeedEscapeHtml=function(e){return o.markdownTextToEscapeHtmlRx.test(e)},o.prototype._isNeedEscapeBackSlash=function(e){return o.markdownTextToEscapeBackSlashRx.test(e)},o.prototype.mix=function(e){u(this.rules,e.rules)},o.factory=function(e,t){var n=new o;return t?n.mix(e):t=e,n.addRules(t),n},e.exports=o},function(e,t,n){"use strict";function r(e,t){var n;return e.className.indexOf("task-list-item")!==-1&&(n=e.className.indexOf("checked")!==-1?"x":" ",t="["+n+"] "+t),t}function o(e){var t,n,r,o;return t=e.align,o=e.textContent?e.textContent.length:e.innerText.length,n="",r="",t&&("left"===t?(n=":",o-=1):"right"===t?(r=":",o-=1):"center"===t&&(r=":",n=":",o-=2)),n+a("-",o)+r}function i(e,t){var n,r=e.childNodes,o=r.length,i=[];for(n=0;n<o;n+=1)r[n].tagName&&r[n].tagName===t&&i.push(r[n]);return i}function a(e,t){var n=e;for(t=Math.max(t,3);t>1;)n+=e,t-=1;return n}var u=n(1),c=n(0),s=u.factory(c,{"DEL, S":function(e,t){return"~~"+t+"~~"},"PRE CODE":function(e,t){var n,r="",o=e.getAttribute("data-backticks");return e.getAttribute("data-language")&&(r=" "+e.getAttribute("data-language")),o=parseInt(o,10),n=isNaN(o)?"```":Array(o+1).join("`"),t=t.replace(/(\r\n)|(\r)|(\n)/g,this.lineFeedReplacement),"\n\n"+n+r+"\n"+t+"\n"+n+"\n\n"},PRE:function(e,t){return t},"UL LI":function(e,t){return c.convert(e,r(e,t))},"OL LI":function(e,t){return c.convert(e,r(e,t))},TABLE:function(e,t){return"\n\n"+t+"\n\n"},"TBODY, TFOOT":function(e,t){return t},"TR TD, TR TH":function(e,t){return t=t.replace(/(\r\n)|(\r)|(\n)/g,"")," "+t+" |"},"TD BR, TH BR":function(){return"<br>"},TR:function(e,t){return"|"+t+"\n"},THEAD:function(e,t){var n,r,a,u="";for(r=i(i(e,"TR")[0],"TH"),a=r.length,n=0;n<a;n+=1)u+=" "+o(r[n])+" |";return t?t+"|"+u+"\n":""}});e.exports=s},function(e,t,n){"use strict";var r=n(4),o=n(1),i=n(0),a=n(2);r.Renderer=o,r.basicRenderer=i,r.gfmRenderer=a,e.exports=r},function(e,t,n){"use strict";function r(e,t){var n,r,a=!0;return e?(r=p,t&&(a=t.gfm,a===!1&&(r=s),r=t.renderer||r),n=new u(c(e)),i(o(n,r),a,r.lineFeedReplacement)):""}function o(e,t){for(var n="";e.next();)n+=a(e,t);return n}function i(e,t,n){return e=e.replace(l,"\n"),e=e.replace(d,"\n\n"),e=e.replace(g,function(e){var t=(e.match(/\n/g)||[]).length;return t>=3?"\n\n":e>=1?"\n":e}),e=e.replace(f,""),e=e.replace(new RegExp(n,"g"),"\n"),t&&(e=e.replace(h,"\n")),e}function a(e,t){var n,r,o,i="",u=e.getNode();for(n=0,r=u.childNodes.length;n<r;n+=1)e.next(),i+=a(e,t);return o=t.convert(u,i)}var u=n(5),c=n(6),s=n(0),p=n(2),l=/[ \xA0]+(\n\n)/g,f=/^[\n]+|[\s\n]+$/g,d=/([ \xA0]+\n){2,}/g,h=/([ \xA0]){2,}\n/g,g=/[ \xA0\n]+/g;e.exports=r},function(e,t,n){"use strict";function r(e){this._normalizeTextChildren(e),this._root=e,this._current=e}var o={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3};r.prototype.next=function(){var e,t=this._current;if(this._current){for(e=this._getNextNode(t);this._isNeedNextSearch(e,t);)t=t.parentNode,e=t.nextSibling;this._current=e}return this._current},r.prototype.getNode=function(){return this._normalizeTextChildren(this._current),this._current},r.prototype._normalizeTextChildren=function(e){var t,n;if(e&&!(e.childNodes.length<2))for(t=e.firstChild;t.nextSibling;)n=t.nextSibling,t.nodeType===o.TEXT_NODE&&n.nodeType===o.TEXT_NODE?(t.nodeValue+=n.nodeValue,e.removeChild(n)):t=n},r.prototype.getNodeText=function(){var e,t=this.getNode();return e=t.nodeType===o.TEXT_NODE?t.nodeValue:t.textContent||t.innerText},r.prototype._isNeedNextSearch=function(e,t){return!e&&t!==this._root&&t.parentNode!==this._root},r.prototype._getNextNode=function(e){return e.firstChild||e.nextSibling},r.NODE_TYPE=o,e.exports=r},function(e,t,n){"use strict";function r(e){var t;return"[object String]"===Object.prototype.toString.call(e)?(t=document.createElement("div"),t.innerHTML=o(e)):t=e,t.__htmlRootByToMark=!0,t}function o(e){return e=e.replace(i,""),e=e.replace(a,"><"),e=e.replace(u,"> <")}var i=/^[\s\r\n\t]+|[\s\r\n\t]+$/g,a=/>[\r\n\t]+</g,u=/>[ ]+</g;r.preProcess=o,e.exports=r}])}); |