diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.js b/src/public/app/widgets/attribute_widgets/attribute_detail.js index 4645d8211..e46625ad5 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_detail.js +++ b/src/public/app/widgets/attribute_widgets/attribute_detail.js @@ -227,7 +227,9 @@ const ATTR_HELP = {
  • Log for \${now.format('YYYY-MM-DD HH:mm:ss')}
  • - See wiki with details, API docs for parentNote and now for details.` + See wiki with details, API docs for parentNote and now for details.`, + "template": "This note will appear in the selection of available template when creating new note", + "toc": "#toc or #toc=show will force the Table of Contents to be shown, #toc=hide will force hiding it. If the label doesn't exist, the global setting is observed" }, "relation": { "runOnNoteCreation": "executes when note is created on backend", diff --git a/src/public/app/widgets/toc.js b/src/public/app/widgets/toc.js index c127083f1..22837a809 100644 --- a/src/public/app/widgets/toc.js +++ b/src/public/app/widgets/toc.js @@ -74,9 +74,7 @@ export default class TocWidget extends CollapsibleWidget { } isEnabled() { - return super.isEnabled() - && this.note.type === 'text' - && !this.note.hasLabel('noToc'); + return super.isEnabled() && this.note.type === 'text'; } async doRenderBody() { @@ -85,6 +83,14 @@ export default class TocWidget extends CollapsibleWidget { } async refreshWithNote(note) { + const tocLabel = note.getLabel('toc'); + + if (tocLabel?.value === 'hide') { + this.toggleInt(false); + this.triggerCommand("reevaluateIsEnabled"); + return; + } + let $toc = "", headingCount = 0; // Check for type text unconditionally in case alwaysShowWidget is set if (this.note.type === 'text') { @@ -93,7 +99,11 @@ export default class TocWidget extends CollapsibleWidget { } this.$toc.html($toc); - this.toggleInt(headingCount >= options.getInt('minTocHeadings')); + this.toggleInt( + ["", "show"].includes(tocLabel?.value) + || headingCount >= options.getInt('minTocHeadings') + ); + this.triggerCommand("reevaluateIsEnabled"); } @@ -241,7 +251,7 @@ export default class TocWidget extends CollapsibleWidget { if (loadResults.isNoteContentReloaded(this.noteId)) { await this.refresh(); } else if (loadResults.getAttributes().find(attr => attr.type === 'label' - && (attr.name.toLowerCase().includes('readonly') || attr.name === 'noToc') + && (attr.name.toLowerCase().includes('readonly') || attr.name === 'toc') && attributeService.isAffecting(attr, this.note))) { await this.refresh(); diff --git a/src/services/builtin_attributes.js b/src/services/builtin_attributes.js index bda0f7654..814f1deaf 100644 --- a/src/services/builtin_attributes.js +++ b/src/services/builtin_attributes.js @@ -52,6 +52,7 @@ module.exports = [ { type: 'label', name: 'hideRelations' }, { type: 'label', name: 'titleTemplate', isDangerous: true }, { type: 'label', name: 'template' }, + { type: 'label', name: 'toc' }, // relation names { type: 'relation', name: 'internalLink' },