Skip to content

Commit

Permalink
fix: Properly handles the icon manager not finding an icon node
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Mar 29, 2022
1 parent 3c101d0 commit 4470170
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/callout/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 6 additions & 2 deletions src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ export class IconSuggestionModal extends SuggestionModal<AdmonitionIconDefinitio
}

const iconDiv = createDiv("suggestion-flair admonition-suggester-icon");
iconDiv.appendChild(this.plugin.iconManager.getIconNode(item));
iconDiv.appendChild(
this.plugin.iconManager.getIconNode(item) ?? createDiv()
);
content.prepend(iconDiv);
content.createDiv({
cls: "suggestion-note",
Expand Down Expand Up @@ -388,7 +390,9 @@ class AdmonitionSuggestionModal extends SuggestionModal<Admonition> {

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);
Expand Down
12 changes: 6 additions & 6 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4470170

Please sign in to comment.