Skip to content

Commit

Permalink
Merge pull request #29 from johansatge/toc-shorthand
Browse files Browse the repository at this point in the history
Introduce 'toc' shorthand
  • Loading branch information
johansatge committed Jan 19, 2024
2 parents 282645f + e80075e commit 0952621
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 0952621

Please # to comment.