Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lys-markdown-parser

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lys-markdown-parser - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

3

dist/index.js

@@ -1121,3 +1121,3 @@ 'use strict';

// 不能是连续的``
if (helper.isType(tokens[index], TOKEN_TYPE.CODE_BLOCK) || helper.isType(tokens[index + 1], TOKEN_TYPE.CODE_BLOCK)) {
if (helper.isType(tokens[index], TOKEN_TYPE.CODE_BLOCK) && helper.isType(tokens[index + 1], TOKEN_TYPE.CODE_BLOCK)) {
return false;

@@ -2241,3 +2241,2 @@ }

var diffResult = diffNode(this.prevRoot, result.root);
console.log(diffResult, this.prevRoot, result.root);
this.prevRoot = result.root;

@@ -2244,0 +2243,0 @@ patch(diffResult, this.dom);

@@ -1,1 +0,1 @@

"use strict";function _objectWithoutProperties(d,a){if(null==d)return{};var b,e,h=_objectWithoutPropertiesLoose(d,a);if(Object.getOwnPropertySymbols){var g=Object.getOwnPropertySymbols(d);for(e=0;e<g.length;e++)b=g[e],!(0<=a.indexOf(b))&&Object.prototype.propertyIsEnumerable.call(d,b)&&(h[b]=d[b])}return h}function _objectWithoutPropertiesLoose(d,a){if(null==d)return{};var b,e,h={},g=Object.keys(d);for(e=0;e<g.length;e++)b=g[e],0<=a.indexOf(b)||(h[b]=d[b]);return h}function _classCallCheck(a,b){if(!(a instanceof b))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(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(d,c){var e,a=[],b=!0,k=!1;try{for(var l,m=d[Symbol.iterator]();!(b=(l=m.next()).done)&&(a.push(l.value),!(c&&a.length===c));b=!0);}catch(b){k=!0,e=b}finally{try{b||null==m["return"]||m["return"]()}finally{if(k)throw e}}return a}function _arrayWithHoles(b){if(Array.isArray(b))return b}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(b){return Object.getOwnPropertyDescriptor(f,b).enumerable}))),d.forEach(function(b){_defineProperty(a,b,f[b])})}return a}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(a){if(Array.isArray(a)){for(var b=0,e=Array(a.length);b<a.length;b++)e[b]=a[b];return e}}var fuckMD=function(d){"use strict";function h(h,a){if(!h)return{type:"add",prevNode:h,nextNode:a};if(!a)return{type:"del",prevNode:h,nextNode:a};if(h.type!==a.type)return{type:"replace",prevNode:h,nextNode:a};var b={type:"update",prevNode:h,nextNode:a,propsChange:[],children:[]},c=g(h,a);if(c.length){var d;(d=b.propsChange).push.apply(d,_toConsumableArray(c))}return(b.children=f(h,a).filter(function(b){return b}),0<b.propsChange.length+b.children.length)?b:(a.__htmlNode=h.__htmlNode,a.__update=h.__update,b)}function f(g,i){var j=g.children,k=void 0===j?[]:j,d=i.children,c=void 0===d?[]:d,e=[],l=[],a=k.filter(function(a){return!!c.some(function(b){return b.type===a.type})||(e.push(h(a,null)),!1)});c.forEach(function(b){a.some(function(e,d){return e.type===b.type&&(a[d]={isDel:!0,ele:e},!0)})}),a.filter(function(b){return!b.isDel}).forEach(function(a){return e.push(h(a,null))});var m=a.filter(function(b){return b.isDel}).map(function(b){return b.ele});return c.forEach(function(d,e){var c=m.some(function(f,a){if(f.type===d.type){m.splice(a,1),m.splice(e>a?e-1:e,0,{used:!0,ele:f}),a!==e&&l.push({type:"move",prevNode:f,nextNode:d,current:a,moveTo:e>a?e+1:e});var b=h(f,d);return l.push(b),!0}return!1});if(!c){m.splice(e,0,{add:!0,item:d});var a=h(null,d);l.push(_objectSpread({},a,{moveTo:e}))}}),e.concat(l,[],[])}function g(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},b=Object.keys(e),d=Object.keys(a),f=[];return b.forEach(function(b){return["__htmlNode","__parent","__update","children","type"].includes(b)?void 0:d.includes(b)?void(e[b]!==a[b]&&f.push({type:"change",key:b,prevNode:e,nextNode:a})):void f.push({type:"del",key:b,prevNode:e,nextNode:a})}),d.forEach(function(c){b.includes(c)||f.push({type:"add",key:c,prevNode:e,nextNode:a})}),f}function b(){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 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 m(d,e){var f=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},a=f.isPush,b=o;o=d,d.__parent=o,e&&e(),o=b,(void 0===a||a)&&o.children.push(d)}function l(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";p=p.slice(b.length)}function h(a){return[R.head,R.ul,R.code,R.queto].some(function(b){return b.test(a)})}function n(){function c(){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 a=c(p,0),d=c(p,1),b=a.length;if(0!=b&&a.length==d.length&&d.every(function(b){return /^-+$/.test(b.replace(/\s/g,""))}))return m({type:"table",children:[]},function(){p=p.replace(/(.+)\n?/,function(b,c){return m({type:"thead",children:[]},function(){m({type:"tr",children:[]},function(){c.trim().split("|").slice(1,-1).map(function(a){m({type:"th",children:[]},function(){f(a)})})})}),""}),p=p.replace(/.+\n?/,""),m({type:"tbody",children:[]},function(){for(var c,d=function c(){var c=(p.match(/^.+\n?/)||[])[0];return c?h(c)?"break":void(p=p.replace(c,""),m({type:"tr",children:[]},function(){var a,d=c.trim().split("|");d=d[0]?d.slice(0,b):d.slice(1).slice(0,b),(a=d).push.apply(a,_toConsumableArray(Array(b-d.length).fill(""))),d.forEach(function(a){m({type:"td",children:[]},function(){f(a)})})})):"break"};c=d(),"break"!==c;);})}),!0}function f(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(a){if(R.url.test(a))return void f(a.replace(R.url,function(a,b,c){return m({type:"a",href:c,value:b,children:[]},function(){f(b)}),""}));if(R.blod.test(a))return void f(a.replace(R.blod,function(b,c){return m({type:"b",children:[]},function(){f(c)}),""}));if(R.italic.test(a))return void f(a.replace(R.italic,function(b,c){return m({type:"i",children:[]},function(){f(c)}),""}));if(R.inlineCode.test(a))return void f(a.replace(R.inlineCode,function(b,c){return c&&m({type:"inlineCode",children:[]},function(){f(c)}),""}));if(R.video.test(a))return void f(a.replace(R.video,function(d,a,b){return o.children.push({type:"video",src:b,alt:a}),""}));if(R.audio.test(a))return a=a.replace(R.audio,function(d,a,b){return o.children.push({type:"audio",src:b,alt:a}),""}),void f(a);if(R.img.test(a))return void f(a.replace(R.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 f(a.slice(1));var b=o.children[o.children.length-1];b&&"text"===b.type?b.value+=a[0]:o.children.push({type:"text",value:c(a[0])}),f(a.slice(1))}}function c(b){return b.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function g(){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 m(i,function(){g(c+1)}),void g(c)}if(k==c)return m({type:"li",children:[]},function(){c(e.replace(/\s*[-+]\s*/,""))}),j=j.slice(e.length),void g(c);if(k<c)return}var l=o.children[o.children.length-1];m(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 a(){if(!/^\n{1,2}$/.test(p)&&p){if(/Reg.br/.test(p)){var c=p.match(R.br),d=_slicedToArray(c,1),q=d[0];return o.children.push({type:"br"}),l(q),void a()}if(R.head.test(p)){var j=p.match(R.head)||[],D=_slicedToArray(j,3),h=D[0],S=D[1],k=D[2],T={type:"h".concat(S.length),children:[]};return m(T,function(){f(k)}),l(h),void a()}if(R.queto.test(p)){var w=p.match(R.queto),U=_slicedToArray(w,2),V=U[0],s=U[1],t=b(s,"[","]"),u=_slicedToArray(t,2),x=u[0],y=u[1],r={type:"queto",tag:x,children:[]},z=e(y.replace(/^\s*\n/,""));return r.children=z.children,o.children.push(r),o.children.push({type:"br"}),l(V),void a()}if(R.code.test(p)){var A=p.match(R.code),B=_slicedToArray(A,2),C=B[0],v=B[1],X=i(v,"\n").map(function(b){return b.trim()}),F=_slicedToArray(X,2),G=F[0],H=F[1];return o.children.push({type:"code",language:G,value:H}),l(C),void a()}if(R.ul.test(p)){var I=p.match(R.ul),J=_slicedToArray(I,2),K=J[0],L=J[1];return m(o,function(){g(L)},{isPush:!1}),o.children.push({type:"br"}),l(K),void a()}if(p.match(/.+\n/)&&/\|.+\|/.test(p.match(/.+\n/)[0].trim())&&n(p))return void a();if(R.hr.test(p)){var M=p.match(R.hr)||[],N=_slicedToArray(M,1),O=N[0];return void 0!==O&&o.children.push({type:"hr",children:[]}),l(O),void a()}if(R.text.test(p)){var W=p.match(R.text)||[""],P=_slicedToArray(W,1),E=P[0];return f(E),l(E),void a()}throw new Error("cannot handle str:".concat(p))}}var p=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";p+="\n\n";var o={children:[],type:"root"};return a(),o}function j(a,b){return b&&b.parentElement&&b.parentElement.insertBefore(a,b),a}function l(p){var o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(p){var m=p.nextNode;switch(p.type){case"del":{var c=p.prevNode.__htmlNode;c.parentElement||console.log("delete error::",p),c.parentElement.removeChild(c);break}case"add":{n(m,o,{beforeAppend:function(b){var c=o.childNodes[p.moveTo];if(c)return j(b,c),!0}});break}case"replace":{var b=p.prevNode.__htmlNode,d=document.createDocumentFragment();n(m,d),b.parentElement.replaceChild(d,b);break}case"move":{var f=p.moveTo,e=p.prevNode,g=e.__htmlNode.parentElement;g.childNodes[f]!==e.__htmlNode&&(g.childNodes[f]?j(e.__htmlNode,g.childNodes[f]):g.appendChild(e.__htmlNode));break}case"update":{var h=p.propsChange,a=p.children,i=p.prevNode,q=p.nextNode,r=i.__htmlNode;q.__htmlNode=r,i.__update&&(q.__update=i.__update),h.forEach(function(c){var d=c.key;switch(c.type){case"change":case"add":{var a=q[d];if(i.__update){i.__update(d,q);break}if(r instanceof Text){r.data=a;break}r.setAttribute(d,a);break}case"del":{r.removeAttribute(d);break}}}),a.forEach(function(a){return l(a,r)});break}default:console.error("canot handle type",p,p.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 n(c,f){var a,q=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(c.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(c.src.trim())){a=document.createElement("div"),a.className="audio",a.innerHTML=c.src.replace("http://","//");var o=a.querySelector("iframe");o.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else a=document.createElement(c.type),a.src=c.src,a.alt=c.alt,a.controls="true";break}case"img":{var d=c.src.match(/\.(\d+)x(\d+)\./);if(d){var e=d.slice(1,3),g=_slicedToArray(e,2),h=g[0],i=g[1],j=c.src;a=document.createElement("div"),a.style.cssText=";position: relative; max-width: ".concat(h,"px; overflow: hidden; background: rgb(219, 221, 215);"),a.innerHTML="<div style=\"padding-top: ".concat(100*(i/h),"%;\">\n <img ").concat(LY.lazyLoad.caches.includes(j)?"src=\"".concat(j,"\" data-img-cache=\"true\""):"","\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(c.src,"\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>");break}else{a=document.createElement(c.type),a.src=c.src,a.alt=c.alt;break}}case"text":{var r=c.value;a=document.createTextNode(r);break}case"br":{a=document.createElement(c.type);break}case"a":{a=document.createElement(c.type),a.href=c.href,a.target="_blank";break}case"code":{a=document.createElement("pre");var l=document.createElement("code");c.__update=function(a,b){switch(a){case"language":{l.className=["highlight",b[a]||""].join(" ");break}case"value":{l.textContent=b[a];break}default:}},c.__update("language",c),c.__update("value",c),a.appendChild(l);break}case"inlineCode":{a=document.createElement("code"),a.className="inlineCode";break}case"h1":{a=document.createElement(c.type);var m=document.createElement("a"),p=k(c);m.href="#".concat(p),m.id=p,a.appendChild(m);break}case"ul":{a=document.createElement(c.type),c.__update=function(b,c){a.style.cssText+=";list-style-type:".concat(c[b],";")},c.__update("listStyleType",c);break}default:a=document.createElement(c.type),c.indent&&(a.style.cssText+=";padding-left: 2em;"),"table"==c.type&&a.setAttribute("border","1");}c.tag&&a.setAttribute("tag",c.tag),c.children&&c.children.forEach(function(b){return n(b,a)});var s=q.beforeAppend&&q.beforeAppend(a);return s||f.appendChild(a),c.__htmlNode=a,a}function m(b){function c(b){"text"==b.type&&(d+=b.value||""),"img"==b.type&&g.push(b.src),b.children&&b.children.forEach(c)}var d="",g=[];return c(b),{text:d,imgs:g}}function o(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=s[a];if(!b){var c=e(a);b=_objectSpread({root:c},m(c)),s[a]=b}return b}function p(d){return new Promise(function(e){if(t[d])return e();var f=function(){t[d]=!0,e()};if(d.endsWith(".js")){var a=document.createElement("script");a.onload=f,a.src=d,document.head.appendChild(a)}else if(d.endsWith(".css")){var b=document.createElement("link");b.onload=f,b.type="text/css",b.rel="stylesheet",b.charset="utf-8",b.href=d,document.head.appendChild(b)}})}function q(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(b){window.hljs.highlightBlock(b)}))})}function r(b){return _objectSpread({asset:[]},b)}var R={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 /^!\[([^\]]*)\]\(([^)]+)\)/}},s={},t={},a=function(){function c(a,d){_classCallCheck(this,c),this.dom=a,this.config=d,this.prevRoot=null}return _createClass(c,[{key:"update",value:function(e){this.dom.classList.add("markdown");var c=o(e),a=h(this.prevRoot,c.root);this.prevRoot=c.root,l(a,this.dom);var d=r(this.config);d.useHighlight&&q(this.dom,d)}}]),c}();return d.Markdown=a,d.parser=e,d.trans=n,d.codeHighlight=q,d.getParseResult=o,d.markdown=function(e,c,b){e.innerHTML="",e.classList.add("markdown");var f=o(c);n(f.root,e),b=r(b),q(e,b)},d.markdownInfo=function(c){var d=o(c),a=d.root,e=_objectWithoutProperties(d,["root"]);return e},d}({});
"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(b,e){var d,f=[],g=!0,k=!1;try{for(var l,m=b[Symbol.iterator]();!(g=(l=m.next()).done)&&(f.push(l.value),!(e&&f.length===e));g=!0);}catch(b){k=!0,d=b}finally{try{g||null==m["return"]||m["return"]()}finally{if(k)throw d}}return f}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(a){"use strict";function s(d,e){if(!d)return{type:"add",prevNode:d,nextNode:e};if(!e)return{type:"del",prevNode:d,nextNode:e};if(d.type!==e.type)return{type:"replace",prevNode:d,nextNode:e};var f={type:"update",prevNode:d,nextNode:e,propsChange:[],children:[]},a=u(d,e);if(a.length){var b;(b=f.propsChange).push.apply(b,_toConsumableArray(a))}return(f.children=t(d,e).filter(function(b){return b}),0<f.propsChange.length+f.children.length)?f:(e.__htmlNode=d.__htmlNode,e.__update=d.__update,f)}function t(a,b){var e=a.children,f=void 0===e?[]:e,g=b.children,h=void 0===g?[]:g,d=[],i=[],j=f.filter(function(b){return!!h.some(function(c){return c.type===b.type})||(d.push(s(b,null)),!1)});h.forEach(function(d){j.some(function(a,b){return a.type===d.type&&(j[b]={isDel:!0,ele:a},!0)})}),j.filter(function(b){return!b.isDel}).forEach(function(a){return d.push(s(a,null))});var k=j.filter(function(b){return b.isDel}).map(function(b){return b.ele});return h.forEach(function(f,g){var a=k.some(function(b,c){if(b.type===f.type){k.splice(c,1),k.splice(g>c?g-1:g,0,{used:!0,ele:b}),c!==g&&i.push({type:"move",prevNode:b,nextNode:f,current:c,moveTo:g>c?g+1:g});var d=s(b,f);return i.push(d),!0}return!1});if(!a){k.splice(g,0,{add:!0,item:f});var b=s(null,f);i.push(_objectSpread({},b,{moveTo:g}))}}),d.concat(i,[],[])}function u(){var f=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},g=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},e=Object.keys(f),b=Object.keys(g),c=[];return e.forEach(function(d){return["__htmlNode","__parent","__update","children","type"].includes(d)?void 0:b.includes(d)?void(f[d]!==g[d]&&c.push({type:"change",key:d,prevNode:f,nextNode:g})):void c.push({type:"del",key:d,prevNode:f,nextNode:g})}),b.forEach(function(a){e.includes(a)||c.push({type:"add",key:a,prevNode:f,nextNode:g})}),c}function c(){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 d(){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 b(){function r(b,c){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},e=d.isPush,f=o;o=b,b.__parent=o,c&&c(),o=f,(void 0===e||e)&&o.children.push(b)}function g(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";m=m.slice(b.length)}function a(b){return[E.head,E.ul,E.code,E.queto].some(function(c){return c.test(b)})}function e(){function b(){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 d=b(m,0),c=b(m,1),g=d.length;if(0!=g&&d.length==c.length&&c.every(function(b){return /^-+$/.test(b.replace(/\s/g,""))}))return r({type:"table",children:[]},function(){m=m.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(){i(a)})})})}),""}),m=m.replace(/.+\n?/,""),r({type:"tbody",children:[]},function(){for(var c,d=function d(){var d=(m.match(/^.+\n?/)||[])[0];return d?a(d)?"break":void(m=m.replace(d,""),r({type:"tr",children:[]},function(){var a,b=d.trim().split("|");b=b[0]?b.slice(0,g):b.slice(1).slice(0,g),(a=b).push.apply(a,_toConsumableArray(Array(g-b.length).fill(""))),b.forEach(function(a){r({type:"td",children:[]},function(){i(a)})})})):"break"};c=d(),"break"!==c;);})}),!0}function i(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(a){if(E.url.test(a))return void i(a.replace(E.url,function(c,d,a){return r({type:"a",href:a,value:d,children:[]},function(){i(d)}),""}));if(E.blod.test(a))return void i(a.replace(E.blod,function(c,a){return r({type:"b",children:[]},function(){i(a)}),""}));if(E.italic.test(a))return void i(a.replace(E.italic,function(c,a){return r({type:"i",children:[]},function(){i(a)}),""}));if(E.inlineCode.test(a))return void i(a.replace(E.inlineCode,function(c,a){return a&&r({type:"inlineCode",children:[]},function(){i(a)}),""}));if(E.video.test(a))return void i(a.replace(E.video,function(b,c,d){return o.children.push({type:"video",src:d,alt:c}),""}));if(E.audio.test(a))return a=a.replace(E.audio,function(b,c,d){return o.children.push({type:"audio",src:d,alt:c}),""}),void i(a);if(E.img.test(a))return void i(a.replace(E.img,function(b,c,d){return o.children.push({type:"img",src:d,alt:c}),""}));if("\n"==a[0])return o.children.push({type:"br"}),void i(a.slice(1));var b=o.children[o.children.length-1];b&&"text"===b.type?b.value+=a[0]:o.children.push({type:"text",value:h(a[0])}),i(a.slice(1))}}function h(b){return b.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function f(){function l(){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(){l(g+1)}),void l(g)}if(e==g)return r({type:"li",children:[]},function(){g(j.replace(/\s*[-+]\s*/,""))}),f=f.slice(j.length),void l(g);if(e<g)return}var h=o.children[o.children.length-1];r(h,function(){g(j)},{isPush:!1}),f=f.slice(j.length),l(g)}}var f=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";f="".concat(f,"\n");var b=["disc","circle","square"];l()}function l(){if(!/^\n{1,2}$/.test(m)&&m){if(/Reg.br/.test(m)){var h=m.match(E.br),a=_slicedToArray(h,1),n=a[0];return o.children.push({type:"br"}),g(n),void l()}if(E.head.test(m)){var q=m.match(E.head)||[],D=_slicedToArray(q,3),j=D[0],p=D[1],Q=D[2],R={type:"h".concat(p.length),children:[]};return r(R,function(){i(Q)}),g(j),void l()}if(E.queto.test(m)){var k=m.match(E.queto),S=_slicedToArray(k,2),w=S[0],T=S[1],U=c(T,"[","]"),s=_slicedToArray(U,2),t=s[0],u=s[1],x={type:"queto",tag:t,children:[]},y=b(u.replace(/^\s*\n/,""));return x.children=y.children,o.children.push(x),o.children.push({type:"br"}),g(w),void l()}if(E.code.test(m)){var V=m.match(E.code),z=_slicedToArray(V,2),A=z[0],B=z[1],C=d(B,"\n").map(function(b){return b.trim()}),v=_slicedToArray(C,2),X=v[0],F=v[1];return o.children.push({type:"code",language:X,value:F}),g(A),void l()}if(E.ul.test(m)){var G=m.match(E.ul),H=_slicedToArray(G,2),I=H[0],J=H[1];return r(o,function(){f(J)},{isPush:!1}),o.children.push({type:"br"}),g(I),void l()}if(m.match(/.+\n/)&&/\|.+\|/.test(m.match(/.+\n/)[0].trim())&&e(m))return void l();if(E.hr.test(m)){var K=m.match(E.hr)||[],L=_slicedToArray(K,1),M=L[0];return void 0!==M&&o.children.push({type:"hr",children:[]}),g(M),void l()}if(E.text.test(m)){var N=m.match(E.text)||[""],O=_slicedToArray(N,1),W=O[0];return i(W),g(W),void l()}throw new Error("cannot handle str:".concat(m))}}var m=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";m+="\n\n";var o={children:[],type:"root"};return l(),o}function g(b,c){return c&&c.parentElement&&c.parentElement.insertBefore(b,c),b}function f(h){var j=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(h){var a=h.nextNode;switch(h.type){case"del":{var k=h.prevNode.__htmlNode;k.parentElement||console.log("delete error::",h),k.parentElement.removeChild(k);break}case"add":{i(a,j,{beforeAppend:function(c){var a=j.childNodes[h.moveTo];if(a)return g(c,a),!0}});break}case"replace":{var l=h.prevNode.__htmlNode,c=document.createDocumentFragment();i(a,c),l.parentElement.replaceChild(c,l);break}case"move":{var b=h.moveTo,d=h.prevNode,m=d.__htmlNode.parentElement;m.childNodes[b]!==d.__htmlNode&&(m.childNodes[b]?g(d.__htmlNode,m.childNodes[b]):m.appendChild(d.__htmlNode));break}case"update":{var e=h.propsChange,n=h.children,o=h.prevNode,p=h.nextNode,r=o.__htmlNode;p.__htmlNode=r,o.__update&&(p.__update=o.__update),e.forEach(function(a){var b=a.key;switch(a.type){case"change":case"add":{var c=p[b];if(o.__update){o.__update(b,p);break}if(r instanceof Text){r.data=c;break}r.setAttribute(b,c);break}case"del":{r.removeAttribute(b);break}}}),n.forEach(function(a){return f(a,r)});break}default:console.error("canot handle type",h,h.type);}}}function h(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+=h(a)}),c}function i(a,b){var c,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(a.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(a.src.trim())){c=document.createElement("div"),c.className="audio",c.innerHTML=a.src.replace("http://","//");var j=c.querySelector("iframe");j.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else c=document.createElement(a.type),c.src=a.src,c.alt=a.alt,c.controls="true";break}case"img":{var k=a.src.match(/\.(\d+)x(\d+)\./);if(k){var n=k.slice(1,3),d=_slicedToArray(n,2),o=d[0],g=d[1],q=a.src;c=document.createElement("div"),c.style.cssText=";position: relative; max-width: ".concat(o,"px; overflow: hidden; background: rgb(219, 221, 215);"),c.innerHTML="<div style=\"padding-top: ".concat(100*(g/o),"%;\">\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{c=document.createElement(a.type),c.src=a.src,c.alt=a.alt;break}}case"text":{var s=a.value;c=document.createTextNode(s);break}case"br":{c=document.createElement(a.type);break}case"a":{c=document.createElement(a.type),c.href=a.href,c.target="_blank";break}case"code":{c=document.createElement("pre");var t=document.createElement("code");a.__update=function(b,c){switch(b){case"language":{t.className=["highlight",c[b]||""].join(" ");break}case"value":{t.textContent=c[b];break}default:}},a.__update("language",a),a.__update("value",a),c.appendChild(t);break}case"inlineCode":{c=document.createElement("code"),c.className="inlineCode";break}case"h1":{c=document.createElement(a.type);var r=document.createElement("a"),l=h(a);r.href="#".concat(l),r.id=l,c.appendChild(r);break}case"ul":{c=document.createElement(a.type),a.__update=function(d,a){c.style.cssText+=";list-style-type:".concat(a[d],";")},a.__update("listStyleType",a);break}default:c=document.createElement(a.type),a.indent&&(c.style.cssText+=";padding-left: 2em;"),"table"==a.type&&c.setAttribute("border","1");}a.tag&&c.setAttribute("tag",a.tag),a.children&&a.children.forEach(function(b){return i(b,c)});var m=e.beforeAppend&&e.beforeAppend(c);return m||b.appendChild(c),a.__htmlNode=c,c}function j(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 k(){var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",d=n[c];if(!d){var f=b(c);d=_objectSpread({root:f},j(f)),n[c]=d}return d}function e(b){return new Promise(function(c){if(o[b])return c();var d=function(){o[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 l(c,b){Promise.all(b.asset.map(e)).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 E={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(b,c){_classCallCheck(this,d),this.dom=b,this.config=c,this.prevRoot=null}return _createClass(d,[{key:"update",value:function(d){this.dom.classList.add("markdown");var b=k(d),e=s(this.prevRoot,b.root);this.prevRoot=b.root,f(e,this.dom);var c=m(this.config);c.useHighlight&&l(this.dom,c)}}]),d}();return a.Markdown=p,a.parser=b,a.trans=i,a.codeHighlight=l,a.getParseResult=k,a.markdown=function(b,a,d){b.innerHTML="",b.classList.add("markdown");var f=k(a);i(f.root,b),d=m(d),l(b,d)},a.markdownInfo=function(e){var b=k(e),c=b.root,d=_objectWithoutProperties(b,["root"]);return d},a}({});
{
"name": "lys-markdown-parser",
"version": "3.1.0",
"version": "3.2.0",
"description": "js markdown parser",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -87,3 +87,2 @@ import { diffNode } from './diff.js';

const diffResult = diffNode(this.prevRoot, result.root);
console.log(diffResult, this.prevRoot, result.root);
this.prevRoot = result.root;

@@ -90,0 +89,0 @@ patch(diffResult, this.dom);

@@ -745,3 +745,3 @@ import nodeType, { TOKEN_TYPE as TKS } from './nodeType.js';

if (
helper.isType(tokens[index], TKS.CODE_BLOCK) ||
helper.isType(tokens[index], TKS.CODE_BLOCK) &&
helper.isType(tokens[index + 1], TKS.CODE_BLOCK)

@@ -748,0 +748,0 @@ ) {

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc