From 099a80bb86712d4c177f6567d65ab8fd3c9ddfc1 Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Thu, 20 May 2021 08:22:38 -0400 Subject: [PATCH] 4.2.0 - Close #33 - Added Collapsible by Default and Default Collapse Type settings --- @types/types.ts | 4 +++- README.md | 14 ++++++++++++++ manifest.json | 2 +- package.json | 2 +- src/main.ts | 10 +++++++++- src/settings.ts | 31 ++++++++++++++++++++++++++++++- src/util.ts | 2 +- versions.json | 3 ++- 8 files changed, 61 insertions(+), 7 deletions(-) diff --git a/@types/types.ts b/@types/types.ts index bb6a72b..e1d1a36 100644 --- a/@types/types.ts +++ b/@types/types.ts @@ -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; admonitions: { [admonitionType: string]: Admonition }; -/* userAdmonitions: { [admonitionType: string]: Admonition }; + /* userAdmonitions: { [admonitionType: string]: Admonition }; syntaxHighlight: boolean; */ data: ISettingsData; turnOnSyntaxHighlighting: (types?: string[]) => void; diff --git a/README.md b/README.md index b9fb8d5..bd4cf66 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/manifest.json b/manifest.json index 352f120..5bb95fc 100644 --- a/manifest.json +++ b/manifest.json @@ -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", diff --git a/package.json b/package.json index 218869d..fe25117 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/main.ts b/src/main.ts index 8725750..8d574fd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -56,7 +56,9 @@ const DEFAULT_APP_SETTINGS: ISettingsData = { userAdmonitions: {}, syntaxHighlight: false, copyButton: false, - version: "" + version: "", + autoCollapse: false, + defaultCollapseType: "open" }; const ADMONITION_MAP: { @@ -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, diff --git a/src/settings.ts b/src/settings.ts index 1ab6644..8155823 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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.") @@ -291,7 +321,6 @@ class SettingsModal extends Modal { modal.onClose = validate; text.inputEl.onblur = validate; - }); const desc = iconSetting.descEl.createDiv(); diff --git a/src/util.ts b/src/util.ts index b256958..21fd13e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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"; } diff --git a/versions.json b/versions.json index 8c62a1c..a5d71c8 100644 --- a/versions.json +++ b/versions.json @@ -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" } \ No newline at end of file