1
0

Auto down-adjust sub-headers in TOC

This commit is contained in:
Zef Hemel 2024-01-02 11:40:59 +01:00
parent ba90397c02
commit 11693fbd00
2 changed files with 10 additions and 5 deletions

View File

@ -52,10 +52,15 @@ export async function renderTOC(): Promise<CodeWidgetContent | null> {
return null; return null;
} }
// console.log("Headers", headers); // console.log("Headers", headers);
// Adjust level down if only sub-headers are used
const minLevel = headers.reduce(
(min, header) => Math.min(min, header.level),
6,
);
const renderedMd = "# Table of Contents\n" + const renderedMd = "# Table of Contents\n" +
headers.map((header) => headers.map((header) =>
`${ `${
" ".repeat((header.level - 1) * 2) " ".repeat((header.level - minLevel) * 2)
}* [[${page}@${header.pos}|${header.name}]]` }* [[${page}@${header.pos}|${header.name}]]`
).join("\n"); ).join("\n");
// console.log("Markdown", renderedMd); // console.log("Markdown", renderedMd);

View File

@ -2,20 +2,20 @@
The [[Plugs/Template]] plug implements a few templating mechanisms. The [[Plugs/Template]] plug implements a few templating mechanisms.
### Daily Note # Daily Note
The {[Open Daily Note]} command navigates (or creates) a daily note prefixed with a 📅 emoji by default, but this is configurable via the `dailyNotePrefix` setting in `SETTINGS`. If you have a page template (see above) named `template/page/Daily Note` it will use this as a template, otherwise, the page will just be empty (this path is also configurable via the `dailyNoteTemplate` setting). The {[Open Daily Note]} command navigates (or creates) a daily note prefixed with a 📅 emoji by default, but this is configurable via the `dailyNotePrefix` setting in `SETTINGS`. If you have a page template (see above) named `template/page/Daily Note` it will use this as a template, otherwise, the page will just be empty (this path is also configurable via the `dailyNoteTemplate` setting).
### Weekly Note # Weekly Note
The {[Open Weekly Note]} command navigates (or creates) a weekly note prefixed The {[Open Weekly Note]} command navigates (or creates) a weekly note prefixed
with a 🗓️ emoji by default, but this is configurable via the `weeklyNotePrefix` setting in `SETTINGS`. If you have a page template (see above) named `template/page/Weekly Note` it will use this as a template, otherwise, the page will just be empty. with a 🗓️ emoji by default, but this is configurable via the `weeklyNotePrefix` setting in `SETTINGS`. If you have a page template (see above) named `template/page/Weekly Note` it will use this as a template, otherwise, the page will just be empty.
### Quick Note # Quick Note
The {[Quick Note]} command will navigate to an empty page named with the current date and time prefixed with a 📥 emoji, but this is configurable via the `quickNotePrefix` in `SETTINGS`. The use case is to take a quick note outside of your current context. The {[Quick Note]} command will navigate to an empty page named with the current date and time prefixed with a 📥 emoji, but this is configurable via the `quickNotePrefix` in `SETTINGS`. The use case is to take a quick note outside of your current context.
## Built-in slash commands # Built-in slash commands
* `/frontmatter`: Insert [[Frontmatter]] * `/frontmatter`: Insert [[Frontmatter]]
* `/h1` - `/h4`: turn the current line into a header * `/h1` - `/h4`: turn the current line into a header
* `/code`: insert a fenced code block * `/code`: insert a fenced code block