diff --git a/manifest.json b/manifest.json
index 1ab7f76..892f019 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"id": "obsidian-admonition",
"name": "Admonition",
- "version": "3.3.3",
+ "version": "3.3.4",
"minAppVersion": "0.11.0",
"description": "Admonition block-styled content for Obsidian.md",
"author": "Jeremy Valentine",
diff --git a/package.json b/package.json
index b9bdf4a..897c97e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "obsidian-admonition",
- "version": "3.3.3",
+ "version": "3.3.4",
"description": "Admonition block-styled content for Obsidian.md",
"main": "main.js",
"scripts": {
diff --git a/src/main.ts b/src/main.ts
index 676a1a1..579168e 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -317,25 +317,25 @@ export default class ObsidianAdmonition
* Collapsible -> Title
Content
* Regular ->
*/
- let admonitionElement = await getAdmonitionElement(
+ let admonitionElement = getAdmonitionElement(
type,
title,
this.admonitions[type].icon,
this.admonitions[type].color,
collapse
);
-
/**
* Create a unloadable component.
*/
- let admonitionContent = admonitionElement.createDiv({
- cls: "admonition-content"
- });
let markdownRenderChild = new MarkdownRenderChild(
admonitionElement
);
markdownRenderChild.containerEl = admonitionElement;
+ let admonitionContent = admonitionElement.createDiv({
+ cls: "admonition-content"
+ });
+
/**
* Render the content as markdown and append it to the admonition.
*/
diff --git a/src/util.ts b/src/util.ts
index 9f830bc..930da9f 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -5,104 +5,93 @@ import {
} from "@fortawesome/fontawesome-svg-core";
import { MarkdownRenderer } from "obsidian";
-export async function getAdmonitionElement(
+export /* async */ function getAdmonitionElement(
type: string,
title: string,
iconName: string,
color: string,
collapse?: string
-): Promise {
- return new Promise(async (resolve) => {
- let admonition,
- titleEl,
- attrs: { style: string; open?: string } = {
- style: `--admonition-color: ${color};`
- };
- if (collapse) {
- if (collapse === "open") {
- attrs.open = "open";
- }
- admonition = createEl("details", {
- cls: `admonition admonition-${type}`,
- attr: attrs
- });
- titleEl = admonition.createEl("summary", {
- cls: `admonition-title ${
- !title.trim().length ? "no-title" : ""
- }`
- });
- } else {
- admonition = createDiv({
- cls: `admonition admonition-${type}`,
- attr: attrs
- });
- titleEl = admonition.createDiv({
- cls: `admonition-title ${
- !title.trim().length ? "no-title" : ""
- }`
- });
+): HTMLElement {
+ let admonition,
+ titleEl,
+ attrs: { style: string; open?: string } = {
+ style: `--admonition-color: ${color};`
+ };
+ if (collapse) {
+ if (collapse === "open") {
+ attrs.open = "open";
}
+ admonition = createEl("details", {
+ cls: `admonition admonition-${type}`,
+ attr: attrs
+ });
+ titleEl = admonition.createEl("summary", {
+ cls: `admonition-title ${!title.trim().length ? "no-title" : ""}`
+ });
+ } else {
+ admonition = createDiv({
+ cls: `admonition admonition-${type}`,
+ attr: attrs
+ });
+ titleEl = admonition.createDiv({
+ cls: `admonition-title ${!title.trim().length ? "no-title" : ""}`
+ });
+ }
- if (title && title.length) {
- /**
- * Title structure
- * .admonition-title
- *
.admonition-title-content - Rendered Markdown top-level element (e.g. H1/2/3 etc, p)
- * div.admonition-title-icon
- * svg
- * div.admonition-title-markdown - Container of rendered markdown
- * ...rendered markdown children...
- */
+ if (title && title.length) {
+ /**
+ * Title structure
+ * .admonition-title
+ * .admonition-title-content - Rendered Markdown top-level element (e.g. H1/2/3 etc, p)
+ * div.admonition-title-icon
+ * svg
+ * div.admonition-title-markdown - Container of rendered markdown
+ * ...rendered markdown children...
+ */
- //get markdown
- const markdownHolder = createDiv();
- await MarkdownRenderer.renderMarkdown(
- title,
- markdownHolder,
- "",
- null
- );
+ //get markdown
+ const markdownHolder = createDiv();
+ MarkdownRenderer.renderMarkdown(title, markdownHolder, "", null);
- //admonition-title-content is first child of rendered markdown
- const admonitionTitleContent = markdownHolder.children[0];
+ //admonition-title-content is first child of rendered markdown
+ const admonitionTitleContent = markdownHolder.children[0];
- //get children of markdown element, then remove them
- const markdownElements = Array.from(
- admonitionTitleContent?.childNodes || []
- );
- admonitionTitleContent.innerHTML = "";
- admonitionTitleContent.addClass("admonition-title-content");
+ //get children of markdown element, then remove them
+ const markdownElements = Array.from(
+ admonitionTitleContent?.childNodes || []
+ );
+ admonitionTitleContent.innerHTML = "";
+ admonitionTitleContent.addClass("admonition-title-content");
- //build icon element
- const iconEl = admonitionTitleContent.createDiv(
- "admonition-title-icon"
+ //build icon element
+ const iconEl = admonitionTitleContent.createDiv(
+ "admonition-title-icon"
+ );
+ if (iconName) {
+ iconEl.appendChild(
+ icon(
+ findIconDefinition({
+ iconName: iconName as IconName,
+ prefix: "fas"
+ })
+ ).node[0]
);
- if (iconName) {
- iconEl.appendChild(
- icon(
- findIconDefinition({
- iconName: iconName as IconName,
- prefix: "fas"
- })
- ).node[0]
- );
- }
+ }
- //add markdown children back
- const admonitionTitleMarkdown = admonitionTitleContent.createDiv(
- "admonition-title-markdown"
- );
- for (let i = 0; i < markdownElements.length; i++) {
- admonitionTitleMarkdown.appendChild(markdownElements[i]);
- }
- titleEl.appendChild(admonitionTitleContent || createDiv());
+ //add markdown children back
+ const admonitionTitleMarkdown = admonitionTitleContent.createDiv(
+ "admonition-title-markdown"
+ );
+ for (let i = 0; i < markdownElements.length; i++) {
+ admonitionTitleMarkdown.appendChild(markdownElements[i]);
}
+ titleEl.appendChild(admonitionTitleContent || createDiv());
+ }
- //add them to title element
+ //add them to title element
- if (collapse) {
- titleEl.createDiv("collapser").createDiv("handle");
- }
- resolve(admonition);
- });
+ if (collapse) {
+ titleEl.createDiv("collapser").createDiv("handle");
+ }
+ return admonition;
}
diff --git a/versions.json b/versions.json
index 6b8c573..60dbd14 100644
--- a/versions.json
+++ b/versions.json
@@ -4,5 +4,5 @@
"2.0.1": "0.11.0",
"3.1.2": "0.11.0",
"3.2.2": "0.11.0",
- "3.3.3": "0.11.0"
+ "3.3.4": "0.11.0"
}
\ No newline at end of file