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.
3 lines
7.0 KiB
3 lines
7.0 KiB
3 years ago
|
var K=Object.create;var h=Object.defineProperty,W=Object.defineProperties,B=Object.getOwnPropertyDescriptor,V=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,M=Object.getOwnPropertySymbols,F=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var A=(n,e,t)=>e in n?h(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,u=(n,e)=>{for(var t in e||(e={}))b.call(e,t)&&A(n,t,e[t]);if(M)for(var t of M(e))I.call(e,t)&&A(n,t,e[t]);return n},T=(n,e)=>W(n,V(e)),D=n=>h(n,"__esModule",{value:!0});var Y=(n,e)=>{D(n);for(var t in e)h(n,t,{get:e[t],enumerable:!0})},$=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j(e))!b.call(n,i)&&i!=="default"&&h(n,i,{get:()=>e[i],enumerable:!(t=B(e,i))||t.enumerable});return n},m=n=>$(D(h(n!=null?K(F(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var r=(n,e,t)=>new Promise((i,s)=>{var a=l=>{try{c(t.next(l))}catch(S){s(S)}},p=l=>{try{c(t.throw(l))}catch(S){s(S)}},c=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,p);c((t=t.apply(n,e)).next())});Y(exports,{default:()=>w});var H=m(require("obsidian"));var L=m(require("obsidian"));function x(n,e){let t=Object.assign({},e,n);return Object.keys(t).reduce((i,s)=>{let a=n[s],p=typeof a=="undefined"||a===null;return T(u({},i),{[s]:p?e[s]:a})},{})}function k(n,e){try{let t=(0,L.parseYaml)(n);return x(t,e)}catch(t){return e}}var d={None:"",TOC:"[TOC]",_TOC_:"__TOC__",AzureWiki:"_TOC_",DevonThink:"{{toc}}",TheBrain:"[/toc/]"};var R={style:"bullet",min_depth:2,max_depth:6,externalStyle:"None",supportAllMatchers:!1},g="dynamic-toc",v=`.${g}`,N=Object.keys(d);var f=m(require("obsidian"));function X(n){return n.replace(/[[\]]/g,"")}function y(n,e){if(!(n==null?void 0:n.headings))return"";let{headings:t}=n,i=t.filter(a=>!!a&&a.level>=e.min_depth&&a.level<=e.max_depth);if(!i.length)return"";let s=i[0].level;return i.map(a=>{let p=e.style==="number"&&"1."||"-",c=new Array(Math.max(0,a.level-s)).fill(" ").join(""),l=X(a.heading);return`${c}${p} [[#${l}|${l}]]`}).join(`
|
||
|
`)}function P(n){let e=null;return{start:()=>{e=new Date().getTime()},stop:()=>{!e||console.log(`Dynamic TOC ${n} completed in ${new Date().getTime()-e}ms.`)}}}var O=class extends f.MarkdownRenderChild{constructor(e,t,i,s){super(s);this.app=e;this.config=t;this.filePath=i;this.container=s;this.onSettingsChangeHandler=e=>{this.render(x(this.config,e))};this.onFileChangeHandler=e=>{e.deleted||e.path!==this.filePath||this.render()}}onload(){return r(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(e){return r(this,null,function*(){let t=P("codeblock renderer");t.start(),this.container.empty(),this.container.classList.add(g);let i=y(this.app.metadataCache.getCache(this.filePath),e||this.config);yield f.MarkdownRenderer.renderMarkdown(i,this.container,this.filePath,this),t.stop()})}};var o=m(require("obsidian"));var _=class extends o.PluginSettingTab{constructor(e,t){super(e,t);this.plugin=t}display(){let{containerEl:e}=this;e.empty(),e.createEl("h2",{text:"Dynamic Table of Contents Settings"}),new o.Setting(e).setName("List Style").setDesc("The table indication").addDropdown(i=>i.addOptions({bullet:"Bullet",number:"Number"}).setValue(this.plugin.settings.style).onChange(s=>r(this,null,function*(){this.plugin.settings.style=s,yield this.plugin.saveSettings()}))),new o.Setting(e).setName("Minimum Header Depth").setDesc("The default minimum header depth to render").addSlider(i=>i.setLimits(1,6,1).setValue(this.plugin.settings.min_depth).setDynamicTooltip().onChange(s=>r(this,null,function*(){s>this.plugin.settings.max_depth?new o.Notice("Min Depth is higher than Max Depth"):(this.plugin.settings.min_depth=s,yield this.plugin.saveSettings())}))),new o.Setting(e).setName("Maximum Header Depth").setDesc("The default maximum header depth to render").addSlider(i=>i.setLimits(1,6,1).setValue(this.plugin.settings.max_depth).setDynamicTooltip().onChange(s=>r(this,null,function*(){s<this.plugin.settings.min_depth?new o.Notice("Max Depth is higher than Min Depth"):(this.plugin.settings.max_depth=s,yield this.plugin.saveSettings())})));let t=new o.Setting(e).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(i=>i.addOptions(Object.keys(d).reduce((s,a)=>{let p=d[a];return T(u({},s),{[a]:p})},{})).setDisabled(this.plugin.settings.supportAllMatchers).setValue(this.plugin.settings.externalStyle).onChange(s=>r(this,null,function*(){this.plugin.settings.externalStyle=s,yield this.plugin.saveSettings()})));new o.Setting(e).setName("Support all external renderers").setDesc("Cannot be used in conjunction with individual renderers").addToggle(i=>i.setValue(this.plugin.settings.supportAllMatchers).onChange(s=>r(this,null,function*(){this.plugin.settings.supportAllMatchers=s,t.setDisabled(s),yield this.plugin.saveSettings()})))}};var E=m(require("obsidian"));var C=class extends E.MarkdownRenderChild{constructor(e,t,i,s,a){super(s);this.app=e;this.settings=t;this.filePath=i;this.match=a;this.onSettingsChangeHandler=()=>{this.render()};this.onFileChangeHandler=e=>{e.deleted||e.path!==this.filePath||this.render()}}static findMatch(e,t){return Array.from(e.querySelectorAll("p, span, a")).find(s=>s.textContent.toLowerCase().includes(t.toLowerCase()))||null}onload(){return r(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 r(this,null,function*(){let e=y(this.app.metadataCache.getCache(this.filePath),this.settings),t=document.createElement("div");t.classList.add(g),yield E.MarkdownRenderer.renderMarkdown(e,t,this.filePath,this),this.match.style.display="none";let i=this.containerEl.querySelector(v);i&&this.containerEl.removeChild(i),this.
|