From e80075e07b0fed2e7ae7c8fca4e6a4f9f91545b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Satg=C3=A9?= Date: Fri, 19 Jan 2024 22:07:36 +0100 Subject: [PATCH] Introduce 'toc' shorthand --- README.md | 2 +- main.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d1ca6f7..3ee1d76 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Alternatively, download the [latest release](https://github.com/johansatge/obsid ## Usage -Insert a codeblock with the `table-of-contents` syntax. +Insert a codeblock with the `table-of-contents` (or its short version `toc`) syntax. ```` ```table-of-contents diff --git a/main.js b/main.js index 9a5ab5b..7f6a4a7 100644 --- a/main.js +++ b/main.js @@ -10,6 +10,7 @@ if (isObsidian()) { } const codeblockId = 'table-of-contents' +const codeblockIdShort = 'toc' const availableOptions = { style: { type: 'string', @@ -41,9 +42,11 @@ const availableOptions = { class ObsidianAutomaticTableOfContents extends Plugin { async onload() { - this.registerMarkdownCodeBlockProcessor(codeblockId, (sourceText, element, context) => { + const handler = (sourceText, element, context) => { context.addChild(new Renderer(this.app, element, context.sourcePath, sourceText)) - }) + } + this.registerMarkdownCodeBlockProcessor(codeblockId, handler) + this.registerMarkdownCodeBlockProcessor(codeblockIdShort, handler) this.addCommand({ id: 'insert-automatic-table-of-contents', name: 'Insert table of contents',