Skip to content

Commit 27c4a60

Browse files
committed
3.3.4
- Fixed issue where images no longer rendered in admonitions
1 parent 2313887 commit 27c4a60

File tree

5 files changed

+81
-92
lines changed

5 files changed

+81
-92
lines changed

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.3.3",
4+
"version": "3.3.4",
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.3.3",
3+
"version": "3.3.4",
44
"description": "Admonition block-styled content for Obsidian.md",
55
"main": "main.js",
66
"scripts": {

src/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,25 @@ export default class ObsidianAdmonition
317317
* Collapsible -> <details> <summary> Title </summary> <div> Content </div> </details>
318318
* Regular -> <div> <div> Title </div> <div> Content </div> </div>
319319
*/
320-
let admonitionElement = await getAdmonitionElement(
320+
let admonitionElement = getAdmonitionElement(
321321
type,
322322
title,
323323
this.admonitions[type].icon,
324324
this.admonitions[type].color,
325325
collapse
326326
);
327-
328327
/**
329328
* Create a unloadable component.
330329
*/
331-
let admonitionContent = admonitionElement.createDiv({
332-
cls: "admonition-content"
333-
});
334330
let markdownRenderChild = new MarkdownRenderChild(
335331
admonitionElement
336332
);
337333
markdownRenderChild.containerEl = admonitionElement;
338334

335+
let admonitionContent = admonitionElement.createDiv({
336+
cls: "admonition-content"
337+
});
338+
339339
/**
340340
* Render the content as markdown and append it to the admonition.
341341
*/

src/util.ts

Lines changed: 73 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,104 +5,93 @@ import {
55
} from "@fortawesome/fontawesome-svg-core";
66
import { MarkdownRenderer } from "obsidian";
77

8-
export async function getAdmonitionElement(
8+
export /* async */ function getAdmonitionElement(
99
type: string,
1010
title: string,
1111
iconName: string,
1212
color: string,
1313
collapse?: string
14-
): Promise<HTMLElement> {
15-
return new Promise(async (resolve) => {
16-
let admonition,
17-
titleEl,
18-
attrs: { style: string; open?: string } = {
19-
style: `--admonition-color: ${color};`
20-
};
21-
if (collapse) {
22-
if (collapse === "open") {
23-
attrs.open = "open";
24-
}
25-
admonition = createEl("details", {
26-
cls: `admonition admonition-${type}`,
27-
attr: attrs
28-
});
29-
titleEl = admonition.createEl("summary", {
30-
cls: `admonition-title ${
31-
!title.trim().length ? "no-title" : ""
32-
}`
33-
});
34-
} else {
35-
admonition = createDiv({
36-
cls: `admonition admonition-${type}`,
37-
attr: attrs
38-
});
39-
titleEl = admonition.createDiv({
40-
cls: `admonition-title ${
41-
!title.trim().length ? "no-title" : ""
42-
}`
43-
});
14+
): HTMLElement {
15+
let admonition,
16+
titleEl,
17+
attrs: { style: string; open?: string } = {
18+
style: `--admonition-color: ${color};`
19+
};
20+
if (collapse) {
21+
if (collapse === "open") {
22+
attrs.open = "open";
4423
}
24+
admonition = createEl("details", {
25+
cls: `admonition admonition-${type}`,
26+
attr: attrs
27+
});
28+
titleEl = admonition.createEl("summary", {
29+
cls: `admonition-title ${!title.trim().length ? "no-title" : ""}`
30+
});
31+
} else {
32+
admonition = createDiv({
33+
cls: `admonition admonition-${type}`,
34+
attr: attrs
35+
});
36+
titleEl = admonition.createDiv({
37+
cls: `admonition-title ${!title.trim().length ? "no-title" : ""}`
38+
});
39+
}
4540

46-
if (title && title.length) {
47-
/**
48-
* Title structure
49-
* <div|summary>.admonition-title
50-
* <element>.admonition-title-content - Rendered Markdown top-level element (e.g. H1/2/3 etc, p)
51-
* div.admonition-title-icon
52-
* svg
53-
* div.admonition-title-markdown - Container of rendered markdown
54-
* ...rendered markdown children...
55-
*/
41+
if (title && title.length) {
42+
/**
43+
* Title structure
44+
* <div|summary>.admonition-title
45+
* <element>.admonition-title-content - Rendered Markdown top-level element (e.g. H1/2/3 etc, p)
46+
* div.admonition-title-icon
47+
* svg
48+
* div.admonition-title-markdown - Container of rendered markdown
49+
* ...rendered markdown children...
50+
*/
5651

57-
//get markdown
58-
const markdownHolder = createDiv();
59-
await MarkdownRenderer.renderMarkdown(
60-
title,
61-
markdownHolder,
62-
"",
63-
null
64-
);
52+
//get markdown
53+
const markdownHolder = createDiv();
54+
MarkdownRenderer.renderMarkdown(title, markdownHolder, "", null);
6555

66-
//admonition-title-content is first child of rendered markdown
67-
const admonitionTitleContent = markdownHolder.children[0];
56+
//admonition-title-content is first child of rendered markdown
57+
const admonitionTitleContent = markdownHolder.children[0];
6858

69-
//get children of markdown element, then remove them
70-
const markdownElements = Array.from(
71-
admonitionTitleContent?.childNodes || []
72-
);
73-
admonitionTitleContent.innerHTML = "";
74-
admonitionTitleContent.addClass("admonition-title-content");
59+
//get children of markdown element, then remove them
60+
const markdownElements = Array.from(
61+
admonitionTitleContent?.childNodes || []
62+
);
63+
admonitionTitleContent.innerHTML = "";
64+
admonitionTitleContent.addClass("admonition-title-content");
7565

76-
//build icon element
77-
const iconEl = admonitionTitleContent.createDiv(
78-
"admonition-title-icon"
66+
//build icon element
67+
const iconEl = admonitionTitleContent.createDiv(
68+
"admonition-title-icon"
69+
);
70+
if (iconName) {
71+
iconEl.appendChild(
72+
icon(
73+
findIconDefinition({
74+
iconName: iconName as IconName,
75+
prefix: "fas"
76+
})
77+
).node[0]
7978
);
80-
if (iconName) {
81-
iconEl.appendChild(
82-
icon(
83-
findIconDefinition({
84-
iconName: iconName as IconName,
85-
prefix: "fas"
86-
})
87-
).node[0]
88-
);
89-
}
79+
}
9080

91-
//add markdown children back
92-
const admonitionTitleMarkdown = admonitionTitleContent.createDiv(
93-
"admonition-title-markdown"
94-
);
95-
for (let i = 0; i < markdownElements.length; i++) {
96-
admonitionTitleMarkdown.appendChild(markdownElements[i]);
97-
}
98-
titleEl.appendChild(admonitionTitleContent || createDiv());
81+
//add markdown children back
82+
const admonitionTitleMarkdown = admonitionTitleContent.createDiv(
83+
"admonition-title-markdown"
84+
);
85+
for (let i = 0; i < markdownElements.length; i++) {
86+
admonitionTitleMarkdown.appendChild(markdownElements[i]);
9987
}
88+
titleEl.appendChild(admonitionTitleContent || createDiv());
89+
}
10090

101-
//add them to title element
91+
//add them to title element
10292

103-
if (collapse) {
104-
titleEl.createDiv("collapser").createDiv("handle");
105-
}
106-
resolve(admonition);
107-
});
93+
if (collapse) {
94+
titleEl.createDiv("collapser").createDiv("handle");
95+
}
96+
return admonition;
10897
}

versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"2.0.1": "0.11.0",
55
"3.1.2": "0.11.0",
66
"3.2.2": "0.11.0",
7-
"3.3.3": "0.11.0"
7+
"3.3.4": "0.11.0"
88
}

0 commit comments

Comments
 (0)