Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ If an open note has collapsible admonitions, these commands can collapse or expa

This command opens a modal window to set the type, title, and collapse behavior of a new admonition. The plugin then generates the appropriate code block, which is inserted into the open editor.

### Collapse behavior in the modal

The **Make Collapsible** dropdown controls whether a collapse parameter is written into the inserted block. The dropdown initializes to match your configured *Default Collapse Type* if *Collapsible By Default* is enabled, or **Default** otherwise.

**For callouts** (`> [!type]` syntax):

| Selection | Written syntax | Behavior |
|---|---|---|
| **Default** | `> [!type]` | Obsidian's native behavior — collapsible, but neither forced open nor closed. |
| **Open** | `> [!type]+` | Starts expanded; can be collapsed. |
| **Closed** | `> [!type]-` | Starts collapsed; can be expanded. |
| **None** | `> [!type]` | Same as Default — callouts have no syntax to explicitly disable collapse. |

**For code block admonitions** (`` ```ad-type `` syntax):

| Selection | Written syntax | Behavior |
|---|---|---|
| **Default** | *(no collapse line)* | The plugin's *Collapsible By Default* setting applies at render time. |
| **Open** | `collapse: open` | Starts expanded; can be collapsed. |
| **Closed** | `collapse: closed` | Starts collapsed; can be expanded. |
| **None** | `collapse: none` | Removes collapsible behavior entirely, overriding *Collapsible By Default*. |

## Admonition-Specific Commands

Custom commands can be registered for each custom admonition type by clicking the **Register Commands** button next to the type in the Admonitions settings list.
Expand Down
27 changes: 5 additions & 22 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,7 @@ export default class ObsidianAdmonition extends Plugin {
) {
titleLine = `title: ${suggestor.title}\n`;
}
if (
(this.data.autoCollapse &&
suggestor.collapse !=
this.data.defaultCollapseType) ||
(!this.data.autoCollapse &&
suggestor.collapse != "none")
) {
if (suggestor.collapse !== "default") {
collapseLine = `collapse: ${suggestor.collapse}\n`;
}
editor.getDoc().replaceSelection(
Expand All @@ -263,22 +257,11 @@ ${editor.getDoc().getSelection()}
if (!suggestor.insert) return;
let title = "",
collapse = "";
if (
(this.data.autoCollapse &&
suggestor.collapse !=
this.data.defaultCollapseType) ||
(!this.data.autoCollapse &&
suggestor.collapse != "none")
) {
if (suggestor.collapse !== "default") {
switch (suggestor.collapse) {
case "open": {
collapse = "+";
break;
}
case "closed": {
collapse = "-";
break;
}
case "open": collapse = "+"; break;
case "closed": collapse = "-"; break;
case "none": collapse = ""; break;
}
}
if (
Expand Down
15 changes: 11 additions & 4 deletions src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ export class InsertAdmonitionModal extends Modal {
public type: string;
public title: string;
public noTitle: boolean;
public collapse: "open" | "closed" | "none" = this.plugin.data.autoCollapse
? this.plugin.data.defaultCollapseType
: "none";
public collapse: "open" | "closed" | "none" | "default" =
this.plugin.data.autoCollapse
? this.plugin.data.defaultCollapseType
: "default";
private element: HTMLElement;
admonitionEl: HTMLDivElement;
insert: boolean;
Expand Down Expand Up @@ -175,6 +176,7 @@ export class InsertAdmonitionModal extends Modal {

const collapseSetting = new Setting(contentEl);
collapseSetting.setName("Make Collapsible").addDropdown((d) => {
d.addOption("default", "Default");
d.addOption("open", "Open");
d.addOption("closed", "Closed");
d.addOption("none", "None");
Expand Down Expand Up @@ -212,14 +214,19 @@ export class InsertAdmonitionModal extends Modal {
this.admonitionEl.empty();
if (this.type && this.plugin.admonitions[this.type]) {
const admonition = this.plugin.admonitions[this.type];
const collapseForPreview = this.collapse === "default"
? (this.plugin.data.autoCollapse
? this.plugin.data.defaultCollapseType
: "none")
: this.collapse;
this.element = this.plugin.getAdmonitionElement(
this.type,
this.title,
admonition.icon,
admonition.injectColor ?? this.plugin.data.injectColor
? admonition.color
: null,
this.collapse
collapseForPreview
);
this.element.createDiv({
cls: "admonition-content",
Expand Down