Skip to content

Commit

Permalink
Introduce 'toc' shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
johansatge committed Jan 19, 2024
1 parent 282645f commit e80075e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if (isObsidian()) {
}

const codeblockId = 'table-of-contents'
const codeblockIdShort = 'toc'
const availableOptions = {
style: {
type: 'string',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit e80075e

Please # to comment.