lys-markdown-parser
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -413,3 +413,3 @@ 'use strict'; | ||
function sortUl(ul) { | ||
var SPACE_PER = 5; | ||
var SPACE_PER = 4; | ||
@@ -416,0 +416,0 @@ var newUl = _objectSpread({}, ul, { |
@@ -1,1 +0,1 @@ | ||
"use strict";function _objectWithoutProperties(b,c){if(null==b)return{};var d,e,g=_objectWithoutPropertiesLoose(b,c);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(b);for(e=0;e<i.length;e++)d=i[e],!(0<=c.indexOf(d))&&Object.prototype.propertyIsEnumerable.call(b,d)&&(g[d]=b[d])}return g}function _objectWithoutPropertiesLoose(b,c){if(null==b)return{};var d,e,g={},i=Object.keys(b);for(e=0;e<i.length;e++)d=i[e],0<=c.indexOf(d)||(g[d]=b[d]);return g}function _classCallCheck(b,c){if(!(b instanceof c))throw new TypeError("Cannot call a class as a function")}function _defineProperties(b,c){for(var d,f=0;f<c.length;f++)d=c[f],d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(b,d.key,d)}function _createClass(b,c,d){return c&&_defineProperties(b.prototype,c),d&&_defineProperties(b,d),b}function _slicedToArray(b,c){return _arrayWithHoles(b)||_iterableToArrayLimit(b,c)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(d,a){var f,b=[],g=!0,k=!1;try{for(var l,m=d[Symbol.iterator]();!(g=(l=m.next()).done)&&(b.push(l.value),!(a&&b.length===a));g=!0);}catch(a){k=!0,f=a}finally{try{g||null==m["return"]||m["return"]()}finally{if(k)throw f}}return b}function _arrayWithHoles(b){if(Array.isArray(b))return b}function _objectSpread(b){for(var c=1;c<arguments.length;c++){var d=null==arguments[c]?{}:arguments[c],e=Object.keys(d);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(d).filter(function(b){return Object.getOwnPropertyDescriptor(d,b).enumerable}))),e.forEach(function(c){_defineProperty(b,c,d[c])})}return b}function _defineProperty(b,c,d){return c in b?Object.defineProperty(b,c,{value:d,enumerable:!0,configurable:!0,writable:!0}):b[c]=d,b}function _toConsumableArray(b){return _arrayWithoutHoles(b)||_iterableToArray(b)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(b){if(Symbol.iterator in Object(b)||"[object Arguments]"===Object.prototype.toString.call(b))return Array.from(b)}function _arrayWithoutHoles(b){if(Array.isArray(b)){for(var c=0,e=Array(b.length);c<b.length;c++)e[c]=b[c];return e}}var fuckMD=function(f){"use strict";function u(h,e){if(!h)return{type:"add",prevNode:h,nextNode:e};if(!e)return{type:"del",prevNode:h,nextNode:e};if(h.type!==e.type)return{type:"replace",prevNode:h,nextNode:e};var f={type:"update",prevNode:h,nextNode:e,propsChange:[],children:[]},a=g(h,e);if(a.length){var c;(c=f.propsChange).push.apply(c,_toConsumableArray(a))}return(f.children=b(h,e).filter(function(b){return b}),0<f.propsChange.length+f.children.length)?f:(e.__htmlNode=h.__htmlNode,e.__update=h.__update,f)}function b(k,e){var d=k.children,c=void 0===d?[]:d,g=e.children,h=void 0===g?[]:g,a=[],l=[],b=c.filter(function(c){return!!h.some(function(a){return a.type===c.type})||(a.push(u(c,null)),!1)});h.forEach(function(e){b.some(function(c,d){return c.type===e.type&&(b[d]={isDel:!0,ele:c},!0)})}),b.filter(function(b){return!b.isDel}).forEach(function(b){return a.push(u(b,null))});var f=b.filter(function(b){return b.isDel}).map(function(b){return b.ele});return h.forEach(function(d,e){var b=f.some(function(g,a){if(g.type===d.type){f.splice(a,1),f.splice(e>a?e-1:e,0,{used:!0,ele:g}),a!==e&&l.push({type:"move",prevNode:g,nextNode:d,current:a,moveTo:e>a?e+1:e});var b=u(g,d);return l.push(b),!0}return!1});if(!b){f.splice(e,0,{add:!0,item:d});var c=u(null,d);l.push(_objectSpread({},c,{moveTo:e}))}}),a.concat(l,[],[])}function g(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},f=Object.keys(b),g=Object.keys(c),e=[];return f.forEach(function(d){return["__htmlNode","__parent","__update","children","type"].includes(d)?void 0:g.includes(d)?void(b[d]!==c[d]&&e.push({type:"change",key:d,prevNode:b,nextNode:c})):void e.push({type:"del",key:d,prevNode:b,nextNode:c})}),g.forEach(function(d){f.includes(d)||e.push({type:"add",key:d,prevNode:b,nextNode:c})}),e}function h(){for(var b,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"[",f=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"]",d=0,k=-1,l=0,m=function(b){return c.slice(d,d+b.length)===b};d<c.length;){if(b=c[d],!l)if(!b.trim()){d+=1;continue}else if(m(e)){k=d,l+=1,d+=e.length;continue}else return[void 0,c];if(m(f)?(l-=1,d+=f.length):m(e)?(l+=1,d+=e.length):d+=1,!l)return[c.slice(k+e.length,d-f.length),c.slice(d)]}return[void 0,c]}function i(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",d=b.indexOf(c);return[b.slice(0,d),b.slice(d+c.length)]}function j(){function t(b,c){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},e=d.isPush,f=n;n=b,b.__parent=n,c&&c(),n=f,(void 0===e||e)&&n.children.push(b)}function k(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";m=m.slice(b.length)}function f(b){return[B.head,B.ul,B.code,B.queto].some(function(c){return c.test(b)})}function a(){function d(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,d=b.split("\n")[c].trim();return /^\|.+\|$/.test(d)?d.split("|").slice(1,-1):[]}var c=d(m,0),e=d(m,1),b=c.length;if(0!=b&&c.length==e.length&&e.every(function(b){return /^-+$/.test(b.replace(/\s/g,""))}))return t({type:"table",children:[]},function(){m=m.replace(/(.+)\n?/,function(c,a){return t({type:"thead",children:[]},function(){t({type:"tr",children:[]},function(){a.trim().split("|").slice(1,-1).map(function(a){t({type:"th",children:[]},function(){g(a)})})})}),""}),m=m.replace(/.+\n?/,""),t({type:"tbody",children:[]},function(){for(var a,d=function a(){var a=(m.match(/^.+\n?/)||[])[0];return a?f(a)?"break":void(m=m.replace(a,""),t({type:"tr",children:[]},function(){var c,e=a.trim().split("|");e=e[0]?e.slice(0,b):e.slice(1).slice(0,b),(c=e).push.apply(c,_toConsumableArray(Array(b-e.length).fill(""))),e.forEach(function(a){t({type:"td",children:[]},function(){g(a)})})})):"break"};a=d(),"break"!==a;);})}),!0}function g(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(b){if(B.url.test(b))return void g(b.replace(B.url,function(c,d,a){return t({type:"a",href:a,value:d,children:[]},function(){g(d)}),""}));if(B.blod.test(b))return void g(b.replace(B.blod,function(c,a){return t({type:"b",children:[]},function(){g(a)}),""}));if(B.italic.test(b))return void g(b.replace(B.italic,function(c,a){return t({type:"i",children:[]},function(){g(a)}),""}));if(B.inlineCode.test(b))return void g(b.replace(B.inlineCode,function(c,a){return a&&t({type:"inlineCode",children:[]},function(){g(a)}),""}));if(B.video.test(b))return void g(b.replace(B.video,function(b,c,d){return n.children.push({type:"video",src:d,alt:c}),""}));if(B.audio.test(b))return b=b.replace(B.audio,function(b,c,d){return n.children.push({type:"audio",src:d,alt:c}),""}),void g(b);if(B.img.test(b))return void g(b.replace(B.img,function(b,c,d){return n.children.push({type:"img",src:d,alt:c}),""}));if("\n"==b[0])return n.children.push({type:"br"}),void g(b.slice(1));var c=n.children[n.children.length-1];c&&"text"===c.type?c.value+=b[0]:n.children.push({type:"text",value:l(b[0])}),g(b.slice(1))}}function l(b){return b.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function e(){function g(){var a=Math.floor,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:-1;if(j){var e=(j.match(/.+\n?/)||[])[0],d=e.match(/\s*/)[0],k=a(d.length/5);if(/^[-+]\s+/.test(e.trim())){var h="+"==e.match(/\s*[-+]/)[0].trim();if(k==c+1){var i={type:"ul",listStyleType:h?"decimal":b[k%b.length],children:[]};return t(i,function(){g(c+1)}),void g(c)}if(k==c)return t({type:"li",children:[]},function(){c(e.replace(/\s*[-+]\s*/,""))}),j=j.slice(e.length),void g(c);if(k<c)return}var l=n.children[n.children.length-1];t(l,function(){c(e)},{isPush:!1}),j=j.slice(e.length),g(c)}}var j=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";j="".concat(j,"\n");var b=["disc","circle","square"];g()}function c(){if(!/^\n{1,2}$/.test(m)&&m){if(/Reg.br/.test(m)){var b=m.match(B.br),d=_slicedToArray(b,1),l=d[0];return n.children.push({type:"br"}),k(l),void c()}if(B.head.test(m)){var o=m.match(B.head)||[],p=_slicedToArray(o,3),q=p[0],f=p[1],r=p[2],C={type:"h".concat(f.length),children:[]};return t(C,function(){g(r)}),k(q),void c()}if(B.queto.test(m)){var s=m.match(B.queto),D=_slicedToArray(s,2),F=D[0],v=D[1],G=h(v,"[","]"),H=_slicedToArray(G,2),W=H[0],I=H[1],J={type:"queto",tag:W,children:[]},w=j(I.replace(/^\s*\n/,""));return J.children=w.children,n.children.push(J),n.children.push({type:"br"}),k(F),void c()}if(B.code.test(m)){var K=m.match(B.code),L=_slicedToArray(K,2),M=L[0],N=L[1],O=i(N,"\n").map(function(b){return b.trim()}),u=_slicedToArray(O,2),P=u[0],E=u[1];return n.children.push({type:"code",language:P,value:E}),k(M),void c()}if(B.ul.test(m)){var Q=m.match(B.ul),R=_slicedToArray(Q,2),S=R[0],T=R[1];return t(n,function(){e(T)},{isPush:!1}),n.children.push({type:"br"}),k(S),void c()}if(m.match(/.+\n/)&&/\|.+\|/.test(m.match(/.+\n/)[0].trim())&&a(m))return void c();if(B.hr.test(m)){var U=m.match(B.hr)||[],X=_slicedToArray(U,1),V=X[0];return void 0!==V&&n.children.push({type:"hr",children:[]}),k(V),void c()}if(B.text.test(m)){var x=m.match(B.text)||[""],y=_slicedToArray(x,1),z=y[0];return g(z),k(z),void c()}throw new Error("cannot handle str:".concat(m))}}var m=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";m+="\n\n";var n={children:[],type:"root"};return c(),n}function v(b,c){return c&&c.parentElement&&c.parentElement.insertBefore(b,c),b}function k(a){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(a){var b=a.nextNode;switch(a.type){case"del":{var c=a.prevNode.__htmlNode;c.parentElement||console.log("delete error::",a),c.parentElement.removeChild(c);break}case"add":{m(b,n,{beforeAppend:function(b){var c=n.childNodes[a.moveTo];if(c)return v(b,c),!0}});break}case"replace":{var e=a.prevNode.__htmlNode,p=document.createDocumentFragment();m(b,p),e.parentElement.replaceChild(p,e);break}case"move":{var f=a.moveTo,j=a.prevNode,q=j.__htmlNode.parentElement;q.childNodes[f]!==j.__htmlNode&&(q.childNodes[f]?v(j.__htmlNode,q.childNodes[f]):q.appendChild(j.__htmlNode));break}case"update":{var l=a.propsChange,h=a.children,g=a.prevNode,i=a.nextNode,d=g.__htmlNode;i.__htmlNode=d,g.__update&&(i.__update=g.__update),l.forEach(function(a){var b=a.key;switch(a.type){case"change":case"add":{var c=i[b];if(g.__update){g.__update(b,i);break}if(d instanceof Text){d.data=c;break}d.setAttribute(b,c);break}case"del":{d.removeAttribute(b);break}}}),h.forEach(function(a){return k(a,d)});break}default:console.error("canot handle type",a,a.type);}}}function l(b){var d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return"text"===b.type&&(d+=b.value||""),b.children&&b.children.forEach(function(b){d+=l(b)}),d}function m(d,c){var e,o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(d.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(d.src.trim())){e=document.createElement("div"),e.className="audio",e.innerHTML=d.src.replace("http://","//");var a=e.querySelector("iframe");a.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else e=document.createElement(d.type),e.src=d.src,e.alt=d.alt,e.controls="true";break}case"img":{var n=d.src.match(/\.(\d+)x(\d+)\./);if(n){var p=n.slice(1,3),f=_slicedToArray(p,2),b=f[0],q=f[1],t=d.src;e=document.createElement("div"),e.style.cssText=";position: relative; max-width: ".concat(b,"px; overflow: hidden; background: rgb(219, 221, 215);"),e.innerHTML="<div style=\"padding-top: ".concat(100*(q/b),"%;\">\n <img ").concat(LY.lazyLoad.caches.includes(t)?"src=\"".concat(t,"\" data-img-cache=\"true\""):"","\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(d.src,"\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>");break}else{e=document.createElement(d.type),e.src=d.src,e.alt=d.alt;break}}case"text":{var g=d.value;e=document.createTextNode(g);break}case"br":{e=document.createElement(d.type);break}case"a":{e=document.createElement(d.type),e.href=d.href,e.target="_blank";break}case"code":{e=document.createElement("pre");var h=document.createElement("code");d.__update=function(b,c){switch(b){case"language":{h.className=["highlight",c[b]||""].join(" ");break}case"value":{h.textContent=c[b];break}default:}},d.__update("language",d),d.__update("value",d),e.appendChild(h);break}case"inlineCode":{e=document.createElement("code"),e.className="inlineCode";break}case"h1":{e=document.createElement(d.type);var r=document.createElement("a"),s=l(d);r.href="#".concat(s),r.id=s,e.appendChild(r);break}case"ul":{e=document.createElement(d.type),d.__update=function(b,c){e.style.cssText+=";list-style-type:".concat(c[b],";")},d.__update("listStyleType",d);break}default:e=document.createElement(d.type),d.indent&&(e.style.cssText+=";padding-left: 2em;"),"table"==d.type&&e.setAttribute("border","1");}d.tag&&e.setAttribute("tag",d.tag),d.children&&d.children.forEach(function(a){return m(a,e)});var i=o.beforeAppend&&o.beforeAppend(e);return i||c.appendChild(e),d.__htmlNode=e,e}function o(b){function d(b){"text"==b.type&&(e+=b.value||""),"img"==b.type&&g.push(b.src),b.children&&b.children.forEach(d)}var e="",g=[];return d(b),{text:e,imgs:g}}function p(){var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=d[c];if(!b){var f=j(c);b=_objectSpread({root:f},o(f)),d[c]=b}return b}function a(b){return new Promise(function(c){if(r[b])return c();var d=function(){r[b]=!0,c()};if(b.endsWith(".js")){var e=document.createElement("script");e.onload=d,e.src=b,document.head.appendChild(e)}else if(b.endsWith(".css")){var f=document.createElement("link");f.onload=d,f.type="text/css",f.rel="stylesheet",f.charset="utf-8",f.href=b,document.head.appendChild(f)}})}function n(d,b){Promise.all(b.asset.map(a)).then(function(){window.hljs&&d&&(window.hljs.configure({tabReplace:4}),_toConsumableArray(d.querySelectorAll("code.highlight")).forEach(function(b){window.hljs.highlightBlock(b)}))})}function q(b){return _objectSpread({asset:[]},b)}var B={get hr(){return /(^-{3,}[^\n]+\n?)/},get code(){return /^`{3}(((?!```)[\s\S])*)`{3}/},get queto(){return /^>(((?!\n\n)[\s\S])*)\n\n/},get head(){return /^\s*(#{1,6})([^\n]*)\n?/},get ul(){return /^([-+]\s+((?!\n\n)[\s\S])*)\n\n/},get url(){return /^\[([^\]]+)\]\(([^)]+)\)/},get inlineCode(){return /^`([^`]*)`/},get br(){return /^\n/},get text(){return /^[^\n]*\n?/},get blod(){return /^\*{3}(((?!\*{3}).)*)\*{3}/},get italic(){return /^\*{2}(((?!\*{2}).)*)\*{2}/},get video(){return /^!{3}\[([^\]]*)\]\(([^)]+)\)/},get audio(){return /^!{2}\[([^\]]*)\]\(([^)]+)\)/},get img(){return /^!\[([^\]]*)\]\(([^)]+)\)/}},d={},r={},c=function(){function d(b,c){_classCallCheck(this,d),this.dom=b,this.config=c,this.prevRoot=null}return _createClass(d,[{key:"update",value:function(b){this.dom.classList.add("markdown");var e=p(b),a=u(this.prevRoot,e.root);this.prevRoot=e.root,k(a,this.dom);var c=q(this.config);c.useHighlight&&n(this.dom,c)}}]),d}();return f.Markdown=c,f.parser=j,f.trans=m,f.codeHighlight=n,f.getParseResult=p,f.markdown=function(b,a,c){b.innerHTML="",b.classList.add("markdown");var e=p(a);m(e.root,b),c=q(c),n(b,c)},f.markdownInfo=function(c){var d=p(c),a=d.root,e=_objectWithoutProperties(d,["root"]);return e},f}({}); | ||
"use strict";function _objectWithoutProperties(a,b){if(null==a)return{};var c,f,h=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var g=Object.getOwnPropertySymbols(a);for(f=0;f<g.length;f++)c=g[f],!(0<=b.indexOf(c))&&Object.prototype.propertyIsEnumerable.call(a,c)&&(h[c]=a[c])}return h}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,f,h={},g=Object.keys(a);for(f=0;f<g.length;f++)c=g[f],0<=b.indexOf(c)||(h[c]=a[c]);return h}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,e=0;e<b.length;e++)c=b[e],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(c,d){var e,a=[],b=!0,h=!1;try{for(var i,j=c[Symbol.iterator]();!(b=(i=j.next()).done)&&(a.push(i.value),!(d&&a.length===d));b=!0);}catch(b){h=!0,e=b}finally{try{b||null==j["return"]||j["return"]()}finally{if(h)throw e}}return a}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _objectSpread(a){for(var b=1;b<arguments.length;b++){var f=null==arguments[b]?{}:arguments[b],d=Object.keys(f);"function"==typeof Object.getOwnPropertySymbols&&(d=d.concat(Object.getOwnPropertySymbols(f).filter(function(a){return Object.getOwnPropertyDescriptor(f,a).enumerable}))),d.forEach(function(b){_defineProperty(a,b,f[b])})}return a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,d=Array(a.length);b<a.length;b++)d[b]=a[b];return d}}var fuckMD=function(e){"use strict";function s(d,g){if(!d)return{type:"add",prevNode:d,nextNode:g};if(!g)return{type:"del",prevNode:d,nextNode:g};if(d.type!==g.type)return{type:"replace",prevNode:d,nextNode:g};var e={type:"update",prevNode:d,nextNode:g,propsChange:[],children:[]},f=b(d,g);if(f.length){var a;(a=e.propsChange).push.apply(a,_toConsumableArray(f))}return(e.children=t(d,g).filter(function(a){return a}),0<e.propsChange.length+e.children.length)?e:(g.__htmlNode=d.__htmlNode,g.__update=d.__update,e)}function t(i,j){var e=i.children,d=void 0===e?[]:e,c=j.children,g=void 0===c?[]:c,h=[],k=[],a=d.filter(function(b){return!!g.some(function(c){return c.type===b.type})||(h.push(s(b,null)),!1)});g.forEach(function(b){a.some(function(e,c){return e.type===b.type&&(a[c]={isDel:!0,ele:e},!0)})}),a.filter(function(a){return!a.isDel}).forEach(function(a){return h.push(s(a,null))});var l=a.filter(function(a){return a.isDel}).map(function(a){return a.ele});return g.forEach(function(f,d){var a=l.some(function(c,e){if(c.type===f.type){l.splice(e,1),l.splice(d>e?d-1:d,0,{used:!0,ele:c}),e!==d&&k.push({type:"move",prevNode:c,nextNode:f,current:e,moveTo:d>e?d+1:d});var a=s(c,f);return k.push(a),!0}return!1});if(!a){l.splice(d,0,{add:!0,item:f});var b=s(null,f);k.push(_objectSpread({},b,{moveTo:d}))}}),h.concat(k,[],[])}function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=Object.keys(a),f=Object.keys(b),g=[];return c.forEach(function(c){return["__htmlNode","__parent","__update","children","type"].includes(c)?void 0:f.includes(c)?void(a[c]!==b[c]&&g.push({type:"change",key:c,prevNode:a,nextNode:b})):void g.push({type:"del",key:c,prevNode:a,nextNode:b})}),f.forEach(function(e){c.includes(e)||g.push({type:"add",key:e,prevNode:a,nextNode:b})}),g}function f(){for(var a,g=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"[",e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"]",f=0,h=-1,i=0,j=function(a){return g.slice(f,f+a.length)===a};f<g.length;){if(a=g[f],!i)if(!a.trim()){f+=1;continue}else if(j(c)){h=f,i+=1,f+=c.length;continue}else return[void 0,g];if(j(e)?(i-=1,f+=e.length):j(c)?(i+=1,f+=c.length):f+=1,!i)return[g.slice(h+c.length,f-e.length),g.slice(f)]}return[void 0,g]}function g(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",c=a.indexOf(b);return[a.slice(0,c),a.slice(c+b.length)]}function h(){function s(a,b){var c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},d=c.isPush,e=o;o=a,a.__parent=o,b&&b(),o=e,(void 0===d||d)&&o.children.push(a)}function i(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";t=t.slice(a.length)}function d(a){return[A.head,A.ul,A.code,A.queto].some(function(b){return b.test(a)})}function j(){function a(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=a.split("\n")[b].trim();return /^\|.+\|$/.test(c)?c.split("|").slice(1,-1):[]}var f=a(t,0),c=a(t,1),g=f.length;if(0!=g&&f.length==c.length&&c.every(function(a){return /^-+$/.test(a.replace(/\s/g,""))}))return s({type:"table",children:[]},function(){t=t.replace(/(.+)\n?/,function(b,c){return s({type:"thead",children:[]},function(){s({type:"tr",children:[]},function(){c.trim().split("|").slice(1,-1).map(function(b){s({type:"th",children:[]},function(){k(b)})})})}),""}),t=t.replace(/.+\n?/,""),s({type:"tbody",children:[]},function(){for(var b,c=function b(){var b=(t.match(/^.+\n?/)||[])[0];return b?d(b)?"break":void(t=t.replace(b,""),s({type:"tr",children:[]},function(){var a,d=b.trim().split("|");d=d[0]?d.slice(0,g):d.slice(1).slice(0,g),(a=d).push.apply(a,_toConsumableArray(Array(g-d.length).fill(""))),d.forEach(function(b){s({type:"td",children:[]},function(){k(b)})})})):"break"};b=c(),"break"!==b;);})}),!0}function k(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(d){if(A.url.test(d))return void k(d.replace(A.url,function(b,c,d){return s({type:"a",href:d,value:c,children:[]},function(){k(c)}),""}));if(A.blod.test(d))return void k(d.replace(A.blod,function(b,c){return s({type:"b",children:[]},function(){k(c)}),""}));if(A.italic.test(d))return void k(d.replace(A.italic,function(b,c){return s({type:"i",children:[]},function(){k(c)}),""}));if(A.inlineCode.test(d))return void k(d.replace(A.inlineCode,function(b,c){return c&&s({type:"inlineCode",children:[]},function(){k(c)}),""}));if(A.video.test(d))return void k(d.replace(A.video,function(a,b,c){return o.children.push({type:"video",src:c,alt:b}),""}));if(A.audio.test(d))return d=d.replace(A.audio,function(a,b,c){return o.children.push({type:"audio",src:c,alt:b}),""}),void k(d);if(A.img.test(d))return void k(d.replace(A.img,function(a,b,c){return o.children.push({type:"img",src:c,alt:b}),""}));if("\n"==d[0])return o.children.push({type:"br"}),void k(d.slice(1));var e=o.children[o.children.length-1];e&&"text"===e.type?e.value+=d[0]:o.children.push({type:"text",value:a(d[0])}),k(d.slice(1))}}function a(a){return a.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function b(){function f(){var b=Math.floor,j=0<arguments.length&&void 0!==arguments[0]?arguments[0]:-1;if(g){var c=(g.match(/.+\n?/)||[])[0],e=c.match(/\s*/)[0],d=b(e.length/5);if(/^[-+]\s+/.test(c.trim())){var k="+"==c.match(/\s*[-+]/)[0].trim();if(d==j+1){var h={type:"ul",listStyleType:k?"decimal":a[d%a.length],children:[]};return s(h,function(){f(j+1)}),void f(j)}if(d==j)return s({type:"li",children:[]},function(){j(c.replace(/\s*[-+]\s*/,""))}),g=g.slice(c.length),void f(j);if(d<j)return}var i=o.children[o.children.length-1];s(i,function(){j(c)},{isPush:!1}),g=g.slice(c.length),f(j)}}var g=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";g="".concat(g,"\n");var a=["disc","circle","square"];f()}function e(){if(!/^\n{1,2}$/.test(t)&&t){if(/Reg.br/.test(t)){var a=t.match(A.br),c=_slicedToArray(a,1),d=c[0];return o.children.push({type:"br"}),i(d),void e()}if(A.head.test(t)){var l=t.match(A.head)||[],m=_slicedToArray(l,3),n=m[0],p=m[1],q=m[2],r={type:"h".concat(p.length),children:[]};return s(r,function(){k(q)}),i(n),void e()}if(A.queto.test(t)){var B=t.match(A.queto),C=_slicedToArray(B,2),D=C[0],F=C[1],v=f(F,"[","]"),G=_slicedToArray(v,2),H=G[0],W=G[1],I={type:"queto",tag:H,children:[]},J=h(W.replace(/^\s*\n/,""));return I.children=J.children,o.children.push(I),o.children.push({type:"br"}),i(D),void e()}if(A.code.test(t)){var w=t.match(A.code),K=_slicedToArray(w,2),L=K[0],M=K[1],N=g(M,"\n").map(function(a){return a.trim()}),O=_slicedToArray(N,2),u=O[0],P=O[1];return o.children.push({type:"code",language:u,value:P}),i(L),void e()}if(A.ul.test(t)){var E=t.match(A.ul),Q=_slicedToArray(E,2),R=Q[0],S=Q[1];return s(o,function(){b(S)},{isPush:!1}),o.children.push({type:"br"}),i(R),void e()}if(t.match(/.+\n/)&&/\|.+\|/.test(t.match(/.+\n/)[0].trim())&&j(t))return void e();if(A.hr.test(t)){var T=t.match(A.hr)||[],U=_slicedToArray(T,1),X=U[0];return void 0!==X&&o.children.push({type:"hr",children:[]}),i(X),void e()}if(A.text.test(t)){var V=t.match(A.text)||[""],x=_slicedToArray(V,1),y=x[0];return k(y),i(y),void e()}throw new Error("cannot handle str:".concat(t))}}var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";t+="\n\n";var o={children:[],type:"root"};return e(),o}function i(a,b){return b&&b.parentElement&&b.parentElement.insertBefore(a,b),a}function j(k){var a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(k){var m=k.nextNode;switch(k.type){case"del":{var b=k.prevNode.__htmlNode;b.parentElement||console.log("delete error::",k),b.parentElement.removeChild(b);break}case"add":{l(m,a,{beforeAppend:function(d){var b=a.childNodes[k.moveTo];if(b)return i(d,b),!0}});break}case"replace":{var c=k.prevNode.__htmlNode,e=document.createDocumentFragment();l(m,e),c.parentElement.replaceChild(e,c);break}case"move":{var n=k.moveTo,f=k.prevNode,o=f.__htmlNode.parentElement;o.childNodes[n]!==f.__htmlNode&&(o.childNodes[n]?i(f.__htmlNode,o.childNodes[n]):o.appendChild(f.__htmlNode));break}case"update":{var p=k.propsChange,q=k.children,h=k.prevNode,g=k.nextNode,r=h.__htmlNode;g.__htmlNode=r,h.__update&&(g.__update=h.__update),p.forEach(function(d){var a=d.key;switch(d.type){case"change":case"add":{var b=g[a];if(h.__update){h.__update(a,g);break}if(r instanceof Text){r.data=b;break}r.setAttribute(a,b);break}case"del":{r.removeAttribute(a);break}}}),q.forEach(function(b){return j(b,r)});break}default:console.error("canot handle type",k,k.type);}}}function k(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return"text"===a.type&&(c+=a.value||""),a.children&&a.children.forEach(function(a){c+=k(a)}),c}function l(j,d){var m,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(j.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(j.src.trim())){m=document.createElement("div"),m.className="audio",m.innerHTML=j.src.replace("http://","//");var o=m.querySelector("iframe");o.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else m=document.createElement(j.type),m.src=j.src,m.alt=j.alt,m.controls="true";break}case"img":{var a=j.src.match(/\.(\d+)x(\d+)\./);if(a){var n=a.slice(1,3),p=_slicedToArray(n,2),f=p[0],b=p[1],q=j.src;m=document.createElement("div"),m.style.cssText=";position: relative; max-width: ".concat(f,"px; overflow: hidden; background: rgb(219, 221, 215);"),m.innerHTML="<div style=\"padding-top: ".concat(100*(b/f),"%;\">\n <img ").concat(LY.lazyLoad.caches.includes(q)?"src=\"".concat(q,"\" data-img-cache=\"true\""):"","\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(j.src,"\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>");break}else{m=document.createElement(j.type),m.src=j.src,m.alt=j.alt;break}}case"text":{var t=j.value;m=document.createTextNode(t);break}case"br":{m=document.createElement(j.type);break}case"a":{m=document.createElement(j.type),m.href=j.href,m.target="_blank";break}case"code":{m=document.createElement("pre");var g=document.createElement("code");j.__update=function(a,b){switch(a){case"language":{g.className=["highlight",b[a]||""].join(" ");break}case"value":{g.textContent=b[a];break}default:}},j.__update("language",j),j.__update("value",j),m.appendChild(g);break}case"inlineCode":{m=document.createElement("code"),m.className="inlineCode";break}case"h1":{m=document.createElement(j.type);var h=document.createElement("a"),r=k(j);h.href="#".concat(r),h.id=r,m.appendChild(h);break}case"ul":{m=document.createElement(j.type),j.__update=function(a,b){m.style.cssText+=";list-style-type:".concat(b[a],";")},j.__update("listStyleType",j);break}default:m=document.createElement(j.type),j.indent&&(m.style.cssText+=";padding-left: 2em;"),"table"==j.type&&m.setAttribute("border","1");}j.tag&&m.setAttribute("tag",j.tag),j.children&&j.children.forEach(function(b){return l(b,m)});var s=c.beforeAppend&&c.beforeAppend(m);return s||d.appendChild(m),j.__htmlNode=m,m}function m(a){function c(a){"text"==a.type&&(d+=a.value||""),"img"==a.type&&f.push(a.src),a.children&&a.children.forEach(c)}var d="",f=[];return c(a),{text:d,imgs:f}}function o(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=a[d];if(!c){var e=h(d);c=_objectSpread({root:e},m(e)),a[d]=c}return c}function p(a){return new Promise(function(b){if(q[a])return b();var c=function(){q[a]=!0,b()};if(a.endsWith(".js")){var d=document.createElement("script");d.onload=c,d.src=a,document.head.appendChild(d)}else if(a.endsWith(".css")){var e=document.createElement("link");e.onload=c,e.type="text/css",e.rel="stylesheet",e.charset="utf-8",e.href=a,document.head.appendChild(e)}})}function u(a,c){Promise.all(c.asset.map(p)).then(function(){window.hljs&&a&&(window.hljs.configure({tabReplace:4}),_toConsumableArray(a.querySelectorAll("code.highlight")).forEach(function(a){window.hljs.highlightBlock(a)}))})}function n(a){return _objectSpread({asset:[]},a)}var A={get hr(){return /(^-{3,}[^\n]+\n?)/},get code(){return /^`{3}(((?!```)[\s\S])*)`{3}/},get queto(){return /^>(((?!\n\n)[\s\S])*)\n\n/},get head(){return /^\s*(#{1,6})([^\n]*)\n?/},get ul(){return /^([-+]\s+((?!\n\n)[\s\S])*)\n\n/},get url(){return /^\[([^\]]+)\]\(([^)]+)\)/},get inlineCode(){return /^`([^`]*)`/},get br(){return /^\n/},get text(){return /^[^\n]*\n?/},get blod(){return /^\*{3}(((?!\*{3}).)*)\*{3}/},get italic(){return /^\*{2}(((?!\*{2}).)*)\*{2}/},get video(){return /^!{3}\[([^\]]*)\]\(([^)]+)\)/},get audio(){return /^!{2}\[([^\]]*)\]\(([^)]+)\)/},get img(){return /^!\[([^\]]*)\]\(([^)]+)\)/}},a={},q={},d=function(){function a(d,b){_classCallCheck(this,a),this.dom=d,this.config=b,this.prevRoot=null}return _createClass(a,[{key:"update",value:function(d){this.dom.classList.add("markdown");var b=o(d),e=s(this.prevRoot,b.root);this.prevRoot=b.root,j(e,this.dom);var a=n(this.config);a.useHighlight&&u(this.dom,a)}}]),a}();return e.Markdown=d,e.parser=h,e.trans=l,e.codeHighlight=u,e.getParseResult=o,e.markdown=function(d,b,a){d.innerHTML="",d.classList.add("markdown");var f=o(b);l(f.root,d),a=n(a),u(d,a)},e.markdownInfo=function(b){var c=o(b),d=c.root,a=_objectWithoutProperties(c,["root"]);return a},e}({}); |
@@ -412,3 +412,3 @@ "use strict"; | ||
function sortUl(ul) { | ||
var SPACE_PER = 5; | ||
var SPACE_PER = 4; | ||
@@ -415,0 +415,0 @@ var newUl = _objectSpread({}, ul, { |
{ | ||
"name": "lys-markdown-parser", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "js markdown parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -0,1 +1,2 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
@@ -2,0 +3,0 @@ trailingComma: "es5", |
@@ -108,3 +108,3 @@ function getNextLine(ss) { | ||
function sortUl(ul) { | ||
const SPACE_PER = 5; | ||
const SPACE_PER = 4; | ||
const newUl = { | ||
@@ -111,0 +111,0 @@ ...ul, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
204157
4368