This commit is contained in:
binghuai
2025-09-25 10:49:38 +08:00
parent 51608d4b52
commit 3b41b22f59
12 changed files with 114 additions and 34 deletions

View File

@@ -0,0 +1,13 @@
// Automatic Table Of Contents 1.7.3 (https://github.com/johansatge)
var c=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var d=c((ee,k)=>{var g=class{},p={},v=class{},w=t=>t;if(A()){let t=require("obsidian");g=t.Plugin,p=t.MarkdownRenderer,v=t.MarkdownRenderChild,w=t.htmlToMarkdown}k.exports={Plugin:g,MarkdownRenderer:p,MarkdownRenderChild:v,htmlToMarkdown:w};function A(){return typeof process!="object"?!0:!process.env||!process.env.JEST_WORKER_ID}});var y=c((re,b)=>{var s={title:{type:"string",default:"",comment:""},style:{type:"value",default:"nestedList",values:["nestedList","nestedOrderedList","inlineFirstLevel"],comment:"TOC style (nestedList|nestedOrderedList|inlineFirstLevel)"},minLevel:{type:"number",default:0,comment:"Include headings from the specified level"},maxLevel:{type:"number",default:0,comment:"Include headings up to the specified level"},include:{type:"regexp",default:null,comment:""},exclude:{type:"regexp",default:null,comment:""},includeLinks:{type:"boolean",default:!0,comment:"Make headings clickable"},hideWhenEmpty:{type:"boolean",default:!1,comment:"Hide TOC if no headings are found"},debugInConsole:{type:"boolean",default:!1,comment:"Print debug info in Obsidian console"}};b.exports={getOptionsDocs:P,parseOptionsFromSourceText:E};function P(){let t=[];for(let e of Object.keys(s)){let n=s[e],r=n.comment.length>0?` # ${n.comment}`:"",o=n.default!==null?n.default:"";t.push(`${e}: ${o}${r}`)}return t.join(`
`)}function E(t=""){let e={};for(let n of Object.keys(s))e[n]=s[n].default;for(let n of t.split(`
`)){let r=R(n);r!==null&&(e[r.name]=r.value)}return e}function R(t){let e=t.match(/([a-zA-Z0-9._ ]+):(.*)/);if(t.startsWith("#")||!e)return null;let n=e[1].trim(),r=s[n],o=e[2].trim();(!r||!["string","regexp"].includes(r.type))&&(o=o.replace(/#[^#]*$/,"").trim());let a=new Error(`Invalid value for \`${n}\``);if(r&&r.type==="number"){let i=Number.parseInt(o);if(i<0)throw a;return{name:n,value:i}}if(r&&r.type==="boolean"){if(!["true","false"].includes(o))throw a;return{name:n,value:o==="true"}}if(r&&r.type==="value"){if(!r.values.includes(o))throw a;return{name:n,value:o}}if(r&&r.type==="string")return{name:n,value:o};if(r&&r.type==="regexp"){if(o==="null"||o.length===0)return null;try{let i=/^\/(.*)\/([a-z]*)/.exec(o);if(!i)throw new Error("Invalid regexp");let l=new RegExp(i[1],i[2]);return{name:n,value:l}}catch{throw a}}return null}});var x=c((oe,L)=>{var{htmlToMarkdown:S}=d();L.exports={isHeadingAllowed:_,getFormattedMarkdownHeading:W};function _(t,e){return e.include?e.include.test(t):e.exclude?!e.exclude.test(t):!0}function W(t,e){if(e.includeLinks){let n=t;n=$(n),n=j(n),n=M(n,!1);let r=t;return r=M(r,!0),r=q(r),`[[#${r}|${n}]]`}return t}function $(t){return t.replaceAll("*","").replaceAll(/(\W|^)_+(\S)(.*?\S)?_+(\W|$)/g,"$1$2$3$4").replaceAll("`","").replaceAll("==","").replaceAll("~~","").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1")}function j(t){return $(S(t))}function M(t,e){return t.replace(/\[\[([^\]]+)\|([^\]]+)\]\]/g,e?"$1 $2":"$2").replace(/\[\[([^\]]+)\]\]/g,"$1").replaceAll("[[","").replaceAll("| ",e?"":"- ").replaceAll("|",e?" ":"-")}function q(t){return t.replaceAll("#"," ")}});var F=c((le,H)=>{var{isHeadingAllowed:C,getFormattedMarkdownHeading:I}=x();H.exports={getMarkdownFromHeadings:N};function N(t,e){let n={nestedList:D,nestedOrderedList:B,inlineFirstLevel:z},r="";if(e.title&&e.title.length>0){let a=e.style==="inlineFirstLevel"?" ":`
`;r+=`${e.title}${a}`}let o=n[e.style](t,e);return o===null?e.hideWhenEmpty?"":`${r}_Table of contents: no headings found_`:r+o}function D(t,e){return O(t,!1,e)}function B(t,e){return O(t,!0,e)}function O(t,e,n){let r=e?"1.":"-",o=[],a=n.minLevel>0?n.minLevel:Math.min(...t.map(l=>l.level)),i=0;for(let l of t)if(!(i>0&&l.level>i)){if(l.level<=i&&(i=0),!C(l.heading,n)){i=l.level;continue}l.level<a||n.maxLevel>0&&l.level>n.maxLevel||l.heading.length!==0&&o.push(`${" ".repeat(l.level-a)}${r} ${I(l.heading,n)}`)}return o.length>0?o.join(`
`):null}function z(t,e){let n=e.minLevel>0?e.minLevel:Math.min(...t.map(o=>o.level)),r=t.filter(o=>o.level===n).filter(o=>o.heading.length>0).filter(o=>C(o.heading,e)).map(o=>I(o.heading,e));return r.length>0?r.join(" | "):null}});var{Plugin:J,MarkdownRenderer:T,MarkdownRenderChild:K}=d(),{getOptionsDocs:V,parseOptionsFromSourceText:Z}=y(),{getMarkdownFromHeadings:G}=F(),h="table-of-contents",Q="toc",m=class extends J{async onload(){let e=(n,r,o)=>{o.addChild(new f(this.app,r,o.sourcePath,n))};this.registerMarkdownCodeBlockProcessor(h,e),this.registerMarkdownCodeBlockProcessor(Q,e),this.addCommand({id:"insert-automatic-table-of-contents",name:"Insert table of contents",editorCallback:U}),this.addCommand({id:"insert-automatic-table-of-contents-docs",name:"Insert table of contents (with available options)",editorCallback:X})}};function U(t){let e=`\`\`\`${h}
\`\`\``;t.replaceRange(e,t.getCursor())}function X(t){let e=[`\`\`\`${h}
${V()}
\`\`\``];t.replaceRange(e.join(`
`),t.getCursor())}var f=class extends K{constructor(e,n,r,o){super(n),this.app=e,this.element=n,this.sourcePath=r,this.sourceText=o}onload(){this.render(),this.registerEvent(this.app.metadataCache.on("changed",this.onMetadataChange.bind(this)))}onMetadataChange(){this.render()}render(){try{let e=Z(this.sourceText);e.debugInConsole&&u("Options",e);let n=this.app.metadataCache.getCache(this.sourcePath),r=n?.headings?n.headings:[];e.debugInConsole&&u("Headings",r);let o=G(r,e);e.debugInConsole&&u("Markdown",o),this.element.empty(),T.renderMarkdown(o,this.element,this.sourcePath,this)}catch(e){let n=`_\u{1F4A5} Could not render table of contents (${e.message})_`;T.renderMarkdown(n,this.element,this.sourcePath,this)}}};function u(t,e){console.log(`%cAutomatic Table Of Contents %c${t}:
`,"color: orange; font-weight: bold","font-weight: bold",e)}module.exports=m;
/* nosourcemap */

View File

@@ -0,0 +1,10 @@
{
"id": "automatic-table-of-contents",
"name": "Automatic Table Of Contents",
"version": "1.7.3",
"minAppVersion": "1.3.0",
"description": "Create a table of contents in a note, that updates itself when the note changes",
"author": "Johan Satgé",
"authorUrl": "https://github.com/johansatge",
"isDesktopOnly": false
}

View File

@@ -1,5 +1,7 @@
{
"obsidian-prism-theme@@color-schemes-lt": "pt-color-scheme-custom-lt",
"obsidian-prism-theme@@color-schemes-dt": "pt-color-scheme-custom-dt",
"obsidian-prism-theme@@pt-titlebar-hide-text": false
"obsidian-prism-theme@@pt-titlebar-hide-text": false,
"shimmering-focus@@active-line-highlight": "active-line-gutter",
"shimmering-focus@@alt-colorschemes": "colorscheme-gamma"
}

View File

@@ -1 +1 @@
{"月度/8月/8月.md":{"scroll":347.8164,"cursor":{"from":{"ch":13,"line":317},"to":{"ch":22,"line":317}}},"材料/服务器.md":{"scroll":5.2801,"cursor":{"from":{"ch":0,"line":25},"to":{"ch":0,"line":25}}},"月度/9月/9月.md":{"scroll":280.5761,"cursor":{"from":{"ch":0,"line":294},"to":{"ch":0,"line":294}}},"月度/7月/7月.md":{"scroll":138.3906,"cursor":{"from":{"ch":29,"line":147},"to":{"ch":29,"line":147}}},"月度/6月/6月.md":{"scroll":58.2917,"cursor":{"from":{"ch":72,"line":63},"to":{"ch":72,"line":63}}},"月度/5月/5月.md":{"scroll":93.1957,"cursor":{"from":{"ch":20,"line":105},"to":{"ch":20,"line":105}}},"月度/4月/4月.md":{"scroll":120.1806,"cursor":{"from":{"ch":20,"line":139},"to":{"ch":20,"line":139}}},"月度/3月/3月.md":{"scroll":32.7083,"cursor":{"from":{"ch":6,"line":39},"to":{"ch":6,"line":39}}},"月度/7月/7月工作总结及8月工作计划.md":{"scroll":0,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/6月/6月份晨午检bug修复.md":{"scroll":307.9981,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/7月/设备管理中心研发记录.md":{"scroll":110.1015,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/8月/CA身份认证app/CA身份认证app流程图.md":{"scroll":5.8654,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/9月/常见病/20250903常见病优化沟通.md":{"scroll":0.7205,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/9月/汇海/对接主机/不登录模式接口文档.md":{"scroll":0,"cursor":{"from":{"ch":0,"line":7},"to":{"ch":0,"line":7}}},"月度/9月/汇海/对接主机/登录算法和密钥.md":{"scroll":0,"cursor":{"from":{"ch":0,"line":9},"to":{"ch":0,"line":9}}},"月度/9月/汇海/对接主机/华夏汇海接口文档.md":{"scroll":1653.2083,"cursor":{"from":{"ch":19,"line":1328},"to":{"ch":19,"line":1328}}},"材料/配置/Obsidian快捷键.md":{"scroll":0,"cursor":{"from":{"ch":18,"line":16},"to":{"ch":18,"line":16}}},"材料/配置/工具.md":{"scroll":0,"cursor":{"from":{"ch":50,"line":0},"to":{"ch":50,"line":0}}}}
{"月度/8月/8月.md":{"scroll":451.6552,"cursor":{"from":{"ch":6,"line":465},"to":{"ch":6,"line":465}}},"材料/服务器.md":{"scroll":0.687,"cursor":{"from":{"ch":7,"line":10},"to":{"ch":17,"line":10}}},"月度/9月/9月.md":{"scroll":294.4507,"cursor":{"from":{"ch":0,"line":307},"to":{"ch":0,"line":307}}},"月度/7月/7月.md":{"scroll":138.3906,"cursor":{"from":{"ch":29,"line":147},"to":{"ch":29,"line":147}}},"月度/6月/6月.md":{"scroll":58.2917,"cursor":{"from":{"ch":72,"line":63},"to":{"ch":72,"line":63}}},"月度/5月/5月.md":{"scroll":93.1957,"cursor":{"from":{"ch":20,"line":105},"to":{"ch":20,"line":105}}},"月度/4月/4月.md":{"scroll":120.1806,"cursor":{"from":{"ch":20,"line":139},"to":{"ch":20,"line":139}}},"月度/3月/3月.md":{"scroll":32.7083,"cursor":{"from":{"ch":6,"line":39},"to":{"ch":6,"line":39}}},"月度/7月/7月工作总结及8月工作计划.md":{"scroll":0,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/6月/6月份晨午检bug修复.md":{"scroll":307.9981,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/7月/设备管理中心研发记录.md":{"scroll":110.1015,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/8月/CA身份认证app/CA身份认证app流程图.md":{"scroll":5.8654,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/9月/常见病/20250903常见病优化沟通.md":{"scroll":0.7205,"cursor":{"from":{"ch":0,"line":0},"to":{"ch":0,"line":0}}},"月度/9月/汇海/对接主机/不登录模式接口文档.md":{"scroll":36.3079,"cursor":{"from":{"ch":10,"line":11},"to":{"ch":10,"line":11}}},"月度/9月/汇海/对接主机/登录算法和密钥.md":{"scroll":0,"cursor":{"from":{"ch":0,"line":9},"to":{"ch":0,"line":9}}},"月度/9月/汇海/对接主机/华夏汇海接口文档.md":{"scroll":1653.2083,"cursor":{"from":{"ch":19,"line":1328},"to":{"ch":19,"line":1328}}},"材料/配置/Obsidian快捷键.md":{"scroll":0,"cursor":{"from":{"ch":18,"line":16},"to":{"ch":18,"line":16}}},"材料/配置/工具.md":{"scroll":0,"cursor":{"from":{"ch":50,"line":0},"to":{"ch":50,"line":0}}}}