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

3 lines
1.6 KiB
JavaScript
Raw Normal View History

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