home blog portfolio Ian Fisher

Obsidian cheatsheet

Plugin development

Useful APIs

Show a notice

import { Notice, sanitizeHTMLToDom } from "obsidian";

new Notice("Hello, world", /* durationMs */ 5000);

const document = sanitizeHTMLToDom("<strong>Hello, world!</p>");
new Notice(document);

Tips:

Fuzzy selection

class ShellCommandModal extends FuzzySuggestModal<T> {
  choices: T[]
  onTrigger: (choice: T) => void;

  constructor(choices: T[], onTrigger: (choice: T) => void) {
    super(plugin.app);
    this.choices = choices;
    this.onTrigger = onTrigger;
  }

  getItems() {
    return this.choices;
  }

  getItemText(item: T) {
    return /* ... */;
  }

  onChooseItem(item: T) {
    this.onTrigger(item);
  }
}

const modal = ShellCommandModal(/* ... */);
modal.open();