From 44701700e3209a82de836bb139c015f1896b2108 Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:12:21 -0400 Subject: [PATCH] fix: Properly handles the icon manager not finding an icon node --- src/callout/manager.ts | 4 ++-- src/modal/index.ts | 8 ++++++-- src/settings.ts | 12 ++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/callout/manager.ts b/src/callout/manager.ts index de5dd1d..f1e30b5 100644 --- a/src/callout/manager.ts +++ b/src/callout/manager.ts @@ -176,9 +176,9 @@ export default class CalloutManager extends Component { } else { rule = `.callout[data-callout="${admonition.type}"] { --callout-color: ${admonition.color}; - --callout-icon: '${this.plugin.iconManager + --callout-icon: '${(this.plugin.iconManager .getIconNode(admonition.icon) - .outerHTML.replace(/(width|height)=(\\?"|')\d+(\\?"|')/g, "")}'; + ?.outerHTML ?? "").replace(/(width|height)=(\\?"|')\d+(\\?"|')/g, "")}'; }`; } if (this.indexing.contains(admonition.type)) { diff --git a/src/modal/index.ts b/src/modal/index.ts index 50e2037..e52637d 100644 --- a/src/modal/index.ts +++ b/src/modal/index.ts @@ -308,7 +308,9 @@ export class IconSuggestionModal extends SuggestionModal { const iconDiv = createDiv("suggestion-flair admonition-suggester-icon"); iconDiv - .appendChild(this.plugin.iconManager.getIconNode(item.icon)) + .appendChild( + this.plugin.iconManager.getIconNode(item.icon) ?? createDiv() + ) .setAttribute("color", `rgb(${item.color})`); content.prepend(iconDiv); diff --git a/src/settings.ts b/src/settings.ts index d8941c2..0e3d9f9 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -708,9 +708,9 @@ export default class AdmonitionSetting extends PluginSettingTab { const value = this.plugin.admonitions[key]; admonition_icons[key] = { - icon: this.plugin.iconManager.getIconNode( - value.icon - ).outerHTML, + icon: + this.plugin.iconManager.getIconNode(value.icon) + ?.outerHTML ?? "", color: value.color }; } @@ -1055,9 +1055,9 @@ class SettingsModal extends Modal { ".admonition-title-icon" ); - iconEl.innerHTML = this.plugin.iconManager.getIconNode( - this.icon - ).outerHTML; + iconEl.innerHTML = + this.plugin.iconManager.getIconNode(this.icon) + ?.outerHTML ?? ""; }; const modal = new IconSuggestionModal(this.plugin, text);