Extensions

Everything the editor can do is an extension: keymaps, input rules and commands.

Bundled extensions

NameTypeDescription
StarterKit()ExtensionHeadings, lists, quote, marks, shortcuts and Markdown input rules.
LinkExtension()ExtensionsetLink / unsetLink commands and optional open-on-click.
PlaceholderExtension()ExtensionShows placeholder text while the document is empty.
ImageExtension()ExtensionFile picker, validation, drag & drop, paste and upload handling.

Markdown shortcuts

StarterKit registers input rules for `# `, `## `, `### `, `> `, `- ` and `1. `.

Writing your own

ts
import type { Extension } from "@tlob/babloom-core";

export function HighlightExtension(): Extension {
  return {
    name: "highlight",
    keymap: {
      "Mod-Shift-h": (editor) => editor.insertHTML("<mark>" + window.getSelection() + "</mark>"),
    },
    inputRules: [
      { match: /^==\s(.*)$/, handler: (editor) => editor.insertHTML("<mark></mark>") },
    ],
    commands: {
      clearHighlights: (editor) =>
        editor.element?.querySelectorAll("mark").forEach((m) => m.replaceWith(m.textContent ?? "")),
    },
    onCreate: (editor) => console.log("highlight ready", editor.name),
  };
}

Register it like any other extension and call it with editor.command("clearHighlights").