bigint-crypto-utils/node_modules/markdown-it-anchor/dist/markdownItAnchor.mjs

3 lines
1.6 KiB
JavaScript
Raw Normal View History

var n={false:"push",true:"unshift"},e=Object.prototype.hasOwnProperty,t=function(n,r){r=Object.assign({},t.defaults,r),n.core.ruler.push("anchor",function(n){var t,i={},u=n.tokens,c=Array.isArray(r.level)?(t=r.level,function(n){return t.includes(n)}):function(n){return function(e){return e>=n}}(r.level);u.filter(function(n){return"heading_open"===n.type}).filter(function(n){return c(Number(n.tag.substr(1)))}).forEach(function(t){var c=u[u.indexOf(t)+1].children.filter(function(n){return"text"===n.type||"code_inline"===n.type}).reduce(function(n,e){return n+e.content},""),o=t.attrGet("id");null==o&&(o=function(n,t){for(var r=n,i=2;e.call(t,r);)r=n+"-"+i++;return t[r]=!0,r}(r.slugify(c),i),t.attrPush(["id",o])),r.permalink&&r.renderPermalink(o,r,n,u.indexOf(t)),r.callback&&r.callback(t,{slug:o,title:c})})})};t.defaults={level:1,slugify:function(n){return encodeURIComponent(String(n).trim().toLowerCase().replace(/\s+/g,"-"))},permalink:!1,renderPermalink:function(e,t,r,i){var u,c=[Object.assign(new r.Token("link_open","a",1),{attrs:[["class",t.permalinkClass],["href",t.permalinkHref(e,r)]].concat(Object.entries(t.permalinkAttrs(e,r)))}),Object.assign(new r.Token("html_block","",0),{content:t.permalinkSymbol}),new r.Token("link_close","a",-1)];t.permalinkSpace&&c[n[!t.permalinkBefore]](Object.assign(new r.Token("text","",0),{content:" "})),(u=r.tokens[i+1].children)[n[t.permalinkBefore]].apply(u,c)},permalinkClass:"header-anchor",permalinkSpace:!0,permalinkSymbol:"¶",permalinkBefore:!1,permalinkHref:function(n){return"#"+n},permalinkAttrs:function(n){return{}}};export default t;
//# sourceMappingURL=markdownItAnchor.mjs.map