lys-markdown-parser
Advanced tools
Comparing version 1.1.7 to 1.1.10
@@ -331,2 +331,6 @@ 'use strict'; | ||
get lineThrough() { | ||
return /^~{2}(((?!~{2}).)*)~{2}/; | ||
}, | ||
get italic() { | ||
@@ -619,2 +623,17 @@ return /^\*{2}(((?!\*{2}).)*)\*{2}/; | ||
return; | ||
} // 中划线 | ||
if (Reg.lineThrough.test(textStr)) { | ||
handleText(textStr.replace(Reg.lineThrough, function (m, $0) { | ||
var child = { | ||
type: 'lineThrough', | ||
children: [] | ||
}; | ||
changeCurrentNode(child, function () { | ||
handleText($0); | ||
}); | ||
return ''; | ||
})); | ||
return; | ||
} // 倾斜 | ||
@@ -1261,2 +1280,9 @@ | ||
case 'lineThrough': | ||
{ | ||
ele = document.createElement('span'); | ||
ele.style.cssText += ";text-decoration: line-through;"; | ||
break; | ||
} | ||
default: | ||
@@ -1263,0 +1289,0 @@ { |
@@ -1,1 +0,1 @@ | ||
"use strict";function _objectWithoutProperties(g,a){if(null==g)return{};var b,h,i=_objectWithoutPropertiesLoose(g,a);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(g);for(h=0;h<e.length;h++)b=e[h],!(0<=a.indexOf(b))&&Object.prototype.propertyIsEnumerable.call(g,b)&&(i[b]=g[b])}return i}function _objectWithoutPropertiesLoose(g,a){if(null==g)return{};var b,h,i={},e=Object.keys(g);for(h=0;h<e.length;h++)b=e[h],0<=a.indexOf(b)||(i[b]=g[b]);return i}function _classCallCheck(c,a){if(!(c instanceof a))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,a){for(var b,f=0;f<a.length;f++)b=a[f],b.enumerable=b.enumerable||!1,b.configurable=!0,"value"in b&&(b.writable=!0),Object.defineProperty(e,b.key,b)}function _createClass(d,a,b){return a&&_defineProperties(d.prototype,a),b&&_defineProperties(d,b),d}function _slicedToArray(c,a){return _arrayWithHoles(c)||_iterableToArrayLimit(c,a)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(i,a){var b,j=[],c=!0,k=!1;try{for(var l,m=i[Symbol.iterator]();!(c=(l=m.next()).done)&&(j.push(l.value),!(a&&j.length===a));c=!0);}catch(c){k=!0,b=c}finally{try{c||null==m["return"]||m["return"]()}finally{if(k)throw b}}return j}function _arrayWithHoles(b){if(Array.isArray(b))return b}function _objectSpread(e){for(var a=1;a<arguments.length;a++){var f=null==arguments[a]?{}:arguments[a],c=Object.keys(f);"function"==typeof Object.getOwnPropertySymbols&&(c=c.concat(Object.getOwnPropertySymbols(f).filter(function(b){return Object.getOwnPropertyDescriptor(f,b).enumerable}))),c.forEach(function(a){_defineProperty(e,a,f[a])})}return e}function _defineProperty(d,a,b){return a in d?Object.defineProperty(d,a,{value:b,enumerable:!0,configurable:!0,writable:!0}):d[a]=b,d}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(d){if(Array.isArray(d)){for(var a=0,e=Array(d.length);a<d.length;a++)e[a]=d[a];return e}}var fuckMD=function(s){"use strict";function v(d,a){if(!d)return{type:"add",prevNode:d,nextNode:a};if(!a)return{type:"del",prevNode:d,nextNode:a};if(d.type!==a.type)return{type:"replace",prevNode:d,nextNode:a};var b={type:"update",prevNode:d,nextNode:a,propsChange:[],children:[]},e=c(d,a);if(e.length){var f;(f=b.propsChange).push.apply(f,_toConsumableArray(e))}return(b.children=w(d,a).filter(function(b){return b}),0<b.propsChange.length+b.children.length)?b:(a.__htmlNode=d.__htmlNode,a.__update=d.__update,b)}function w(b,a){var c=b.children,d=void 0===c?[]:c,e=a.children,f=void 0===e?[]:e,g=[],h=[],i=d.filter(function(c){return!!f.some(function(a){return a.type===c.type})||(g.push(v(c,null)),!1)});f.forEach(function(d){i.some(function(a,b){return a.type===d.type&&(i[b]={isDel:!0,ele:a},!0)})}),i.filter(function(b){return!b.isDel}).forEach(function(b){return g.push(v(b,null))});var j=i.filter(function(b){return b.isDel}).map(function(b){return b.ele});return f.forEach(function(b,a){var c=j.some(function(c,d){if(c.type===b.type){j.splice(d,1),j.splice(a>d?a-1:a,0,{used:!0,ele:c}),d!==a&&h.push({type:"move",prevNode:c,nextNode:b,current:d,moveTo:a>d?a+1:a});var e=v(c,b);return h.push(e),!0}return!1});if(!c){j.splice(a,0,{add:!0,item:b});var d=v(null,b);h.push(_objectSpread({},d,{moveTo:a}))}}),g.concat(h,[],[])}function c(){var f=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},b=Object.keys(f),g=Object.keys(a),h=[];return b.forEach(function(b){return["__htmlNode","__parent","__update","children","type"].includes(b)?void 0:g.includes(b)?void(f[b]!==a[b]&&h.push({type:"change",key:b,prevNode:f,nextNode:a})):void h.push({type:"del",key:b,prevNode:f,nextNode:a})}),g.forEach(function(c){b.includes(c)||h.push({type:"add",key:c,prevNode:f,nextNode:a})}),h}function a(){for(var i,j=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"[",c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"]",d=0,k=-1,l=0,m=function(b){return j.slice(d,d+b.length)===b};d<j.length;){if(i=j[d],!l)if(!i.trim()){d+=1;continue}else if(m(b)){k=d,l+=1,d+=b.length;continue}else return[void 0,j];if(m(c)?(l-=1,d+=c.length):m(b)?(l+=1,d+=b.length):d+=1,!l)return[j.slice(k+b.length,d-c.length),j.slice(d)]}return[void 0,j]}function d(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",b=d.indexOf(a);return[d.slice(0,b),d.slice(b+a.length)]}function e(){function q(f,a){var b=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},c=b.isPush,d=o;o=f,f.__parent=o,a&&a(),o=d,(void 0===c||c)&&o.children.push(f)}function f(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";k=k.slice(b.length)}function g(c){return[X.head,X.ul,X.code,X.queto].some(function(a){return a.test(c)})}function b(){function a(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,b=d.split("\n")[a].trim();return /^\|.+\|$/.test(b)?b.split("|").slice(1,-1):[]}var b=a(k,0),c=a(k,1),e=b.length;if(0!=e&&b.length==c.length&&c.every(function(b){return /^-+$/.test(b.replace(/\s/g,""))}))return q({type:"table",children:[]},function(){k=k.replace(/(.+)\n?/,function(a,b){return q({type:"thead",children:[]},function(){q({type:"tr",children:[]},function(){b.trim().split("|").slice(1,-1).map(function(a){q({type:"th",children:[]},function(){m(a)})})})}),""}),k=k.replace(/.+\n?/,""),q({type:"tbody",children:[]},function(){for(var a,c=function(){var a=(k.match(/^.+\n?/)||[])[0];return a?g(a)?"break":void(k=k.replace(a,""),q({type:"tr",children:[]},function(){var b,f=a.trim().split("|");f=f[0]?f.slice(0,e):f.slice(1).slice(0,e),(b=f).push.apply(b,_toConsumableArray(Array(e-f.length).fill(""))),f.forEach(function(a){q({type:"td",children:[]},function(){m(a)})})})):"break"};a=c(),"break"!==a;);})}),!0}function m(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(a){if(X.url.test(a))return void m(a.replace(X.url,function(a,b,c){return q({type:"a",href:c,value:b,children:[]},function(){m(b)}),""}));if(X.blod.test(a))return void m(a.replace(X.blod,function(a,b){return q({type:"b",children:[]},function(){m(b)}),""}));if(X.italic.test(a))return void m(a.replace(X.italic,function(a,b){return q({type:"i",children:[]},function(){m(b)}),""}));if(X.inlineCode.test(a))return void m(a.replace(X.inlineCode,function(a,b){return b&&q({type:"inlineCode",children:[]},function(){m(b)}),""}));if(X.video.test(a))return void m(a.replace(X.video,function(d,a,b){return o.children.push({type:"video",src:b,alt:a}),""}));if(X.audio.test(a))return a=a.replace(X.audio,function(d,a,b){return o.children.push({type:"audio",src:b,alt:a}),""}),void m(a);if(X.img.test(a))return void m(a.replace(X.img,function(d,a,b){return o.children.push({type:"img",src:b,alt:a}),""}));if("\n"==a[0])return o.children.push({type:"br"}),void m(a.slice(1));var d=o.children[o.children.length-1];d&&"text"===d.type?d.value+=a[0]:o.children.push({type:"text",value:h(a[0])}),m(a.slice(1))}}function h(b){return b.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function c(){function a(){var c=Math.floor,d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:-1;if(b){var f=(b.match(/.+\n?/)||[])[0],g=f.match(/\s*/)[0],h=c(g.length/5);if(/^[-+]\s+/.test(f.trim())){var i="+"==f.match(/\s*[-+]/)[0].trim();if(h==d+1){var j={type:"ul",listStyleType:i?"decimal":e[h%e.length],children:[]};return q(j,function(){a(d+1)}),void a(d)}if(h==d)return q({type:"li",children:[]},function(){m(f.replace(/\s*[-+]\s*/,""))}),b=b.slice(f.length),void a(d);if(h<d)return}var k=o.children[o.children.length-1];q(k,function(){m(f)},{isPush:!1}),b=b.slice(f.length),a(d)}}var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";b="".concat(b,"\n");var e=["disc","circle","square"];a()}function j(){if(!/^\n{1,2}$/.test(k)&&k){if(/Reg.br/.test(k)){var g=k.match(X.br),h=_slicedToArray(g,1),i=h[0];return o.children.push({type:"br"}),f(i),void j()}if(X.head.test(k)){var l=k.match(X.head)||[],n=_slicedToArray(l,3),p=n[0],r=n[1],s=n[2],t={type:"h".concat(r.length),children:[]};return q(t,function(){m(s)}),f(p),void j()}if(X.queto.test(k)){var u=k.match(X.queto),v=_slicedToArray(u,2),w=v[0],x=v[1],y=a(x,"[","]"),z=_slicedToArray(y,2),A=z[0],B=z[1],C={type:"queto",tag:A,children:[]},D=e(B.replace(/^\s*\n/,""));return C.children=D.children,o.children.push(C),o.children.push({type:"br"}),f(w),void j()}if(X.code.test(k)){var E=k.match(X.code),F=_slicedToArray(E,2),G=F[0],H=F[1],I=d(H,"\n").map(function(b){return b.trim()}),J=_slicedToArray(I,2),K=J[0],L=J[1];return o.children.push({type:"code",language:K,value:L}),f(G),void j()}if(X.ul.test(k)){var M=k.match(X.ul),N=_slicedToArray(M,2),O=N[0],P=N[1];return q(o,function(){c(P)},{isPush:!1}),o.children.push({type:"br"}),f(O),void j()}if(k.match(/.+\n/)&&/\|.+\|/.test(k.match(/.+\n/)[0].trim())&&b(k))return void j();if(X.hr.test(k)){var Q=k.match(X.hr)||[],R=_slicedToArray(Q,1),S=R[0];return void 0!==S&&o.children.push({type:"hr",children:[]}),f(S),void j()}if(X.text.test(k)){var T=k.match(X.text)||[""],U=_slicedToArray(T,1),V=U[0];return m(V),f(V),void j()}throw new Error("cannot handle str:".concat(k))}}var k=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";k+="\n\n";var o={children:[],type:"root"};return j(),o}function f(c,a){return a&&a.parentElement&&a.parentElement.insertBefore(c,a),c}function b(i){var a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(i){var k=i.nextNode;switch(i.type){case"del":{var c=i.prevNode.__htmlNode;c.parentElement||console.log("delete error::",i),c.parentElement.removeChild(c);break}case"add":{h(k,a,{beforeAppend:function(b){var c=a.childNodes[i.moveTo];if(c)return f(b,c),!0}});break}case"replace":{var d=i.prevNode.__htmlNode,e=document.createDocumentFragment();h(k,e),d.parentElement.replaceChild(e,d);break}case"move":{var r=i.moveTo,g=i.prevNode,j=g.__htmlNode.parentElement;j.childNodes[r]!==g.__htmlNode&&(j.childNodes[r]?f(g.__htmlNode,j.childNodes[r]):j.appendChild(g.__htmlNode));break}case"update":{var l=i.propsChange,m=i.children,n=i.prevNode,o=i.nextNode,p=n.__htmlNode;o.__htmlNode=p,n.__update&&(o.__update=n.__update),l.forEach(function(d){var a=d.key;switch(d.type){case"change":case"add":{var b=o[a];if(n.__update){n.__update(a,o);break}if(p instanceof Text){p.data=b;break}p.setAttribute(a,b);break}case"del":{p.removeAttribute(a);break}}}),m.forEach(function(c){return b(c,p)});break}default:console.error("canot handle type",i,i.type);}}}function g(c){var d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return"text"===c.type&&(d+=c.value||""),c.children&&c.children.forEach(function(b){d+=g(b)}),d}function h(j,b){var c,k=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(j.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(j.src.trim())){c=document.createElement("div"),c.className="audio",c.innerHTML=j.src.replace("http://","//");var e=c.querySelector("iframe");e.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else c=document.createElement(j.type),c.src=j.src,c.alt=j.alt,c.controls="true";break}case"img":{var f=j.src.match(/\.(\d+)x(\d+)\./);if(f){var s=f.slice(1,3),t=_slicedToArray(s,2),i=t[0],l=t[1],m=j.src;c=document.createElement("div"),c.style.cssText=";position: relative; max-width: ".concat(i,"px; overflow: hidden; background: rgb(219, 221, 215);"),c.innerHTML="<div style=\"padding-top: ".concat(100*(l/i),"%;\">\n <img ").concat(LY.lazyLoad.caches.includes(m)?"src=\"".concat(m,"\" 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{c=document.createElement(j.type),c.src=j.src,c.alt=j.alt;break}}case"text":{var n=j.value;c=document.createTextNode(n);break}case"br":{c=document.createElement(j.type);break}case"a":{c=document.createElement(j.type),c.href=j.href,c.target="_blank";break}case"code":{c=document.createElement("pre");var o=document.createElement("code");j.__update=function(c,a){switch(c){case"language":{o.className=["highlight",a[c]||""].join(" ");break}case"value":{o.textContent=a[c];break}default:}},j.__update("language",j),j.__update("value",j),c.appendChild(o);break}case"inlineCode":{c=document.createElement("code"),c.className="inlineCode";break}case"h1":{c=document.createElement(j.type);var p=document.createElement("a"),q=g(j);p.href="#".concat(q),p.id=q,c.appendChild(p);break}case"ul":{c=document.createElement(j.type),j.__update=function(d,a){c.style.cssText+=";list-style-type:".concat(a[d],";")},j.__update("listStyleType",j);break}default:c=document.createElement(j.type),j.indent&&(c.style.cssText+=";padding-left: 2em;"),"table"==j.type&&c.setAttribute("border","1");}j.tag&&c.setAttribute("tag",j.tag),j.children&&j.children.forEach(function(b){return h(b,c)});var a=k.beforeAppend&&k.beforeAppend(c);return a||b.appendChild(c),j.__htmlNode=c,c}function i(e){function f(c){"text"==c.type&&(b+=c.value||""),"img"==c.type&&g.push(c.src),c.children&&c.children.forEach(f)}var b="",g=[];return f(e),{text:b,imgs:g}}function j(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=n[d];if(!a){var f=e(d);a=_objectSpread({root:f},i(f)),n[d]=a}return a}function k(f){return new Promise(function(a){if(o[f])return a();var b=function(){o[f]=!0,a()};if(f.endsWith(".js")){var c=document.createElement("script");c.onload=b,c.src=f,document.head.appendChild(c)}else if(f.endsWith(".css")){var d=document.createElement("link");d.onload=b,d.type="text/css",d.rel="stylesheet",d.charset="utf-8",d.href=f,document.head.appendChild(d)}})}function l(c,a){Promise.all(a.asset.map(k)).then(function(){window.hljs&&c&&(window.hljs.configure({tabReplace:4}),_toConsumableArray(c.querySelectorAll("code.highlight")).forEach(function(b){window.hljs.highlightBlock(b)}))})}function m(b){return _objectSpread({asset:[]},b)}var X={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 /^!\[([^\]]*)\]\(([^)]+)\)/}},n={},o={},p=function(){function d(a,b){_classCallCheck(this,d),this.dom=a,this.config=b,this.prevRoot=null}return _createClass(d,[{key:"update",value:function(f){this.dom.classList.add("markdown");var a=j(f),c=v(this.prevRoot,a.root);this.prevRoot=a.root,b(c,this.dom);var d=m(this.config);d.useHighlight&&l(this.dom,d)}}]),d}();return s.Markdown=p,s.parser=e,s.trans=h,s.codeHighlight=l,s.getParseResult=j,s.markdown=function(e,a,b){e.innerHTML="",e.classList.add("markdown");var f=j(a);h(f.root,e),b=m(b),l(e,b)},s.markdownInfo=function(e){var a=j(e),b=a.root,c=_objectWithoutProperties(a,["root"]);return c},s}({}); | ||
"use strict";function _objectWithoutProperties(d,a){if(null==d)return{};var b,e,g=_objectWithoutPropertiesLoose(d,a);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(d);for(e=0;e<i.length;e++)b=i[e],!(0<=a.indexOf(b))&&Object.prototype.propertyIsEnumerable.call(d,b)&&(g[b]=d[b])}return g}function _objectWithoutPropertiesLoose(d,a){if(null==d)return{};var b,e,g={},i=Object.keys(d);for(e=0;e<i.length;e++)b=i[e],0<=a.indexOf(b)||(g[b]=d[b]);return g}function _classCallCheck(b,c){if(!(b instanceof c))throw new TypeError("Cannot call a class as a function")}function _defineProperties(d,a){for(var b,f=0;f<a.length;f++)b=a[f],b.enumerable=b.enumerable||!1,b.configurable=!0,"value"in b&&(b.writable=!0),Object.defineProperty(d,b.key,b)}function _createClass(d,a,b){return a&&_defineProperties(d.prototype,a),b&&_defineProperties(d,b),d}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(d,a,b){return a in d?Object.defineProperty(d,a,{value:b,enumerable:!0,configurable:!0,writable:!0}):d[a]=b,d}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(j){"use strict";function m(b,e){if(!b)return{type:"add",prevNode:b,nextNode:e};if(!e)return{type:"del",prevNode:b,nextNode:e};if(b.type!==e.type)return{type:"replace",prevNode:b,nextNode:e};var f={type:"update",prevNode:b,nextNode:e,propsChange:[],children:[]},c=l(b,e);if(c.length){var d;(d=f.propsChange).push.apply(d,_toConsumableArray(c))}return(f.children=k(b,e).filter(function(b){return b}),0<f.propsChange.length+f.children.length)?f:(e.__htmlNode=b.__htmlNode,e.__update=b.__update,f)}function k(f,g){var h=f.children,i=void 0===h?[]:h,b=g.children,a=void 0===b?[]:b,c=[],j=[],d=i.filter(function(b){return!!a.some(function(c){return c.type===b.type})||(c.push(m(b,null)),!1)});a.forEach(function(e){d.some(function(a,b){return a.type===e.type&&(d[b]={isDel:!0,ele:a},!0)})}),d.filter(function(b){return!b.isDel}).forEach(function(b){return c.push(m(b,null))});var k=d.filter(function(b){return b.isDel}).map(function(b){return b.ele});return a.forEach(function(g,d){var a=k.some(function(c,e){if(c.type===g.type){k.splice(e,1),k.splice(d>e?d-1:d,0,{used:!0,ele:c}),e!==d&&j.push({type:"move",prevNode:c,nextNode:g,current:e,moveTo:d>e?d+1:d});var b=m(c,g);return j.push(b),!0}return!1});if(!a){k.splice(d,0,{add:!0,item:g});var c=m(null,g);j.push(_objectSpread({},c,{moveTo:d}))}}),c.concat(j,[],[])}function l(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},f=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},g=Object.keys(e),d=Object.keys(f),a=[];return g.forEach(function(b){return["__htmlNode","__parent","__update","children","type"].includes(b)?void 0:d.includes(b)?void(e[b]!==f[b]&&a.push({type:"change",key:b,prevNode:e,nextNode:f})):void a.push({type:"del",key:b,prevNode:e,nextNode:f})}),d.forEach(function(b){g.includes(b)||a.push({type:"add",key:b,prevNode:e,nextNode:f})}),a}function n(){for(var b,d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",g=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"[",c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"]",e=0,k=-1,l=0,m=function(b){return d.slice(e,e+b.length)===b};e<d.length;){if(b=d[e],!l)if(!b.trim()){e+=1;continue}else if(m(g)){k=e,l+=1,e+=g.length;continue}else return[void 0,d];if(m(c)?(l-=1,e+=c.length):m(g)?(l+=1,e+=g.length):e+=1,!l)return[d.slice(k+g.length,e-c.length),d.slice(e)]}return[void 0,d]}function o(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",b=d.indexOf(a);return[d.slice(0,b),d.slice(b+a.length)]}function q(){function r(b,c){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},e=d.isPush,f=u;u=b,b.__parent=u,c&&c(),u=f,(void 0===e||e)&&u.children.push(b)}function j(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";i=i.slice(b.length)}function e(b){return[T.head,T.ul,T.code,T.queto].some(function(c){return c.test(b)})}function a(){function b(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,b=d.split("\n")[a].trim();return /^\|.+\|$/.test(b)?b.split("|").slice(1,-1):[]}var c=b(i,0),f=b(i,1),d=c.length;if(0!=d&&c.length==f.length&&f.every(function(b){return /^-+$/.test(b.replace(/\s/g,""))}))return r({type:"table",children:[]},function(){i=i.replace(/(.+)\n?/,function(c,a){return r({type:"thead",children:[]},function(){r({type:"tr",children:[]},function(){a.trim().split("|").slice(1,-1).map(function(a){r({type:"th",children:[]},function(){g(a)})})})}),""}),i=i.replace(/.+\n?/,""),r({type:"tbody",children:[]},function(){for(var a,c=function a(){var a=(i.match(/^.+\n?/)||[])[0];return a?e(a)?"break":void(i=i.replace(a,""),r({type:"tr",children:[]},function(){var b,f=a.trim().split("|");f=f[0]?f.slice(0,d):f.slice(1).slice(0,d),(b=f).push.apply(b,_toConsumableArray(Array(d-f.length).fill(""))),f.forEach(function(a){r({type:"td",children:[]},function(){g(a)})})})):"break"};a=c(),"break"!==a;);})}),!0}function g(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(a){if(T.url.test(a))return void g(a.replace(T.url,function(a,b,c){return r({type:"a",href:c,value:b,children:[]},function(){g(b)}),""}));if(T.blod.test(a))return void g(a.replace(T.blod,function(c,a){return r({type:"b",children:[]},function(){g(a)}),""}));if(T.italic.test(a))return void g(a.replace(T.italic,function(c,a){return r({type:"i",children:[]},function(){g(a)}),""}));if(T.inlineCode.test(a))return void g(a.replace(T.inlineCode,function(c,a){return a&&r({type:"inlineCode",children:[]},function(){g(a)}),""}));if(T.video.test(a))return void g(a.replace(T.video,function(d,a,b){return u.children.push({type:"video",src:b,alt:a}),""}));if(T.audio.test(a))return a=a.replace(T.audio,function(d,a,b){return u.children.push({type:"audio",src:b,alt:a}),""}),void g(a);if(T.img.test(a))return void g(a.replace(T.img,function(d,a,b){return u.children.push({type:"img",src:b,alt:a}),""}));if("\n"==a[0])return u.children.push({type:"br"}),void g(a.slice(1));var b=u.children[u.children.length-1];b&&"text"===b.type?b.value+=a[0]:u.children.push({type:"text",value:h(a[0])}),g(a.slice(1))}}function h(b){return b.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function c(){function i(){var a=Math.floor,g=0<arguments.length&&void 0!==arguments[0]?arguments[0]:-1;if(f){var j=(f.match(/.+\n?/)||[])[0],c=j.match(/\s*/)[0],e=a(c.length/5);if(/^[-+]\s+/.test(j.trim())){var d="+"==j.match(/\s*[-+]/)[0].trim();if(e==g+1){var k={type:"ul",listStyleType:d?"decimal":b[e%b.length],children:[]};return r(k,function(){i(g+1)}),void i(g)}if(e==g)return r({type:"li",children:[]},function(){g(j.replace(/\s*[-+]\s*/,""))}),f=f.slice(j.length),void i(g);if(e<g)return}var l=u.children[u.children.length-1];r(l,function(){g(j)},{isPush:!1}),f=f.slice(j.length),i(g)}}var f=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";f="".concat(f,"\n");var b=["disc","circle","square"];i()}function f(){if(!/^\n{1,2}$/.test(i)&&i){if(/Reg.br/.test(i)){var b=i.match(T.br),d=_slicedToArray(b,1),e=d[0];return u.children.push({type:"br"}),j(e),void f()}if(T.head.test(i)){var p=i.match(T.head)||[],h=_slicedToArray(p,3),k=h[0],l=h[1],m=h[2],E={type:"h".concat(l.length),children:[]};return r(E,function(){g(m)}),j(k),void f()}if(T.queto.test(i)){var U=i.match(T.queto),V=_slicedToArray(U,2),W=V[0],s=V[1],t=n(s,"[","]"),v=_slicedToArray(t,2),w=v[0],x=v[1],y={type:"queto",tag:w,children:[]},z=q(x.replace(/^\s*\n/,""));return y.children=z.children,u.children.push(y),u.children.push({type:"br"}),j(W),void f()}if(T.code.test(i)){var A=i.match(T.code),B=_slicedToArray(A,2),C=B[0],D=B[1],X=o(D,"\n").map(function(b){return b.trim()}),F=_slicedToArray(X,2),G=F[0],H=F[1];return u.children.push({type:"code",language:G,value:H}),j(C),void f()}if(T.ul.test(i)){var I=i.match(T.ul),J=_slicedToArray(I,2),K=J[0],L=J[1];return r(u,function(){c(L)},{isPush:!1}),u.children.push({type:"br"}),j(K),void f()}if(i.match(/.+\n/)&&/\|.+\|/.test(i.match(/.+\n/)[0].trim())&&a(i))return void f();if(T.hr.test(i)){var M=i.match(T.hr)||[],N=_slicedToArray(M,1),O=N[0];return void 0!==O&&u.children.push({type:"hr",children:[]}),j(O),void f()}if(T.text.test(i)){var P=i.match(T.text)||[""],Q=_slicedToArray(P,1),R=Q[0];return g(R),j(R),void f()}throw new Error("cannot handle str:".concat(i))}}var i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";i+="\n\n";var u={children:[],type:"root"};return f(),u}function p(b,c){return c&&c.parentElement&&c.parentElement.insertBefore(b,c),b}function r(a){var d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(a){var c=a.nextNode;switch(a.type){case"del":{var e=a.prevNode.__htmlNode;e.parentElement||console.log("delete error::",a),e.parentElement.removeChild(e);break}case"add":{s(c,d,{beforeAppend:function(e){var b=d.childNodes[a.moveTo];if(b)return p(e,b),!0}});break}case"replace":{var f=a.prevNode.__htmlNode,g=document.createDocumentFragment();s(c,g),f.parentElement.replaceChild(g,f);break}case"move":{var b=a.moveTo,n=a.prevNode,h=n.__htmlNode.parentElement;h.childNodes[b]!==n.__htmlNode&&(h.childNodes[b]?p(n.__htmlNode,h.childNodes[b]):h.appendChild(n.__htmlNode));break}case"update":{var i=a.propsChange,k=a.children,o=a.prevNode,j=a.nextNode,l=o.__htmlNode;j.__htmlNode=l,o.__update&&(j.__update=o.__update),i.forEach(function(d){var a=d.key;switch(d.type){case"change":case"add":{var b=j[a];if(o.__update){o.__update(a,j);break}if(l instanceof Text){l.data=b;break}l.setAttribute(a,b);break}case"del":{l.removeAttribute(a);break}}}),k.forEach(function(b){return r(b,l)});break}default:console.error("canot handle type",a,a.type);}}}function u(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+=u(b)}),d}function s(a,d){var e,j=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(a.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(a.src.trim())){e=document.createElement("div"),e.className="audio",e.innerHTML=a.src.replace("http://","//");var p=e.querySelector("iframe");p.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else e=document.createElement(a.type),e.src=a.src,e.alt=a.alt,e.controls="true";break}case"img":{var f=a.src.match(/\.(\d+)x(\d+)\./);if(f){var b=f.slice(1,3),g=_slicedToArray(b,2),h=g[0],k=g[1],q=a.src;e=document.createElement("div"),e.style.cssText=";position: relative; max-width: ".concat(h,"px; overflow: hidden; background: rgb(219, 221, 215);"),e.innerHTML="<div style=\"padding-top: ".concat(100*(k/h),"%;\">\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(a.src,"\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>");break}else{e=document.createElement(a.type),e.src=a.src,e.alt=a.alt;break}}case"text":{var r=a.value;e=document.createTextNode(r);break}case"br":{e=document.createElement(a.type);break}case"a":{e=document.createElement(a.type),e.href=a.href,e.target="_blank";break}case"code":{e=document.createElement("pre");var i=document.createElement("code");a.__update=function(b,c){switch(b){case"language":{i.className=["highlight",c[b]||""].join(" ");break}case"value":{i.textContent=c[b];break}default:}},a.__update("language",a),a.__update("value",a),e.appendChild(i);break}case"inlineCode":{e=document.createElement("code"),e.className="inlineCode";break}case"h1":{e=document.createElement(a.type);var l=document.createElement("a"),m=u(a);l.href="#".concat(m),l.id=m,e.appendChild(l);break}case"ul":{e=document.createElement(a.type),a.__update=function(b,c){e.style.cssText+=";list-style-type:".concat(c[b],";")},a.__update("listStyleType",a);break}default:e=document.createElement(a.type),a.indent&&(e.style.cssText+=";padding-left: 2em;"),"table"==a.type&&e.setAttribute("border","1");}a.tag&&e.setAttribute("tag",a.tag),a.children&&a.children.forEach(function(a){return s(a,e)});var n=j.beforeAppend&&j.beforeAppend(e);return n||d.appendChild(e),a.__htmlNode=e,e}function c(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 a(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=h[d];if(!a){var f=q(d);a=_objectSpread({root:f},c(f)),h[d]=a}return a}function d(b){return new Promise(function(c){if(v[b])return c();var d=function(){v[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 t(b,c){Promise.all(c.asset.map(d)).then(function(){window.hljs&&b&&(window.hljs.configure({tabReplace:4}),_toConsumableArray(b.querySelectorAll("code.highlight")).forEach(function(b){window.hljs.highlightBlock(b)}))})}function g(b){return _objectSpread({asset:[]},b)}var T={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 /^!\[([^\]]*)\]\(([^)]+)\)/}},h={},v={},e=function(){function d(a,b){_classCallCheck(this,d),this.dom=a,this.config=b,this.prevRoot=null}return _createClass(d,[{key:"update",value:function(c){this.dom.classList.add("markdown");var d=a(c),e=m(this.prevRoot,d.root);this.prevRoot=d.root,r(e,this.dom);var b=g(this.config);b.useHighlight&&t(this.dom,b)}}]),d}();return j.Markdown=e,j.parser=q,j.trans=s,j.codeHighlight=t,j.getParseResult=a,j.markdown=function(d,e,b){d.innerHTML="",d.classList.add("markdown");var f=a(e);s(f.root,d),b=g(b),t(d,b)},j.markdownInfo=function(f){var b=a(f),c=b.root,d=_objectWithoutProperties(b,["root"]);return d},j}({}); |
@@ -330,2 +330,6 @@ "use strict"; | ||
get lineThrough() { | ||
return /^~{2}(((?!~{2}).)*)~{2}/; | ||
}, | ||
get italic() { | ||
@@ -618,2 +622,17 @@ return /^\*{2}(((?!\*{2}).)*)\*{2}/; | ||
return; | ||
} // 中划线 | ||
if (Reg.lineThrough.test(textStr)) { | ||
handleText(textStr.replace(Reg.lineThrough, function (m, $0) { | ||
var child = { | ||
type: 'lineThrough', | ||
children: [] | ||
}; | ||
changeCurrentNode(child, function () { | ||
handleText($0); | ||
}); | ||
return ''; | ||
})); | ||
return; | ||
} // 倾斜 | ||
@@ -1260,2 +1279,9 @@ | ||
case 'lineThrough': | ||
{ | ||
ele = document.createElement('span'); | ||
ele.style.cssText += ";text-decoration: line-through;"; | ||
break; | ||
} | ||
default: | ||
@@ -1262,0 +1288,0 @@ { |
{ | ||
"name": "lys-markdown-parser", | ||
"version": "1.1.7", | ||
"version": "1.1.10", | ||
"description": "js markdown parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -44,2 +44,5 @@ /* | ||
}, | ||
get lineThrough() { | ||
return /^~{2}(((?!~{2}).)*)~{2}/ | ||
}, | ||
get italic() { | ||
@@ -308,2 +311,17 @@ return /^\*{2}(((?!\*{2}).)*)\*{2}/ | ||
// 中划线 | ||
if (Reg.lineThrough.test(textStr)) { | ||
handleText(textStr.replace(Reg.lineThrough, (m, $0) => { | ||
const child = { | ||
type: 'lineThrough', | ||
children: [], | ||
} | ||
changeCurrentNode(child, () => { | ||
handleText($0) | ||
}) | ||
return '' | ||
})) | ||
return | ||
} | ||
// 倾斜 | ||
@@ -310,0 +328,0 @@ if (Reg.italic.test(textStr)) { |
@@ -149,2 +149,7 @@ /** | ||
} | ||
case 'lineThrough': { | ||
ele = document.createElement('span') | ||
ele.style.cssText += `;text-decoration: line-through;` | ||
break | ||
} | ||
default: | ||
@@ -151,0 +156,0 @@ { |
Sorry, the diff of this file is not supported yet
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
4020
189619
16