From 0983790cd930657d69c96c885c23eabcb884987e Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Mon, 22 Nov 2021 09:24:53 -0500 Subject: [PATCH] feat: added ability to default to no title fix: fixed error that could happen when editing admonitions feat: added per-admonition copy button setting (close #118) feat: added setting to turn off title parsing (close #123) --- README.md | 7 + src/@types/index.ts | 19 +++ src/lang/locale/en.ts | 12 +- src/main.ts | 291 +++++++++++++++++++++++++++++++++++++----- src/modal/index.ts | 11 +- src/settings.ts | 62 +++++++-- src/util/icons.ts | 3 +- src/util/util.ts | 204 ++--------------------------- 8 files changed, 365 insertions(+), 244 deletions(-) diff --git a/README.md b/README.md index 503a0ac..a3ef038 100644 --- a/README.md +++ b/README.md @@ -432,6 +432,13 @@ Commands may be registered for each custom admonition type to insert them into a See [this section](#register-and-unregister-commands) for more information. +### Mermaid Graphs + +Mermaid graphs are supported by Admonitions, but with some caveats: + +1. You cannot combine mermaid graphs and embeds/transclusions. +2. Mermaid graphs do not work in collapsed-by-default admonitions. + ## Non-code block Admonitions As of version 6.0.0, there is a new setting: Enable Non-codeblock Admonitions. diff --git a/src/@types/index.ts b/src/@types/index.ts index 0c34060..b7fea87 100644 --- a/src/@types/index.ts +++ b/src/@types/index.ts @@ -8,6 +8,8 @@ export interface Admonition { color: string; command: boolean; injectColor: boolean; + noTitle: boolean; + copy: boolean; } export interface INestedAdmonition { @@ -29,6 +31,7 @@ export interface ISettingsData { version: string; enableMarkdownProcessor: boolean; injectColor: boolean; + parseTitles: boolean; } export type AdmonitionIconDefinition = { @@ -61,6 +64,22 @@ export declare class ObsidianAdmonitionPlugin extends Plugin_2 { ): void; unregisterCommandsFor(admonition: Admonition): void; registerCommandsFor(admonition: Admonition): void; + getAdmonitionElement( + type: string, + title: string, + icon: AdmonitionIconDefinition, + color?: string, + collapse?: string, + id?: string + ): HTMLElement; + getAdmonitionElementAsync( + type: string, + title: string, + icon: AdmonitionIconDefinition, + color?: string, + collapse?: string, + id?: string + ): Promise; } export type RPGIconName = diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index a746222..8f81056 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -47,5 +47,15 @@ export default { "There was an error parsing the image.", "Admonition Icon": "Admonition Icon", Color: "Color", - Save: "Save" + Save: "Save", + "No Admonition Title by Default": "No Admonition Title by Default", + "The admonition will have no title unless ": + "The admonition will have no title unless ", + " is explicitly provided.": " is explicitly provided.", + "Show Copy Button": "Show Copy Button", + "A copy button will be added to the admonition.": + "A copy button will be added to the admonition.", + "Parse Titles as Markdown": "Parse Titles as Markdown", + "Admonition Titles will be rendered as markdown.": + "Admonition Titles will be rendered as markdown." }; diff --git a/src/main.ts b/src/main.ts index 9077b37..40ad7c6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,24 +1,25 @@ import { addIcon, + MarkdownPostProcessor, MarkdownPostProcessorContext, - MarkdownPreviewView, + MarkdownPreviewRenderer, MarkdownRenderChild, MarkdownRenderer, MarkdownView, + normalizePath, Notice, Plugin, TFile } from "obsidian"; /* import { prettyPrint as html } from "html"; */ -import { Admonition, ObsidianAdmonitionPlugin, ISettingsData } from "./@types"; import { - getAdmonitionElement, - getAdmonitionElementAsync, - getID, - getMatches, - getParametersFromSource -} from "./util"; + Admonition, + ObsidianAdmonitionPlugin, + ISettingsData, + AdmonitionIconDefinition +} from "./@types"; +import { getID, getMatches, getParametersFromSource } from "./util"; import { ADMONITION_MAP, ADD_ADMONITION_COMMAND_ICON, @@ -50,6 +51,7 @@ declare module "obsidian" { } interface MarkdownPreviewRenderer { onCheckboxClick: (evt: MouseEvent, el: HTMLInputElement) => void; + unregisterCodeBlockPostProcessor(lang: string): void; } } Object.fromEntries = @@ -83,7 +85,12 @@ Object.fromEntries = import "./assets/main.css"; import AdmonitionSetting from "./settings"; -import { IconName, COPY_BUTTON_ICON, iconDefinitions } from "./util/icons"; +import { + IconName, + COPY_BUTTON_ICON, + iconDefinitions, + getIconNode +} from "./util/icons"; import { InsertAdmonitionModal } from "./modal"; const DEFAULT_APP_SETTINGS: ISettingsData = { @@ -95,7 +102,8 @@ const DEFAULT_APP_SETTINGS: ISettingsData = { defaultCollapseType: "open", syncLinks: true, enableMarkdownProcessor: false, - injectColor: true + injectColor: true, + parseTitles: true }; export default class ObsidianAdmonition @@ -105,6 +113,8 @@ export default class ObsidianAdmonition admonitions: { [admonitionType: string]: Admonition } = {}; data: ISettingsData; + postprocessors: Map = new Map(); + get types() { return Object.keys(this.admonitions); } @@ -168,14 +178,16 @@ export default class ObsidianAdmonition ...ADMONITION_MAP, ...this.data.userAdmonitions }; - this.registerMarkdownCodeBlockProcessor( - `ad-${admonition.type}`, - (src, el, ctx) => this.postprocessor(admonition.type, src, el, ctx) - ); if (this.data.syntaxHighlight) { this.turnOnSyntaxHighlighting([admonition.type]); } + await this.saveSettings(); + const processor = this.registerMarkdownCodeBlockProcessor( + `ad-${admonition.type}`, + (src, el, ctx) => this.postprocessor(admonition.type, src, el, ctx) + ); + this.postprocessors.set(admonition.type, processor); } async removeAdmonition(admonition: Admonition) { @@ -195,6 +207,17 @@ export default class ObsidianAdmonition this.unregisterCommandsFor(admonition); } + if (this.postprocessors.has(admonition.type)) { + MarkdownPreviewRenderer.unregisterPostProcessor( + this.postprocessors.get(admonition.type) + ); + //@ts-expect-error + MarkdownPreviewRenderer.unregisterCodeBlockPostProcessor( + `ad-${admonition.type}` + ); + this.postprocessors.delete(admonition.type); + } + await this.saveSettings(); } async onload(): Promise { @@ -212,10 +235,11 @@ export default class ObsidianAdmonition } Object.keys(this.admonitions).forEach((type) => { - this.registerMarkdownCodeBlockProcessor( + const processor = this.registerMarkdownCodeBlockProcessor( `ad-${type}`, (src, el, ctx) => this.postprocessor(type, src, el, ctx) ); + this.postprocessors.set(type, processor); if (this.admonitions[type].command) { this.registerCommandsFor(this.admonitions[type]); } @@ -397,15 +421,16 @@ export default class ObsidianAdmonition ); } const admonition = this.admonitions[type]; - const admonitionElement = await getAdmonitionElementAsync( - type, - title.trim(), - admonition.icon, - admonition.injectColor ?? this.data.injectColor - ? admonition.color - : null, - collapse - ); + const admonitionElement = + await this.getAdmonitionElementAsync( + type, + title.trim(), + admonition.icon, + admonition.injectColor ?? this.data.injectColor + ? admonition.color + : null, + collapse + ); const contentHolder = admonitionElement.createDiv( "admonition-content-holder" @@ -623,13 +648,8 @@ title: : ctx?.sourcePath ?? this.app.workspace.getActiveFile()?.path ?? ""; - let { - title, - collapse, - content, - icon, - color - } = getParametersFromSource(type, src, this.admonitions[type]); + let { title, collapse, content, icon, color } = + getParametersFromSource(type, src, this.admonitions[type]); let match = new RegExp(`^!!! ad-(${this.types.join("|")})$`, "gm"); @@ -668,7 +688,7 @@ title: /* const iconNode = icon ? this.admonitions[type].icon; */ const admonition = this.admonitions[type]; - let admonitionElement = getAdmonitionElement( + let admonitionElement = this.getAdmonitionElement( type, title, iconDefinitions.find(({ name }) => icon === name) ?? @@ -739,7 +759,7 @@ title: ); } - if (this.data.copyButton) { + if (admonition.copy ?? this.data.copyButton) { let copy = contentHolder .createDiv("admonition-content-copy") .appendChild(COPY_BUTTON_ICON.cloneNode(true)); @@ -892,4 +912,209 @@ title: } } } + getAdmonitionElement( + type: string, + title: string, + icon: AdmonitionIconDefinition, + color?: string, + collapse?: string, + id?: string + ): HTMLElement { + let admonition, titleEl; + let attrs: { style?: string; open?: string } = color + ? { + style: `--admonition-color: ${color};` + } + : {}; + if (collapse && collapse != "none") { + if (collapse === "open") { + attrs.open = "open"; + } + admonition = createEl("details", { + cls: `admonition admonition-${type} admonition-plugin`, + attr: attrs + }); + titleEl = admonition.createEl("summary", { + cls: `admonition-title ${ + !title?.trim().length ? "no-title" : "" + }` + }); + } else { + admonition = createDiv({ + cls: `admonition admonition-${type} admonition-plugin`, + attr: attrs + }); + titleEl = admonition.createDiv({ + cls: `admonition-title ${ + !title?.trim().length ? "no-title" : "" + }` + }); + } + + if (id) { + admonition.id = id; + } + + if (title && title.trim().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(); + MarkdownRenderer.renderMarkdown(title, markdownHolder, "", null); + + //admonition-title-content is first child of rendered markdown + + const admonitionTitleContent = + markdownHolder.children[0]?.tagName === "P" + ? createDiv() + : markdownHolder.children[0]; + + //get children of markdown element, then remove them + const markdownElements = Array.from( + markdownHolder.children[0]?.childNodes || [] + ); + admonitionTitleContent.innerHTML = ""; + admonitionTitleContent.addClass("admonition-title-content"); + + //build icon element + const iconEl = admonitionTitleContent.createDiv( + "admonition-title-icon" + ); + if (icon && icon.name && icon.type) { + iconEl.appendChild(getIconNode(icon)); + } + + //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 + + if (collapse) { + titleEl.createDiv("collapser").createDiv("handle"); + } + return admonition; + } + async getAdmonitionElementAsync( + type: string, + title: string, + icon: AdmonitionIconDefinition, + color?: string, + collapse?: string, + id?: string + ): Promise { + let admonition, + titleEl, + attrs: { style?: string; open?: string } = color + ? { + style: `--admonition-color: ${color};` + } + : {}; + if (collapse) { + if (collapse === "open") { + attrs.open = "open"; + } + admonition = createEl("details", { + cls: `admonition admonition-${type} admonition-plugin admonition-plugin-async`, + attr: attrs + }); + titleEl = admonition.createEl("summary", { + cls: `admonition-title ${ + !title.trim().length ? "no-title" : "" + }` + }); + } else { + admonition = createDiv({ + cls: `admonition admonition-${type} admonition-plugin`, + attr: attrs + }); + titleEl = admonition.createDiv({ + cls: `admonition-title ${ + !title.trim().length ? "no-title" : "" + }` + }); + } + + if (id) { + admonition.id = id; + } + + if (title && title.trim().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 + if (this.data.parseTitles) { + const markdownHolder = createDiv(); + await MarkdownRenderer.renderMarkdown( + title, + markdownHolder, + "", + null + ); + + //admonition-title-content is first child of rendered markdown + + const admonitionTitleContent = + markdownHolder.children[0].tagName === "P" + ? createDiv() + : markdownHolder.children[0]; + + //get children of markdown element, then remove them + const markdownElements = Array.from( + markdownHolder.children[0]?.childNodes || [] + ); + admonitionTitleContent.innerHTML = ""; + admonitionTitleContent.addClass("admonition-title-content"); + + //build icon element + const iconEl = admonitionTitleContent.createDiv( + "admonition-title-icon" + ); + if (icon && icon.name && icon.type) { + iconEl.appendChild(getIconNode(icon)); + } + + //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()); + } else { + titleEl.appendChild(createDiv({ text: title })); + } + } + + //add them to title element + + if (collapse) { + titleEl.createDiv("collapser").createDiv("handle"); + } + return admonition; + } } diff --git a/src/modal/index.ts b/src/modal/index.ts index e13df9c..2ce64bc 100644 --- a/src/modal/index.ts +++ b/src/modal/index.ts @@ -13,12 +13,7 @@ import { } from "obsidian"; import { createPopper, Instance as PopperInstance } from "@popperjs/core"; -import { - getAdmonitionElement, - getIconModuleName, - getIconNode, - iconDefinitions -} from "../util"; +import { getIconModuleName, getIconNode, iconDefinitions } from "../util"; import { Admonition, AdmonitionIconDefinition, @@ -478,7 +473,7 @@ export class InsertAdmonitionModal extends Modal { } if (this.element) { const admonition = this.plugin.admonitions[this.type]; - const element = getAdmonitionElement( + const element = this.plugin.getAdmonitionElement( this.type, this.title, admonition.icon, @@ -570,7 +565,7 @@ ${this.editor.getDoc().getSelection()} this.admonitionEl.empty(); if (this.type && this.plugin.admonitions[this.type]) { const admonition = this.plugin.admonitions[this.type]; - this.element = getAdmonitionElement( + this.element = this.plugin.getAdmonitionElement( this.type, this.title, admonition.icon, diff --git a/src/settings.ts b/src/settings.ts index fa3825f..9c6cf3b 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -15,12 +15,7 @@ import { ObsidianAdmonitionPlugin } from "./@types"; -import { - getAdmonitionElement, - getIconNode, - getIconType, - WARNING_ICON -} from "./util"; +import { getIconNode, getIconType, WARNING_ICON } from "./util"; import { ADD_COMMAND_NAME, REMOVE_COMMAND_NAME } from "./util"; @@ -238,6 +233,17 @@ export default class AdmonitionSetting extends PluginSettingTab { }); } + await this.plugin.saveSettings(); + }); + }); + new Setting(containerEl) + .setName(t("Parse Titles as Markdown")) + .setDesc(t("Admonition Titles will be rendered as markdown.")) + .addToggle((t) => { + t.setValue(this.plugin.data.parseTitles); + t.onChange(async (v) => { + this.plugin.data.parseTitles = v; + await this.plugin.saveSettings(); }); }); @@ -285,7 +291,9 @@ export default class AdmonitionSetting extends PluginSettingTab { icon: modal.icon, command: false, title: modal.title, - injectColor: modal.injectColor + injectColor: modal.injectColor, + noTitle: modal.noTitle, + copy: modal.copy }); this.display(); } @@ -316,7 +324,7 @@ export default class AdmonitionSetting extends PluginSettingTab { let setting = new Setting(this.additionalEl); - let admonitionElement = await getAdmonitionElement( + let admonitionElement = this.plugin.getAdmonitionElement( admonition.type, admonition.type[0].toUpperCase() + admonition.type.slice(1).toLowerCase(), @@ -369,7 +377,9 @@ export default class AdmonitionSetting extends PluginSettingTab { icon: modal.icon, command: hasCommand, title: modal.title, - injectColor: modal.injectColor + injectColor: modal.injectColor, + noTitle: modal.noTitle, + copy: modal.copy }); this.display(); } @@ -398,7 +408,9 @@ class SettingsModal extends Modal { error: boolean = false; title: string; injectColor: boolean = this.plugin.data.injectColor; + noTitle: boolean = false; admonitionPreview: HTMLElement; + copy: boolean; constructor( public plugin: ObsidianAdmonitionPlugin, admonition?: Admonition @@ -410,6 +422,8 @@ class SettingsModal extends Modal { this.type = admonition.type; this.title = admonition.title; this.injectColor = admonition.injectColor ?? this.injectColor; + this.noTitle = admonition.noTitle ?? false; + this.copy = admonition.copy ?? this.plugin.data.copyButton; } } @@ -421,7 +435,7 @@ class SettingsModal extends Modal { const settingDiv = contentEl.createDiv(); const title = this.title ?? this.type ?? "..."; - this.admonitionPreview = await getAdmonitionElement( + this.admonitionPreview = this.plugin.getAdmonitionElement( this.type, title[0].toUpperCase() + title.slice(1).toLowerCase(), this.icon, @@ -504,6 +518,34 @@ class SettingsModal extends Modal { this.updateTitle(this.admonitionPreview, this.title); }); }); + new Setting(settingDiv) + .setName(t("No Admonition Title by Default")) + .setDesc( + createFragment((e) => { + e.createSpan({ + text: t("The admonition will have no title unless ") + }); + e.createEl("code", { text: "title" }); + e.createSpan({ text: t(" is explicitly provided.") }); + }) + ) + .addToggle((t) => { + t.setValue(this.noTitle).onChange((v) => (this.noTitle = v)); + }); + new Setting(settingDiv) + .setName(t("Show Copy Button")) + .setDesc( + createFragment((e) => { + e.createSpan({ + text: t( + "A copy button will be added to the admonition." + ) + }); + }) + ) + .addToggle((t) => { + t.setValue(this.copy).onChange((v) => (this.copy = v)); + }); const input = createEl("input", { attr: { diff --git a/src/util/icons.ts b/src/util/icons.ts index 4817084..f6bce61 100644 --- a/src/util/icons.ts +++ b/src/util/icons.ts @@ -3,12 +3,13 @@ import { fas } from "@fortawesome/free-solid-svg-icons"; import { fab } from "@fortawesome/free-brands-svg-icons"; import { IconDefinition, - IconName, findIconDefinition, icon, library } from "@fortawesome/fontawesome-svg-core"; +import type { IconName } from "@fortawesome/fontawesome-svg-core"; + import { RPG } from "./rpgawesome"; import { AdmonitionIconDefinition, RPGIconName } from "src/@types"; diff --git a/src/util/util.ts b/src/util/util.ts index bfe8c53..7a3d7d5 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -84,12 +84,12 @@ export function getParametersFromSource( } params[foundKeyword] = lines[i] - .substr(keywordTokens[keywordIndex].length) + .slice(keywordTokens[keywordIndex].length) .trim(); ++skipLines; } - let { title = admonitionTitle, collapse, icon, color } = params; + let { title, collapse, icon, color } = params; let content = lines.slice(skipLines).join("\n"); @@ -105,201 +105,23 @@ export function getParametersFromSource( collapse = "closed"; } + if (!title || !title.length) { + if (!admonition.noTitle) { + title = admonitionTitle; + } + } /** * If the admonition should collapse, but title was blanked, set the default title. */ - if (title.trim() === "" && collapse !== undefined && collapse !== "none") { + if ( + title && + title.trim() === "" && + collapse !== undefined && + collapse !== "none" + ) { title = admonitionTitle; new Notice("An admonition must have a title if it is collapsible."); } return { title, collapse, content, icon, color }; } - -export /* async */ function getAdmonitionElement( - type: string, - title: string, - icon: AdmonitionIconDefinition, - color?: string, - collapse?: string, - id?: string -): HTMLElement { - let admonition, titleEl; - let attrs: { style?: string; open?: string } = color - ? { - style: `--admonition-color: ${color};` - } - : {}; - if (collapse && collapse != "none") { - if (collapse === "open") { - attrs.open = "open"; - } - admonition = createEl("details", { - cls: `admonition admonition-${type} admonition-plugin`, - attr: attrs - }); - titleEl = admonition.createEl("summary", { - cls: `admonition-title ${!title?.trim().length ? "no-title" : ""}` - }); - } else { - admonition = createDiv({ - cls: `admonition admonition-${type} admonition-plugin`, - attr: attrs - }); - titleEl = admonition.createDiv({ - cls: `admonition-title ${!title?.trim().length ? "no-title" : ""}` - }); - } - - if (id) { - admonition.id = id; - } - - if (title && title.trim().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(); - MarkdownRenderer.renderMarkdown(title, markdownHolder, "", null); - - //admonition-title-content is first child of rendered markdown - - const admonitionTitleContent = - markdownHolder.children[0]?.tagName === "P" - ? createDiv() - : markdownHolder.children[0]; - - //get children of markdown element, then remove them - const markdownElements = Array.from( - markdownHolder.children[0]?.childNodes || [] - ); - admonitionTitleContent.innerHTML = ""; - admonitionTitleContent.addClass("admonition-title-content"); - - //build icon element - const iconEl = admonitionTitleContent.createDiv( - "admonition-title-icon" - ); - if (icon && icon.name && icon.type) { - iconEl.appendChild(getIconNode(icon)); - } - - //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 - - if (collapse) { - titleEl.createDiv("collapser").createDiv("handle"); - } - return admonition; -} -export async function getAdmonitionElementAsync( - type: string, - title: string, - icon: AdmonitionIconDefinition, - color?: string, - collapse?: string, - id?: string -): Promise { - let admonition, - titleEl, - attrs: { style?: string; open?: string } = color - ? { - style: `--admonition-color: ${color};` - } - : {}; - if (collapse) { - if (collapse === "open") { - attrs.open = "open"; - } - admonition = createEl("details", { - cls: `admonition admonition-${type} admonition-plugin admonition-plugin-async`, - attr: attrs - }); - titleEl = admonition.createEl("summary", { - cls: `admonition-title ${!title.trim().length ? "no-title" : ""}` - }); - } else { - admonition = createDiv({ - cls: `admonition admonition-${type} admonition-plugin`, - attr: attrs - }); - titleEl = admonition.createDiv({ - cls: `admonition-title ${!title.trim().length ? "no-title" : ""}` - }); - } - - if (id) { - admonition.id = id; - } - - if (title && title.trim().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); - - //admonition-title-content is first child of rendered markdown - - const admonitionTitleContent = - markdownHolder.children[0].tagName === "P" - ? createDiv() - : markdownHolder.children[0]; - - //get children of markdown element, then remove them - const markdownElements = Array.from( - markdownHolder.children[0]?.childNodes || [] - ); - admonitionTitleContent.innerHTML = ""; - admonitionTitleContent.addClass("admonition-title-content"); - - //build icon element - const iconEl = admonitionTitleContent.createDiv( - "admonition-title-icon" - ); - if (icon && icon.name && icon.type) { - iconEl.appendChild(getIconNode(icon)); - } - - //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 - - if (collapse) { - titleEl.createDiv("collapser").createDiv("handle"); - } - return admonition; -}