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

mokuji.js

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mokuji.js - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

2

dist/dom.d.ts
export declare const hasParentNode: (element: Node | null, parent: Node | null) => boolean;
export declare const reverseElement: (element: Node) => Node;
export declare const getHeadingsElement: (element: Element) => NodeListOf<HTMLHeadingElement>;
export declare const getHeadingsElement: (element: Element) => HTMLHeadingElement[];

@@ -10,3 +10,3 @@ declare type AnchorContainerTagNameProps = 'ul' | 'ol';

};
export declare const Mokuji: (element: HTMLElement | null, externalOptions?: MokujiOption | undefined) => HTMLOListElement | undefined;
export declare const Mokuji: (element: HTMLElement | null, externalOptions?: MokujiOption) => HTMLUListElement | HTMLOListElement | undefined;
export {};

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

var e=function(e,n){for(;e;){if(e===n)return!0;e=e.parentNode}return!1},n={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},r=[],a=function(e,n){for(var a=n||"",t=1;t<=e.length;){var o=1===t?a:a+"_"+t;if(-1===r.indexOf(o)){r.push(a=o);break}t++}return a};exports.Mokuji=function(r,t){if(r){var o=Object.assign(n,t),i=function(e){return e.querySelectorAll("h1, h2, h3, h4, h5, h6")}(r),c=document.createElement(o.anchorContainerTagName||n.anchorContainerTagName);return function(n,r,t){for(var o=0,i=document.createElement("li"),c=document.createElement("a"),h=0;h<n.length;h++){var l=n[h],f=Number(l.tagName.substring(1));if(0!==o&&o<f){var u=document.createElement("ol");r.lastChild.appendChild(u),r=u}else if(0!==o&&o>f)for(var d=0;d<o-f;d++)e(r,r.parentNode)&&(r=r.parentNode.parentNode);var m=(g=t,C=void 0,C=(v=a(n,l.textContent),C=v.replace(/\s+/g,"_")).replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===g&&(C=function(e){return(e=encodeURIComponent(e)).replace(/\%+/g,".")}(C)),C);l.id=m;var s=c.cloneNode(!1);s.href="#"+m,s.textContent=l.textContent;var p=i.cloneNode(!1);p.appendChild(s),r.appendChild(p),o=f}var v,g,C}(i,c,!!o.anchorType),function(e,n){for(var r=n.getElementsByTagName("a"),a=function(n){var a=r[n].innerText,t=r[n].hash,o=Array.from(e).filter(function(e){return e.id===a});if(1===o.length)return"continue";var i=0;o.forEach(function(e){for(var n=e.id+"-"+i,a=0,o=Array.from(r);a<o.length;a++){var c=o[a];if(c.hash===t){c.href="#"+n;break}}e.id=n,i++})},t=0;t<r.length;t++)a(t)}(i,c),o.anchorLink&&function(e,n,r){if(n){var a=document.createElement("a");a.setAttribute("aria-hidden","true"),r.anchorLinkClassName&&a.classList.add(r.anchorLinkClassName),e.forEach(function(e){for(var t=e.id,o=0;o<n.length;o++){var i=n[o].hash;if(i.replace("#","")===t){var c=a.cloneNode(!1);c.setAttribute("href",i),r.anchorLinkSymbol&&(c.textContent=r.anchorLinkSymbol),r.anchorLinkBefore?e.insertBefore(c,e.firstChild):e.appendChild(c)}}})}}(i,c.querySelectorAll("a"),o),c}};
var e=function(e,n){for(;e;){if(e===n)return!0;e=e.parentNode}return!1},n={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},r=[],a=function(e,n){for(var a=n||"",t=1;t<=e.length;){var o=1===t?a:a+"_"+t;if(!r.includes(o)){r.push(a=o);break}t++}return a};exports.Mokuji=function(r,t){if(r){var o=Object.assign(n,t),i=function(e){return Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6"))}(r),c=document.createElement(o.anchorContainerTagName||n.anchorContainerTagName);return function(n,r,t){for(var o=0,i=document.createElement("li"),c=document.createElement("a"),l=0;l<n.length;l++){var h=n[l],f=Number(h.tagName.substring(1));if(0!==o&&o<f){var d=document.createElement("ol");r.lastChild.appendChild(d),r=d}else if(0!==o&&o>f)for(var u=0;u<o-f;u++)e(r,r.parentNode)&&(r=r.parentNode.parentNode);var m=(g=t,C=void 0,C=(v=a(n,h.textContent),C=v.replace(/\s+/g,"_")).replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===g&&(C=function(e){return(e=encodeURIComponent(e)).replace(/\%+/g,".")}(C)),C);h.id=m;var s=c.cloneNode(!1);s.href="#"+m,s.textContent=h.textContent;var p=i.cloneNode(!1);p.appendChild(s),r.appendChild(p),o=f}var v,g,C}(i,c,!!o.anchorType),function(e,n){for(var r=Array.from(n.getElementsByTagName("a")),a=function(n){var a=r[n].textContent,t=r[n].hash,o=e.filter(function(e){return e.id===a});if(1===o.length)return"continue";for(var i=0,c=0;c<o.length;c++){for(var l=o[c],h=l.id+"-"+i,f=0;f<r.length;f++){var d=r[f];if(d.hash===t){d.href="#"+h;break}}l.id=h,i++}},t=0;t<r.length;t++)a(t)}(i,c),o.anchorLink&&function(e,n,r){if(n){var a=document.createElement("a");r.anchorLinkClassName&&a.classList.add(r.anchorLinkClassName);for(var t=0;t<e.length;t++)for(var o=e[t],i=o.id,c=0;c<n.length;c++){var l=n[c].hash;if(l.replace("#","")===i){var h=a.cloneNode(!1);h.setAttribute("href",l),r.anchorLinkSymbol&&(h.textContent=r.anchorLinkSymbol),r.anchorLinkBefore?o.insertBefore(h,o.firstChild):o.appendChild(h)}}}}(i,Array.from(c.querySelectorAll("a")),o),c}};
//# sourceMappingURL=mokuji.js.map

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

const e=(e,n)=>{for(;e;){if(e===n)return!0;e=e.parentNode}return!1},n={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},t=[],r=(e,n)=>{let r=n||"",o=1;for(;o<=e.length;){const e=1===o?r:`${r}_${o}`;if(-1===t.indexOf(e)){r=e,t.push(r);break}o++}return r},o=(e,n)=>{let t=(e=>e.replace(/\s+/g,"_"))(e);return t=t.replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===n&&(t=(e=>(e=encodeURIComponent(e)).replace(/\%+/g,"."))(t)),t},a=(t,a)=>{if(!t)return;const c=Object.assign(n,a),l=(e=>e.querySelectorAll("h1, h2, h3, h4, h5, h6"))(t),i=document.createElement(c.anchorContainerTagName||n.anchorContainerTagName);return((n,t,a)=>{let c=0;const l=document.createElement("li"),i=document.createElement("a");for(let h=0;h<n.length;h++){const s=n[h],d=Number(s.tagName.substring(1));if(0!==c&&c<d){const e=document.createElement("ol");t.lastChild.appendChild(e),t=e}else if(0!==c&&c>d)for(let n=0;n<c-d;n++)e(t,t.parentNode)&&(t=t.parentNode.parentNode);const f=r(n,s.textContent),m=o(f,a);s.id=m;const p=i.cloneNode(!1);p.href=`#${m}`,p.textContent=s.textContent;const u=l.cloneNode(!1);u.appendChild(p),t.appendChild(u),c=d}})(l,i,!!c.anchorType),((e,n)=>{const t=n.getElementsByTagName("a");for(let n=0;n<t.length;n++){const r=t[n].innerText,o=t[n].hash,a=Array.from(e).filter(e=>e.id===r);if(1===a.length)continue;let c=0;a.forEach(e=>{const n=`${e.id}-${c}`;for(const e of Array.from(t))if(e.hash===o){e.href=`#${n}`;break}e.id=n,c++})}})(l,i),c.anchorLink&&((e,n,t)=>{if(!n)return;const r=document.createElement("a");r.setAttribute("aria-hidden","true"),t.anchorLinkClassName&&r.classList.add(t.anchorLinkClassName),e.forEach(e=>{const{id:o}=e;for(let a=0;a<n.length;a++){const{hash:c}=n[a];if(c.replace("#","")!==o)continue;const l=r.cloneNode(!1);l.setAttribute("href",c),t.anchorLinkSymbol&&(l.textContent=t.anchorLinkSymbol),t.anchorLinkBefore?e.insertBefore(l,e.firstChild):e.appendChild(l)}})})(l,i.querySelectorAll("a"),c),i};export{a as Mokuji};
const e=(e,n)=>{for(;e;){if(e===n)return!0;e=e.parentNode}return!1},n={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},t=[],o=(e,n)=>{let o=n||"",r=1;for(;r<=e.length;){const e=1===r?o:`${o}_${r}`;if(!t.includes(e)){o=e,t.push(o);break}r++}return o},r=(e,n)=>{let t=(e=>e.replace(/\s+/g,"_"))(e);return t=t.replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===n&&(t=(e=>(e=encodeURIComponent(e)).replace(/\%+/g,"."))(t)),t},a=(t,a)=>{if(!t)return;const l=Object.assign(n,a),c=(e=>Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6")))(t),h=document.createElement(l.anchorContainerTagName||n.anchorContainerTagName);return((n,t,a)=>{let l=0;const c=document.createElement("li"),h=document.createElement("a");for(let i=0;i<n.length;i++){const s=n[i],d=Number(s.tagName.substring(1));if(0!==l&&l<d){const e=document.createElement("ol");t.lastChild.appendChild(e),t=e}else if(0!==l&&l>d)for(let n=0;n<l-d;n++)e(t,t.parentNode)&&(t=t.parentNode.parentNode);const f=o(n,s.textContent),m=r(f,a);s.id=m;const p=h.cloneNode(!1);p.href=`#${m}`,p.textContent=s.textContent;const u=c.cloneNode(!1);u.appendChild(p),t.appendChild(u),l=d}})(c,h,!!l.anchorType),((e,n)=>{const t=Array.from(n.getElementsByTagName("a"));for(let n=0;n<t.length;n++){const o=t[n].textContent,r=t[n].hash,a=e.filter(e=>e.id===o);if(1===a.length)continue;let l=0;for(let e=0;e<a.length;e++){const n=a[e],o=`${n.id}-${l}`;for(let e=0;e<t.length;e++){const n=t[e];if(n.hash===r){n.href=`#${o}`;break}}n.id=o,l++}}})(c,h),l.anchorLink&&((e,n,t)=>{if(!n)return;const o=document.createElement("a");t.anchorLinkClassName&&o.classList.add(t.anchorLinkClassName);for(let r=0;r<e.length;r++){const a=e[r],{id:l}=a;for(let e=0;e<n.length;e++){const{hash:r}=n[e];if(r.replace("#","")!==l)continue;const c=o.cloneNode(!1);c.setAttribute("href",r),t.anchorLinkSymbol&&(c.textContent=t.anchorLinkSymbol),t.anchorLinkBefore?a.insertBefore(c,a.firstChild):a.appendChild(c)}}})(c,Array.from(h.querySelectorAll("a")),l),h};export{a as Mokuji};
//# sourceMappingURL=mokuji.modern.js.map

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

var e=function(e,n){for(;e;){if(e===n)return!0;e=e.parentNode}return!1},n={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},r=[],a=function(e,n){for(var a=n||"",t=1;t<=e.length;){var o=1===t?a:a+"_"+t;if(-1===r.indexOf(o)){r.push(a=o);break}t++}return a},t=function(r,t){if(r){var o=Object.assign(n,t),i=function(e){return e.querySelectorAll("h1, h2, h3, h4, h5, h6")}(r),c=document.createElement(o.anchorContainerTagName||n.anchorContainerTagName);return function(n,r,t){for(var o=0,i=document.createElement("li"),c=document.createElement("a"),h=0;h<n.length;h++){var l=n[h],f=Number(l.tagName.substring(1));if(0!==o&&o<f){var d=document.createElement("ol");r.lastChild.appendChild(d),r=d}else if(0!==o&&o>f)for(var u=0;u<o-f;u++)e(r,r.parentNode)&&(r=r.parentNode.parentNode);var m=(g=t,C=void 0,C=(v=a(n,l.textContent),C=v.replace(/\s+/g,"_")).replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===g&&(C=function(e){return(e=encodeURIComponent(e)).replace(/\%+/g,".")}(C)),C);l.id=m;var s=c.cloneNode(!1);s.href="#"+m,s.textContent=l.textContent;var p=i.cloneNode(!1);p.appendChild(s),r.appendChild(p),o=f}var v,g,C}(i,c,!!o.anchorType),function(e,n){for(var r=n.getElementsByTagName("a"),a=function(n){var a=r[n].innerText,t=r[n].hash,o=Array.from(e).filter(function(e){return e.id===a});if(1===o.length)return"continue";var i=0;o.forEach(function(e){for(var n=e.id+"-"+i,a=0,o=Array.from(r);a<o.length;a++){var c=o[a];if(c.hash===t){c.href="#"+n;break}}e.id=n,i++})},t=0;t<r.length;t++)a(t)}(i,c),o.anchorLink&&function(e,n,r){if(n){var a=document.createElement("a");a.setAttribute("aria-hidden","true"),r.anchorLinkClassName&&a.classList.add(r.anchorLinkClassName),e.forEach(function(e){for(var t=e.id,o=0;o<n.length;o++){var i=n[o].hash;if(i.replace("#","")===t){var c=a.cloneNode(!1);c.setAttribute("href",i),r.anchorLinkSymbol&&(c.textContent=r.anchorLinkSymbol),r.anchorLinkBefore?e.insertBefore(c,e.firstChild):e.appendChild(c)}}})}}(i,c.querySelectorAll("a"),o),c}};export{t as Mokuji};
var e=function(e,n){for(;e;){if(e===n)return!0;e=e.parentNode}return!1},n={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},r=[],a=function(e,n){for(var a=n||"",t=1;t<=e.length;){var o=1===t?a:a+"_"+t;if(!r.includes(o)){r.push(a=o);break}t++}return a},t=function(r,t){if(r){var o=Object.assign(n,t),i=function(e){return Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6"))}(r),c=document.createElement(o.anchorContainerTagName||n.anchorContainerTagName);return function(n,r,t){for(var o=0,i=document.createElement("li"),c=document.createElement("a"),l=0;l<n.length;l++){var h=n[l],f=Number(h.tagName.substring(1));if(0!==o&&o<f){var d=document.createElement("ol");r.lastChild.appendChild(d),r=d}else if(0!==o&&o>f)for(var u=0;u<o-f;u++)e(r,r.parentNode)&&(r=r.parentNode.parentNode);var m=(g=t,C=void 0,C=(v=a(n,h.textContent),C=v.replace(/\s+/g,"_")).replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===g&&(C=function(e){return(e=encodeURIComponent(e)).replace(/\%+/g,".")}(C)),C);h.id=m;var s=c.cloneNode(!1);s.href="#"+m,s.textContent=h.textContent;var p=i.cloneNode(!1);p.appendChild(s),r.appendChild(p),o=f}var v,g,C}(i,c,!!o.anchorType),function(e,n){for(var r=Array.from(n.getElementsByTagName("a")),a=function(n){var a=r[n].textContent,t=r[n].hash,o=e.filter(function(e){return e.id===a});if(1===o.length)return"continue";for(var i=0,c=0;c<o.length;c++){for(var l=o[c],h=l.id+"-"+i,f=0;f<r.length;f++){var d=r[f];if(d.hash===t){d.href="#"+h;break}}l.id=h,i++}},t=0;t<r.length;t++)a(t)}(i,c),o.anchorLink&&function(e,n,r){if(n){var a=document.createElement("a");r.anchorLinkClassName&&a.classList.add(r.anchorLinkClassName);for(var t=0;t<e.length;t++)for(var o=e[t],i=o.id,c=0;c<n.length;c++){var l=n[c].hash;if(l.replace("#","")===i){var h=a.cloneNode(!1);h.setAttribute("href",l),r.anchorLinkSymbol&&(h.textContent=r.anchorLinkSymbol),r.anchorLinkBefore?o.insertBefore(h,o.firstChild):o.appendChild(h)}}}}(i,Array.from(c.querySelectorAll("a")),o),c}};export{t as Mokuji};
//# sourceMappingURL=mokuji.module.js.map

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).mokujiJs={})}(this,function(e){var n=function(e,n){for(;e;){if(e===n)return!0;e=e.parentNode}return!1},r={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},t=[],a=function(e,n){for(var r=n||"",a=1;a<=e.length;){var o=1===a?r:r+"_"+a;if(-1===t.indexOf(o)){t.push(r=o);break}a++}return r};e.Mokuji=function(e,t){if(e){var o=Object.assign(r,t),i=function(e){return e.querySelectorAll("h1, h2, h3, h4, h5, h6")}(e),c=document.createElement(o.anchorContainerTagName||r.anchorContainerTagName);return function(e,r,t){for(var o=0,i=document.createElement("li"),c=document.createElement("a"),f=0;f<e.length;f++){var l=e[f],h=Number(l.tagName.substring(1));if(0!==o&&o<h){var d=document.createElement("ol");r.lastChild.appendChild(d),r=d}else if(0!==o&&o>h)for(var u=0;u<o-h;u++)n(r,r.parentNode)&&(r=r.parentNode.parentNode);var s=(g=t,C=void 0,C=(v=a(e,l.textContent),C=v.replace(/\s+/g,"_")).replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===g&&(C=function(e){return(e=encodeURIComponent(e)).replace(/\%+/g,".")}(C)),C);l.id=s;var m=c.cloneNode(!1);m.href="#"+s,m.textContent=l.textContent;var p=i.cloneNode(!1);p.appendChild(m),r.appendChild(p),o=h}var v,g,C}(i,c,!!o.anchorType),function(e,n){for(var r=n.getElementsByTagName("a"),t=function(n){var t=r[n].innerText,a=r[n].hash,o=Array.from(e).filter(function(e){return e.id===t});if(1===o.length)return"continue";var i=0;o.forEach(function(e){for(var n=e.id+"-"+i,t=0,o=Array.from(r);t<o.length;t++){var c=o[t];if(c.hash===a){c.href="#"+n;break}}e.id=n,i++})},a=0;a<r.length;a++)t(a)}(i,c),o.anchorLink&&function(e,n,r){if(n){var t=document.createElement("a");t.setAttribute("aria-hidden","true"),r.anchorLinkClassName&&t.classList.add(r.anchorLinkClassName),e.forEach(function(e){for(var a=e.id,o=0;o<n.length;o++){var i=n[o].hash;if(i.replace("#","")===a){var c=t.cloneNode(!1);c.setAttribute("href",i),r.anchorLinkSymbol&&(c.textContent=r.anchorLinkSymbol),r.anchorLinkBefore?e.insertBefore(c,e.firstChild):e.appendChild(c)}}})}}(i,c.querySelectorAll("a"),o),c}}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).mokujiJs={})}(this,function(e){var n=function(e,n){for(;e;){if(e===n)return!0;e=e.parentNode}return!1},r={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},t=[],a=function(e,n){for(var r=n||"",a=1;a<=e.length;){var o=1===a?r:r+"_"+a;if(!t.includes(o)){t.push(r=o);break}a++}return r};e.Mokuji=function(e,t){if(e){var o=Object.assign(r,t),i=function(e){return Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6"))}(e),c=document.createElement(o.anchorContainerTagName||r.anchorContainerTagName);return function(e,r,t){for(var o=0,i=document.createElement("li"),c=document.createElement("a"),l=0;l<e.length;l++){var f=e[l],h=Number(f.tagName.substring(1));if(0!==o&&o<h){var d=document.createElement("ol");r.lastChild.appendChild(d),r=d}else if(0!==o&&o>h)for(var u=0;u<o-h;u++)n(r,r.parentNode)&&(r=r.parentNode.parentNode);var s=(g=t,C=void 0,C=(v=a(e,f.textContent),C=v.replace(/\s+/g,"_")).replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===g&&(C=function(e){return(e=encodeURIComponent(e)).replace(/\%+/g,".")}(C)),C);f.id=s;var m=c.cloneNode(!1);m.href="#"+s,m.textContent=f.textContent;var p=i.cloneNode(!1);p.appendChild(m),r.appendChild(p),o=h}var v,g,C}(i,c,!!o.anchorType),function(e,n){for(var r=Array.from(n.getElementsByTagName("a")),t=function(n){var t=r[n].textContent,a=r[n].hash,o=e.filter(function(e){return e.id===t});if(1===o.length)return"continue";for(var i=0,c=0;c<o.length;c++){for(var l=o[c],f=l.id+"-"+i,h=0;h<r.length;h++){var d=r[h];if(d.hash===a){d.href="#"+f;break}}l.id=f,i++}},a=0;a<r.length;a++)t(a)}(i,c),o.anchorLink&&function(e,n,r){if(n){var t=document.createElement("a");r.anchorLinkClassName&&t.classList.add(r.anchorLinkClassName);for(var a=0;a<e.length;a++)for(var o=e[a],i=o.id,c=0;c<n.length;c++){var l=n[c].hash;if(l.replace("#","")===i){var f=t.cloneNode(!1);f.setAttribute("href",l),r.anchorLinkSymbol&&(f.textContent=r.anchorLinkSymbol),r.anchorLinkBefore?o.insertBefore(f,o.firstChild):o.appendChild(f)}}}}(i,Array.from(c.querySelectorAll("a")),o),c}}});
//# sourceMappingURL=mokuji.umd.js.map
{
"name": "mokuji.js",
"version": "4.1.0",
"version": "4.2.0",
"description": "A table of content JavaScript Library",

@@ -51,9 +51,9 @@ "scripts": {

"@types/node": "~17.0.23",
"husky": "^7.0.4",
"lint-staged": "^12.3.7",
"microbundle": "^0.14.2",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"microbundle": "^0.15.0",
"prettier": "^2.6.1",
"rimraf": "^3.0.2",
"typescript": "~4.6.3"
"typescript": "~4.7.4"
}
}

@@ -19,4 +19,4 @@ export const hasParentNode = (element: Node | null, parent: Node | null) => {

export const getHeadingsElement = (element: Element): NodeListOf<HTMLHeadingElement> => {
return element.querySelectorAll("h1, h2, h3, h4, h5, h6");
export const getHeadingsElement = (element: Element): HTMLHeadingElement[] => {
return Array.from(element.querySelectorAll('h1, h2, h3, h4, h5, h6'));
};

@@ -27,4 +27,4 @@ import { hasParentNode, getHeadingsElement } from './dom';

const renderAnchorLink = (
headings: NodeListOf<HTMLHeadingElement>,
anchors: NodeListOf<HTMLAnchorElement> | undefined,
headings: HTMLHeadingElement[],
anchors: HTMLAnchorElement[] | undefined,
options: MokujiOption,

@@ -35,3 +35,2 @@ ) => {

const a = document.createElement('a');
a.setAttribute('aria-hidden', 'true');

@@ -42,7 +41,8 @@ if (options.anchorLinkClassName) {

headings.forEach((heading) => {
for (let i = 0; i < headings.length; i++) {
const heading = headings[i];
const { id } = heading;
for (let i = 0; i < anchors.length; i++) {
const { hash } = anchors[i];
for (let j = 0; j < anchors.length; j++) {
const { hash } = anchors[j];

@@ -70,12 +70,12 @@ if (hash.replace('#', '') !== id) {

}
});
}
};
const removeDuplicateIds = (headings: NodeListOf<HTMLHeadingElement>, elementContainer: HTMLElement) => {
const anchors = elementContainer.getElementsByTagName('a');
const removeDuplicateIds = (headings: HTMLHeadingElement[], elementContainer: HTMLElement) => {
const anchors = Array.from(elementContainer.getElementsByTagName('a'));
for (let i = 0; i < anchors.length; i++) {
const id = anchors[i].innerText;
const id = anchors[i].textContent;
const hash = anchors[i].hash;
const matchedHeadings = Array.from(headings).filter((heading) => heading.id === id);
const matchedHeadings = headings.filter((heading) => heading.id === id);

@@ -89,7 +89,9 @@ if (matchedHeadings.length === 1) {

matchedHeadings.forEach((heading) => {
for (let j = 0; j < matchedHeadings.length; j++) {
const heading = matchedHeadings[j];
const heading_id = `${heading.id}-${count}`;
// search duplicate list
for (const anchor of Array.from(anchors)) {
for (let k = 0; k < anchors.length; k++) {
const anchor = anchors[k];
if (anchor.hash === hash) {

@@ -105,7 +107,7 @@ // update hash

count++;
});
}
}
};
const censorshipId = (headings: NodeListOf<HTMLHeadingElement>, textContent: string | null) => {
const censorshipId = (headings: HTMLHeadingElement[], textContent: string | null) => {
let id = textContent || '';

@@ -118,3 +120,3 @@ let suffix_count = 1;

if (storeIds.indexOf(tmp_id) === -1) {
if (!storeIds.includes(tmp_id)) {
id = tmp_id;

@@ -146,3 +148,3 @@ storeIds.push(id);

const generateHierarchyList = (
headings: NodeListOf<HTMLHeadingElement>,
headings: HTMLHeadingElement[],
elementContainer: HTMLUListElement | HTMLOListElement,

@@ -196,3 +198,6 @@ anchorType: boolean,

export const Mokuji = (element: HTMLElement | null, externalOptions?: MokujiOption): HTMLOListElement | undefined => {
export const Mokuji = (
element: HTMLElement | null,
externalOptions?: MokujiOption,
): HTMLUListElement | HTMLOListElement | undefined => {
if (!element) {

@@ -214,3 +219,3 @@ return;

options.anchorContainerTagName || defaultOptions.anchorContainerTagName,
);
) as HTMLUListElement | HTMLOListElement;

@@ -225,3 +230,3 @@ // generate mokuji list

if (options.anchorLink) {
const anchors = elementContainer.querySelectorAll('a');
const anchors = Array.from(elementContainer.querySelectorAll('a'));
renderAnchorLink(headings, anchors, options);

@@ -228,0 +233,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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