Bläck StudioPlugin SDK v1.0.0 · API 4
Contents

Start

Building

Beyond Bläck Studio

How it runs

Sharing

Look up

Write plugins for Bläck Studio

Bläck Studio is a writing app for long-form fiction. Plugins add to it: commands and hotkeys, views and inspector tabs, cards on the dashboard, marks in the text, formats in Compile, importers, suggestions as you type, and more. They're written in TypeScript or plain JavaScript, against @black/plugin.

npm create black-plugin my-plugin
cd my-plugin
npm install
npm run dev      # builds into Bläck Studio’s plugins folder on every save

A plugin is a folder with a manifest.json and a script. Bläck Studio finds plugins in its plugins folder:

SystemFolder
Linux~/.local/share/black/plugins/ (or $XDG_DATA_HOME/black/plugins)
macOS~/Library/Application Support/black/plugins/
Windows%APPDATA%\black\plugins\

Settings → Plugins opens it, and turns plugins on and off.

Starting one

Until the SDK is on npm, run the template from a clone of this repository: node packages/create-black-plugin/index.mjs my-plugin. The new plugin then uses the SDK beside it. Once it's published, it's:

npm create black-plugin my-plugin             # in the window, with React
npm create black-plugin my-plugin --sandboxed
npm create black-plugin my-plugin --computer  # sandboxed, with files and a program
cd my-plugin
npm install
npm run dev

The three starting points:

  • In the window: a command with a hotkey, and an inspector tab drawn with React.
  • --sandboxed: a command, marks in the text, and text in the status bar, from a worker of its own.
  • --computer: sandboxed, with files:write and exec:pandoc. It saves the scene the writer is in as a Word file, made by Pandoc in the plugin's temporary folder, in a folder the writer chooses. It remembers that folder for next time. It shows how to ask for a folder, run a program, and say plainly when the program isn't installed. To run another program, name it in the manifest and in the code.

npm run dev builds the plugin into the plugins folder every time you save, and Bläck Studio loads it again as it lands. Turn it on once under Settings → Plugins. npm run build makes dist/<id>/ to share, and a zip with its SHA-256 for the plugin list.

No build is needed at all for a plugin in plain JavaScript: a main.js like this, beside its manifest, is a plugin.

var __blackPlugin = class extends __black.require('@black/plugin').Plugin {
  onload() {
    this.addCommand({ id: 'hello', name: 'Say hello', run: () => this.app.ui.notify('Hello') })
  }
}