You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4 lines
8.5 KiB

3 years ago
var B=Object.create;var h=Object.defineProperty,V=Object.defineProperties,W=Object.getOwnPropertyDescriptor,F=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertyNames,A=Object.getOwnPropertySymbols,Y=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var L=(n,t,e)=>t in n?h(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,m=(n,t)=>{for(var e in t||(t={}))v.call(t,e)&&L(n,e,t[e]);if(A)for(var e of A(t))X.call(t,e)&&L(n,e,t[e]);return n},u=(n,t)=>V(n,F(t)),D=n=>h(n,"__esModule",{value:!0});var z=(n,t)=>{D(n);for(var e in t)h(n,e,{get:t[e],enumerable:!0})},q=(n,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of $(t))!v.call(n,s)&&s!=="default"&&h(n,s,{get:()=>t[s],enumerable:!(e=W(t,s))||e.enumerable});return n},p=n=>q(D(h(n!=null?B(Y(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var a=(n,t,e)=>new Promise((s,i)=>{var r=l=>{try{b(e.next(l))}catch(S){i(S)}},c=l=>{try{b(e.throw(l))}catch(S){i(S)}},b=l=>l.done?s(l.value):Promise.resolve(l.value).then(r,c);b((e=e.apply(n,t)).next())});z(exports,{default:()=>M});var j=p(require("obsidian"));var H=p(require("obsidian"));function x(n,t){let e=Object.assign({},t,n);return Object.keys(e).reduce((s,i)=>{let r=n[i],c=typeof r=="undefined"||r===null;return u(m({},s),{[i]:c?t[i]:r})},{})}function P(n,t){try{let e=(0,H.parseYaml)(n);return x(e,t)}catch(e){return t}}var d={None:"",TOC:"[TOC]",_TOC_:"__TOC__",AzureWiki:"_TOC_",DevonThink:"{{toc}}",TheBrain:"[/toc/]"};var N={style:"bullet",min_depth:2,max_depth:6,externalStyle:"None",supportAllMatchers:!1},g="dynamic-toc",R=`.${g}`,K=Object.keys(d);var y=p(require("obsidian"));var O=class{constructor(t){this.cached=t}get level(){return this.cached.level}get rawHeading(){return this.cached.heading}get isLink(){return/\[\[(.*?)\]\]/.test(this.cached.heading)}get href(){return this.isLink?`#${this.parseMarkdownLink(this.rawHeading).split("|").join(" ")}`:null}get markdownHref(){if(!this.isLink)return`[[#${this.rawHeading}]]`;let e=this.parseMarkdownLink(this.rawHeading).split("|");return e.length>1?`[[#${e.join(" ")}|${e[1]}]]`:`[[#${e[0]}]]`}parseMarkdownLink(t){let[,e]=t.match(/\[\[(.*?)]\]/)||[];return e}};function G(n,t){let e=n[0].level,s=t.title?`${t.title}
`:"";return s+=n.map(i=>{let r=t.style==="number"&&"1."||"-";return`${new Array(Math.max(0,i.level-e)).fill(" ").join("")}${r} ${i.markdownHref}`}).join(`
`),s}function T(n,t){if(!(n==null?void 0:n.headings))return"";let{headings:e}=n,s=e.filter(i=>!!i&&i.level>=t.min_depth&&i.level<=t.max_depth);return s.length?G(s.map(i=>new O(i)),t):""}var _=class extends y.MarkdownRenderChild{constructor(t,e,s,i){super(i);this.app=t;this.config=e;this.filePath=s;this.container=i;this.onSettingsChangeHandler=t=>{this.render(x(this.config,t))};this.onFileChangeHandler=t=>{t.deleted||t.path!==this.filePath||this.render()}}onload(){return a(this,null,function*(){yield this.render(),this.registerEvent(this.app.metadataCache.on("dynamic-toc:settings",this.onSettingsChangeHandler)),this.registerEvent(this.app.metadataCache.on("changed",this.onFileChangeHandler))})}render(t){return a(this,null,function*(){this.container.empty(),this.container.classList.add(g);let e=T(this.app.metadataCache.getCache(this.filePath),t||this.config);yield y.MarkdownRenderer.renderMarkdown(e,this.container,this.filePath,this)})}};var o=p(require("obsidian"));var w=class extends o.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e}display(){let{containerEl:t}=this;t.empty(),t.createEl("h2",{text:"Dynamic Table of Contents Settings"}),new o.Setting(t).setName("List Style").setDesc("The table indication").addDropdown(s=>s.addOptions({bullet:"Bullet",number:"Number"}).setValue(this.plugin.settings.style).onChange(i=>a(this,null,function*(){this.plugin.settings.style=i,yield this.plugin.saveSettings()}))),new o.Setting(t).setName("Minimum Header Depth").setDesc("The default minimum header depth to render").addSlider(s=>s.setLimits(1,6,1).setValue(this.plugin.settings.min_depth).setDynamicTooltip().onChange(i=>a(this,null,function*(){i>this.plugin.settings.max_depth?new o.Notice("Min Depth is higher than Max Depth"):(this.plugin.settings.min_depth=i,yield this.plugin.saveSettings())}))),new o.Setting(t).setName("Maximum Header Depth").setDesc("The default maximum header depth to render").addSlider(s=>s.setLimits(1,6,1).setValue(this.plugin.settings.max_depth).setDynamicTooltip().onChange(i=>a(this,null,function*(){i<this.plugin.settings.min_depth?new o.Notice("Max Depth is higher than Min Depth"):(this.plugin.settings.max_depth=i,yield this.plugin.saveSettings())}))),new o.Setting(t).setName("Title").setDesc("The title of the table of contents, supports simple markdown such as ## Contents or **Contents**").addText(s=>s.setPlaceholder("## Table of Contents").setValue(this.plugin.settings.title).onChange(i=>a(this,null,function*(){this.plugin.settings.title=i,this.plugin.saveSettings()})));let e=new o.Setting(t).setName("External rendering support").setDesc("Different markdown viewers provided Table of Contents support such as [TOC] or [[_TOC_]]. You may need to restart Obsidian for this to take effect.").addDropdown(s=>s.addOptions(Object.keys(d).reduce((i,r)=>{let c=d[r];return u(m({},i),{[r]:c})},{})).setDisabled(this.plugin.settings.supportAllMatchers).setValue(this.plugin.settings.externalStyle).onChange(i=>a(this,null,function*(){this.plugin.settings.externalStyle=i,yield this.plugin.saveSettings()})));new o.Setting(t).setName("Support all external renderers").setDesc("Cannot be used in conjunction with individual renderers").addToggle(s=>s.setValue(this.plugin.settings.supportAllMatchers).onChange(i=>a(this,null,function*(){this.plugin.settings.supportAllMatchers=i,e.setDisabled(i),yield this.plugin.saveSettings()})))}};var C=p(require("obsidian"));var f=class extends C.MarkdownRenderChild{constructor(t,e,s,i,r){super(i);this.app=t;this.settings=e;this.filePath=s;this.match=r;this.onSettingsChangeHandler=()=>{this.render()};this.onFileChangeHandler=t=>{t.deleted||t.path!==this.filePath||this.render()}}static findMatch(t,e){return Array.from(t.querySelectorAll("p, span, a")).find(i=>i.textContent.toLowerCase().includes(e.toLowerCase()))||null}onload(){return a(this,null,function*(){this.render(),this.registerEvent(this.app.metadataCache.on("dynamic-toc:settings",this.onSettingsChangeHandler)),this.registerEvent(this.app.metadataCache.on("changed",this.onFileChangeHandler))})}render(){return a(this,null,funct