Skip to content

Commit 99f63fa

Browse files
committed
3.3.0
- Added commands to open and collapse all admonitions in active note (closes #19 ) - Admonition icons now respect the font size of the admonition title (closes #14 ) - Collapse handle now centers inside the title element - CSS changes
1 parent 796f979 commit 99f63fa

File tree

7 files changed

+133
-68
lines changed

7 files changed

+133
-68
lines changed

README.md

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,18 @@ This is all of the CSS applied to the admonitions. Override these classes to cus
121121
Every admonition receives the following CSS classes:
122122

123123
```css
124+
:root {
125+
--admonition-details-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59 16.58L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42z'/></svg>");
126+
}
127+
128+
.use-csv-marker > svg {
129+
color: yellow;
130+
margin-right: 8px;
131+
}
132+
124133
.admonition {
125134
margin: 1.5625em 0;
126-
padding: 0 0.6rem;
135+
padding: 0;
127136
overflow: hidden;
128137
color: var(--text-normal);
129138
page-break-inside: avoid;
@@ -135,30 +144,36 @@ Every admonition receives the following CSS classes:
135144

136145
.admonition-title {
137146
position: relative;
138-
margin: 0 -0.6rem 0 -0.8rem;
139-
padding: 0.4rem 0.6rem 0.4rem 2rem;
147+
padding: 0.6rem 0.25em;
140148
font-weight: 700;
141-
border-left: 0.2rem solid;
142149
background-color: rgba(var(--admonition-color), 0.1);
143150
}
151+
.admonition-title > * {
152+
display: flex;
153+
justify-content: flex-start;
154+
margin-top: 0 !important;
155+
margin-bottom: 0 !important;
156+
}
144157

145158
.admonition-title-icon {
146-
position: absolute;
147-
left: 0.6rem;
148-
width: 1.25rem;
149-
height: 1.25rem;
150159
color: rgb(var(--admonition-color));
151160
display: flex;
152-
justify-content: center;
153161
align-items: center;
162+
justify-content: center;
163+
margin: 0 0.5em 0 0.25em;
164+
min-width: 1em;
154165
}
155166

156167
.admonition-title.no-title {
157168
display: none;
158169
}
159170

160171
.admonition > .admonition-title.no-title + .admonition-content {
161-
margin: 1em 0;
172+
margin: 1rem 0;
173+
}
174+
175+
.admonition-content {
176+
margin: 0 0.6rem;
162177
}
163178
```
164179

@@ -188,7 +203,6 @@ details.admonition > summary {
188203
list-style: none;
189204
display: block;
190205
min-height: 1rem;
191-
padding: 0.4rem 1.8rem 0.4rem 2rem;
192206
border-top-left-radius: 0.1rem;
193207
border-top-right-radius: 0.1rem;
194208
cursor: pointer;
@@ -197,24 +211,29 @@ details.admonition > summary::-webkit-details-marker {
197211
display: none;
198212
}
199213

200-
details.admonition > summary:after {
214+
details.admonition > summary > .collapser {
201215
position: absolute;
202-
top: 8px;
216+
top: 50%;
203217
right: 8px;
204-
width: 20px;
205-
height: 20px;
218+
transform: translateY(-50%);
219+
content: "";
220+
}
221+
222+
details.admonition > summary > .collapser > .handle {
223+
transform: rotate(0deg);
224+
transition: transform 0.25s;
206225
background-color: currentColor;
207-
-webkit-mask-image: var(--admonition-details-icon);
208-
mask-image: var(--admonition-details-icon);
209226
-webkit-mask-repeat: no-repeat;
210227
mask-repeat: no-repeat;
211228
-webkit-mask-size: contain;
212229
mask-size: contain;
213-
transform: rotate(0deg);
214-
transition: transform 0.25s;
215-
content: "";
230+
-webkit-mask-image: var(--admonition-details-icon);
231+
mask-image: var(--admonition-details-icon);
232+
width: 20px;
233+
height: 20px;
216234
}
217-
details.admonition[open] > summary:after {
235+
236+
details.admonition[open] > summary > .collapser > .handle {
218237
transform: rotate(90deg);
219238
}
220239
```
@@ -238,6 +257,13 @@ An icon without a title will have this CSS:
238257

239258
# Version History
240259

260+
## 3.3.0
261+
262+
- Added commands to open and collapse all admonitions in active note
263+
- Admonition icons now respect the font size of the admonition title
264+
- Collapse handle now centers inside the title element
265+
- CSS changes
266+
-
241267
## 3.2.0
242268

243269
- Added a setting to turn on default Obsidian syntax highlighting to admonition code block types

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-admonition",
33
"name": "Admonition",
4-
"version": "3.2.2",
4+
"version": "3.3.0",
55
"minAppVersion": "0.11.0",
66
"description": "Admonition block-styled content for Obsidian.md",
77
"author": "Jeremy Valentine",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-admonition",
3-
"version": "3.2.2",
3+
"version": "3.3.0",
44
"description": "Admonition block-styled content for Obsidian.md",
55
"main": "main.js",
66
"scripts": {

src/main.css

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
.admonition {
1212
margin: 1.5625em 0;
13-
padding: 0 0.6rem;
13+
padding: 0;
1414
overflow: hidden;
1515
color: var(--text-normal);
1616
page-break-inside: avoid;
@@ -22,35 +22,36 @@
2222

2323
.admonition-title {
2424
position: relative;
25-
margin: 0 -0.6rem 0 -0.8rem;
26-
padding: 0.4rem 0.6rem 0.4rem 2rem;
25+
padding: 0.6rem 0.25em;
2726
font-weight: 700;
28-
border-left: 0.2rem solid;
2927
background-color: rgba(var(--admonition-color), 0.1);
3028
}
31-
32-
.admonition-title p {
29+
.admonition-title > * {
30+
display: flex;
31+
justify-content: flex-start;
3332
margin-top: 0 !important;
3433
margin-bottom: 0 !important;
3534
}
3635

3736
.admonition-title-icon {
38-
position: absolute;
39-
left: 0.6rem;
40-
top: 50%;
41-
transform: translateY(-50%);
37+
color: rgb(var(--admonition-color));
4238
display: flex;
39+
align-items: center;
4340
justify-content: center;
44-
width: 1.25rem;
45-
color: rgb(var(--admonition-color));
41+
margin: 0 0.5em 0 0.25em;
42+
min-width: 1em;
4643
}
4744

4845
.admonition-title.no-title {
4946
display: none;
5047
}
5148

5249
.admonition > .admonition-title.no-title + .admonition-content {
53-
margin: 1em 0;
50+
margin: 1rem 0;
51+
}
52+
53+
.admonition-content {
54+
margin: 0 0.6rem;
5455
}
5556

5657
details.admonition:not([open]) {
@@ -62,7 +63,6 @@ details.admonition > summary {
6263
list-style: none;
6364
display: block;
6465
min-height: 1rem;
65-
padding: 0.4rem 1.8rem 0.4rem 2rem;
6666
border-top-left-radius: 0.1rem;
6767
border-top-right-radius: 0.1rem;
6868
cursor: pointer;
@@ -71,24 +71,29 @@ details.admonition > summary::-webkit-details-marker {
7171
display: none;
7272
}
7373

74-
details.admonition > summary:after {
74+
details.admonition > summary > .collapser {
7575
position: absolute;
76-
top: 8px;
76+
top: 50%;
7777
right: 8px;
78-
width: 20px;
79-
height: 20px;
78+
transform: translateY(-50%);
79+
content: "";
80+
}
81+
82+
details.admonition > summary > .collapser > .handle {
83+
transform: rotate(0deg);
84+
transition: transform 0.25s;
8085
background-color: currentColor;
81-
-webkit-mask-image: var(--admonition-details-icon);
82-
mask-image: var(--admonition-details-icon);
8386
-webkit-mask-repeat: no-repeat;
8487
mask-repeat: no-repeat;
8588
-webkit-mask-size: contain;
8689
mask-size: contain;
87-
transform: rotate(0deg);
88-
transition: transform 0.25s;
89-
content: "";
90+
-webkit-mask-image: var(--admonition-details-icon);
91+
mask-image: var(--admonition-details-icon);
92+
width: 20px;
93+
height: 20px;
9094
}
91-
details.admonition[open] > summary:after {
95+
96+
details.admonition[open] > summary > .collapser > .handle {
9297
transform: rotate(90deg);
9398
}
9499

src/main.ts

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
MarkdownPostProcessorContext,
33
MarkdownRenderChild,
44
MarkdownRenderer,
5+
MarkdownView,
56
Notice,
67
Plugin
78
} from "obsidian";
@@ -176,6 +177,39 @@ export default class ObsidianAdmonition
176177
if (this.syntaxHighlight) {
177178
this.turnOnSyntaxHighlighting();
178179
}
180+
181+
this.addCommand({
182+
id: "collapse-admonitions",
183+
name: "Collapse Admonitions in Note",
184+
callback: () => {
185+
let view = this.app.workspace.getActiveViewOfType(MarkdownView);
186+
if (!view || !(view instanceof MarkdownView)) return;
187+
188+
let admonitions = view.contentEl.querySelectorAll(
189+
"details[open]"
190+
);
191+
for (let i = 0; i < admonitions.length; i++) {
192+
let admonition = admonitions[i];
193+
admonition.removeAttribute("open");
194+
}
195+
}
196+
});
197+
this.addCommand({
198+
id: "open-admonitions",
199+
name: "Open Admonitions in Note",
200+
callback: () => {
201+
let view = this.app.workspace.getActiveViewOfType(MarkdownView);
202+
if (!view || !(view instanceof MarkdownView)) return;
203+
204+
let admonitions = view.contentEl.querySelectorAll(
205+
"details:not([open])"
206+
);
207+
for (let i = 0; i < admonitions.length; i++) {
208+
let admonition = admonitions[i];
209+
admonition.setAttribute("open", "open");
210+
}
211+
}
212+
});
179213
}
180214
turnOnSyntaxHighlighting(types: string[] = Object.keys(this.admonitions)) {
181215
if (!this.syntaxHighlight) return;
@@ -403,18 +437,23 @@ export default class ObsidianAdmonition
403437
});
404438
}
405439

406-
titleEl.createDiv({
407-
cls: `admonition-title-icon`
408-
}).innerHTML = icon(
409-
findIconDefinition({
410-
iconName: this.admonitions[type].icon
411-
})
412-
).html[0];
413-
414-
let titleContentEl = createDiv();
440+
let titleContentEl = createDiv("title-content");
415441
MarkdownRenderer.renderMarkdown(title, titleContentEl, "", null);
442+
443+
const iconEl = createDiv("admonition-title-icon");
444+
iconEl.appendChild(
445+
icon(
446+
findIconDefinition({
447+
iconName: this.admonitions[type].icon
448+
})
449+
).node[0]
450+
);
451+
titleContentEl.children[0].prepend(iconEl);
452+
titleEl.appendChild(titleContentEl.children[0]);
416453

417-
titleEl.appendChild(titleContentEl);
454+
if (collapse) {
455+
titleEl.createDiv("collapser").createDiv("handle");
456+
}
418457
return admonition;
419458
}
420459
async onunload() {

src/settings.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,7 @@ class SettingsModal extends Modal {
276276
el.value = rgbToHex(this.color);
277277
el.oninput = ({ target }) => {
278278
let color = hexToRgb((target as HTMLInputElement).value);
279-
console.log(
280-
"🚀 ~ file: settings.ts ~ line 118 ~ SettingsModal ~ display ~ color",
281-
color
282-
);
279+
283280
if (!color) return;
284281
this.color = `${color.r}, ${color.g}, ${color.b}`;
285282
previewEl.setAttribute(
@@ -397,10 +394,7 @@ class SettingsModal extends Modal {
397394

398395
function hexToRgb(hex: string) {
399396
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
400-
console.log(
401-
"🚀 ~ file: settings.ts ~ line 156 ~ hexToRgb ~ result",
402-
result
403-
);
397+
404398
return result
405399
? {
406400
r: parseInt(result[1], 16),

versions.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2-
"0.2.3": "0.11.0",
2+
"0.2.3": "0.11.0",
33
"1.0.1": "0.11.0",
44
"2.0.1": "0.11.0",
55
"3.1.2": "0.11.0",
6-
"3.2.2": "0.11.0"
7-
}
6+
"3.2.2": "0.11.0",
7+
"3.3.0": "0.11.0"
8+
}

0 commit comments

Comments
 (0)