Add option to personalize toc header (#1243)

pull/1246/head^2
KitAmbraid 2025-02-22 12:06:42 +01:00 committed by GitHub
parent f553c62950
commit 7f9615ea9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View File

@ -15,6 +15,7 @@ type TocConfig = {
// Don't show the TOC if there are more than this many headers
maxHeaders?: number;
header?: boolean;
headerText?: string;
};
export async function widget(
@ -58,7 +59,7 @@ export async function widget(
// Too many headers, not showing TOC
return null;
}
let headerText = "# Table of Contents\n";
let headerText = config.headerText ?? "# Table of Contents\n";
if (config.header === false) {
headerText = "";
}

View File

@ -16,6 +16,7 @@ To have a ToC added to all pages with a larger (e.g. 3) number of headings, it i
In the body of the `toc` code widget you can configure a few options:
* `header`: by default a “Table of Contents” header is added to the ToC, set this to `false` to disable rendering this header
* `headerText`: by default "# Table of Contents\n". Change it to change the rendering of this header
* `minHeaders`: only renders a ToC if the number of headers in the current page exceeds this number, otherwise renders an empty widget
* `maxHeaders`: only renders a ToC if the number of headers in the current page is below this number, otherwise renders an empty widget