Skip to content

Commit

Permalink
4.2.0
Browse files Browse the repository at this point in the history
- Close #33 - Added Collapsible by Default and Default Collapse Type settings
  • Loading branch information
valentine195 committed May 20, 2021
1 parent e21db64 commit 099a80b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
4 changes: 3 additions & 1 deletion @types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export interface ISettingsData {
};
syntaxHighlight: boolean;
copyButton: boolean;
autoCollapse: boolean;
defaultCollapseType: string;
version: string;
}
export declare class ObsidianAdmonitionPlugin extends Plugin_2 {
removeAdmonition: (admonition: Admonition) => Promise<void>;
admonitions: { [admonitionType: string]: Admonition };
/* userAdmonitions: { [admonitionType: string]: Admonition };
/* userAdmonitions: { [admonitionType: string]: Admonition };
syntaxHighlight: boolean; */
data: ISettingsData;
turnOnSyntaxHighlighting: (types?: string[]) => void;
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Use the `collapse` parameter to create a collapsible admonition.

If a blank title is provided, the collapse parameter will not do anything.

Admonitions may be set to be collapsible by default in settings.

![](https://raw.githubusercontent.com/valentine195/obsidian-admonition/master/images/collapse.gif)

## Nesting Admonitions
Expand Down Expand Up @@ -281,6 +283,18 @@ An icon without a title will have this CSS:

Turns on an experimental mode that uses Obsidian's markdown syntax highlighter inside admonition code blocks.

### Collapsible By Default

Admonitions will be automatically rendered as collapsible (open) by default.

If set, use `collapse: none` in an admonition block to override.

### Default Collapse Type

**This setting is only available if Collapsible By Default is ON**

Admonitions will be automatically rendered as opened or closed when collapsible by default.

### Copy Button

Adds a "copy content" button to every admonition block.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-admonition",
"name": "Admonition",
"version": "4.1.7",
"version": "4.2.0",
"minAppVersion": "0.11.0",
"description": "Admonition block-styled content for Obsidian.md",
"author": "Jeremy Valentine",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-admonition",
"version": "4.1.7",
"version": "4.2.0",
"description": "Admonition block-styled content for Obsidian.md",
"main": "main.js",
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const DEFAULT_APP_SETTINGS: ISettingsData = {
userAdmonitions: {},
syntaxHighlight: false,
copyButton: false,
version: ""
version: "",
autoCollapse: false,
defaultCollapseType: "open"
};

const ADMONITION_MAP: {
Expand Down Expand Up @@ -308,6 +310,12 @@ export default class ObsidianAdmonition
content = split.join("\n");
}

if (this.data.autoCollapse && !collapse) {
collapse = this.data.defaultCollapseType ?? "open";
} else if (collapse.trim() === "none") {
collapse = "";
}

let admonitionElement = getAdmonitionElement(
type,
title,
Expand Down
31 changes: 30 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,36 @@ export default class AdmonitionSetting extends PluginSettingTab {
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName("Collapsible by Default")
.setDesc(
"All admonitions will be collapsible by default. Use collapse: none to prevent."
)
.addToggle((t) => {
t.setValue(this.plugin.data.autoCollapse).onChange(
async (v) => {
this.plugin.data.autoCollapse = v;
this.display();
await this.plugin.saveSettings();
}
);
});
if (this.plugin.data.autoCollapse) {
new Setting(containerEl)
.setName("Default Collapse Type")
.setDesc(
"Collapsible admonitions will be either opened or closed."
)
.addDropdown((d) => {
d.addOption("open", "open");
d.addOption("closed", "closed");
d.setValue(this.plugin.data.defaultCollapseType);
d.onChange(async (v) => {
this.plugin.data.defaultCollapseType = v;
await this.plugin.saveSettings();
});
});
}
new Setting(containerEl)
.setName("Add Copy Button")
.setDesc("Add a 'copy content' button to admonitions.")
Expand Down Expand Up @@ -291,7 +321,6 @@ class SettingsModal extends Modal {
modal.onClose = validate;

text.inputEl.onblur = validate;

});

const desc = iconSetting.descEl.createDiv();
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function getParametersFromSource(type: string, src: string) {
Object.prototype.hasOwnProperty.call(params, "collapse") &&
(params.collapse.length == 0 ||
params.collapse === undefined ||
collapse !== "open")
(collapse !== "open" && collapse !== "none"))
) {
collapse = "closed";
}
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"3.2.2": "0.11.0",
"3.3.4": "0.11.0",
"4.0.1": "0.11.0",
"4.1.7": "0.11.0"
"4.1.7": "0.11.0",
"4.2.0": "0.11.0"
}

0 comments on commit 099a80b

Please sign in to comment.