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.7.1 to 3.8.0

src/copy.js

2

dist/index.umd.js

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

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

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

@@ -11,3 +11,2 @@ export default {

root: 'root',
blod: 'b',

@@ -23,6 +22,4 @@ italic: 'i',

h6: 'h6',
queto: 'queto',
code: 'code',
table: 'table',

@@ -34,3 +31,2 @@ thead: 'thead',

td: 'td',
ul: 'ul',

@@ -40,2 +36,4 @@ li: 'li',

li_todo: 'li-todo',
comment: 'comment', // comment
htmlRaw: 'htmlRaw', // html原始元素
};

@@ -120,2 +118,4 @@

STRING: 'string', // 非以上关键字符之外的连续字符
COMMENT_START: 'comment_start',
COMMENT_END: 'comment_end',
};

@@ -37,6 +37,14 @@ import { createAstNode } from './createAstNode.js';

let offset = 1;
// <!-- -->
switch (char) {
case '-': {
if (input.slice(index, index + 3) === '-->') {
offset = 3;
tokens.push(
new Token(TKS.COMMENT_END, char, index, index + offset)
);
break;
}
tokens.push(
new Token(TKS.NO_ORDER_LIST, char, index, index + 1)
new Token(TKS.NO_ORDER_LIST, char, index, index + offset)
);

@@ -46,8 +54,22 @@ break;

case '+': {
tokens.push(new Token(TKS.ORDER_LIST, char, index, index + 1));
tokens.push(
new Token(TKS.ORDER_LIST, char, index, index + offset)
);
break;
}
case '<': {
if (input.slice(index, index + 4) === '<!--') {
offset = 4;
tokens.push(
new Token(
TKS.COMMENT_START,
char,
index,
index + offset
)
);
break;
}
tokens.push(
new Token(TKS.SIMPLE_URL_START, char, index, index + 1)
new Token(TKS.SIMPLE_URL_START, char, index, index + offset)
);

@@ -58,3 +80,3 @@ break;

tokens.push(
new Token(TKS.SIMPLE_URL_END, char, index, index + 1)
new Token(TKS.SIMPLE_URL_END, char, index, index + offset)
);

@@ -64,7 +86,11 @@ break;

case '(': {
tokens.push(new Token(TKS.URL_START, char, index, index + 1));
tokens.push(
new Token(TKS.URL_START, char, index, index + offset)
);
break;
}
case ')': {
tokens.push(new Token(TKS.URL_END, char, index, index + 1));
tokens.push(
new Token(TKS.URL_END, char, index, index + offset)
);
break;

@@ -74,3 +100,3 @@ }

tokens.push(
new Token(TKS.URL_DESC_START, char, index, index + 1)
new Token(TKS.URL_DESC_START, char, index, index + offset)
);

@@ -81,3 +107,3 @@ break;

tokens.push(
new Token(TKS.URL_DESC_END, char, index, index + 1)
new Token(TKS.URL_DESC_END, char, index, index + offset)
);

@@ -87,15 +113,23 @@ break;

case '#': {
tokens.push(new Token(TKS.HEAD_TITLE, char, index, index + 1));
tokens.push(
new Token(TKS.HEAD_TITLE, char, index, index + offset)
);
break;
}
case '!': {
tokens.push(new Token(TKS.IMG_START, char, index, index + 1));
tokens.push(
new Token(TKS.IMG_START, char, index, index + offset)
);
break;
}
case '|': {
tokens.push(new Token(TKS.TABLE_SPLIT, char, index, index + 1));
tokens.push(
new Token(TKS.TABLE_SPLIT, char, index, index + offset)
);
break;
}
case '`': {
tokens.push(new Token(TKS.CODE_BLOCK, char, index, index + 1));
tokens.push(
new Token(TKS.CODE_BLOCK, char, index, index + offset)
);
break;

@@ -105,3 +139,3 @@ }

tokens.push(
new Token(TKS.LINE_THROUGH, char, index, index + 1)
new Token(TKS.LINE_THROUGH, char, index, index + offset)
);

@@ -111,3 +145,3 @@ break;

case '*': {
tokens.push(new Token(TKS.BLOB, char, index, index + 1));
tokens.push(new Token(TKS.BLOB, char, index, index + offset));
break;

@@ -122,3 +156,3 @@ }

tokens.push(
new Token(TKS.WHITE_SPACE, char, index, index + 1)
new Token(TKS.WHITE_SPACE, char, index, index + offset)
);

@@ -130,3 +164,5 @@ }

case '\n': {
tokens.push(new Token(TKS.LINE_END, char, index, index + 1));
tokens.push(
new Token(TKS.LINE_END, char, index, index + offset)
);
break;

@@ -133,0 +169,0 @@ }

@@ -31,2 +31,21 @@ import { helper, matchUsefulTokens, TKS, nodeType } from './util.js';

export function parseComment(index, tokens, handler) {
// 如何完美结合起来
const queue = [
TKS.COMMENT_START,
{
content: [],
name: 'content',
test: (type) =>
helper.isType(type, TKS.COMMENT_END)
? { offset: 0 }
: helper.goOn,
},
TKS.COMMENT_END,
];
// 在这里存储匹配到的结果,然后对,某些可递归元素继续解析 比如 [can parse content]()
return matchUsefulTokens(index, tokens, queue, handler);
}
/**

@@ -263,2 +282,13 @@ * 解析url

if (
parseComment(index, tokens, (matchTokens, info) => {
const node = createAstNode(nodeType.comment, matchTokens);
node.data = helper.tokensToString(info.content);
parentNode.push(node);
index += matchTokens.length;
})
) {
return index;
}
if (
parseUrl(index, tokens, (matchTokens, info) => {

@@ -265,0 +295,0 @@ const node = createAstNode(nodeType.url, matchTokens, {

@@ -8,2 +8,3 @@ /**

import { getParserNodeInfo } from './helper.js';
import { copyToClipboard } from './copy.js';

@@ -94,2 +95,12 @@ /**@typedef {import("../@type").ASTNode} ASTNode */

}
case nodeType.comment: {
ele = document.createComment('');
node.__update = (key, newNode) => {
if (key === 'data') {
ele.data = newNode[key];
}
};
node.__update('data', node);
break;
}
case nodeType.text: {

@@ -129,4 +140,6 @@ // const text = node.value;

ele = document.createElement('pre');
ele.className = 'blockCode';
const code = document.createElement('code');
// 需要在node上添加__update方法,方便更新属性
let codeContent = '';
node.__update = (key, newNode) => {

@@ -141,3 +154,4 @@ switch (key) {

case 'code': {
code.textContent = newNode[key]; // 不能使用innerHTML
codeContent = newNode[key];
code.textContent = codeContent; // 不能使用innerHTML
break;

@@ -151,2 +165,12 @@ }

node.__update('code', node);
const copyBtn = document.createElement('div');
copyBtn.textContent = 'copy';
copyBtn.className = 'blockCodeCopyBtn';
copyBtn.addEventListener('click', () => {
copyToClipboard(codeContent);
});
ele.appendChild(copyBtn);
ele.appendChild(code);

@@ -153,0 +177,0 @@ break;

Sorry, the diff of this file is not supported yet

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

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