@voithos-labs/aragonite-slash-commands
v0.11.5
Published
a / command menu for aragonite, the cute markdown editor lib
Readme
@voithos-labs/aragonite-slash-commands
A / menu for aragonite. Type / at the start of a line, pick a block from the list that opens, and it lands right where you are; /td and Enter, and you've got a to-do list. What's aragonite? A Markdown editor, which the readme explains properly and aragonite.dev demonstrates.
What it does
The list holds every block the editor's right-click "Insert block" menu offers (your plugins' blocks included), then Heading 1 to 3. Typing narrows it by name or keyword, Enter picks, and Escape closes it and leaves what you typed.
- On an empty line, the block replaces the line. On a line with text, the
/querygoes and the block lands below, except a heading, which turns the line itself into one. - It opens at the start of a line or after a space, so
and/orstays text. It never opens in a table cell. - Two rows take a word after a space:
/code jsopens a code block taggedjs, and/table 3x4makes a table three columns wide and four rows tall, header row included. Ctrl+/(Cmd+/on a Mac) types the/for you, andeditor.runCommand('slashCommands.open', 'table')opens the list already narrowed, which is how a toolbar button or a touch UI gets there.
What lands is plain Markdown, the same as if you'd typed it. The built-in rows, by id (the ids are what exclude below takes):
| id | Row | Writes |
| ---------------- | -------------- | ------------------------------------------- |
| bullet | Bulleted list | - |
| numbered | Numbered list | 1. |
| todo | To-do list | - [ ] |
| quote | Quote | > |
| divider | Divider | --- |
| code | Code block | an empty fence |
| table | Table | two columns, a header row and one empty row |
| h1, h2, h3 | Heading 1 to 3 | turns the line into that heading |
The bundled plugins add note, details, math, mermaid and toc when they're installed.
Install
npm install @voithos-labs/aragonite @voithos-labs/aragonite-slash-commandsSame release, same version number as the editor, and it asks for exactly that one. Upgrade them as a pair.
Use it
import { slashCommandsPlugin } from '@voithos-labs/aragonite-slash-commands';
const plugins = [
slashCommandsPlugin({
entries: [
{ id: 'shrug', label: 'Shrug', insert: '¯\\_(ツ)_/¯' },
{
id: 'today',
label: 'Today',
run: async (editor) => {
await editor.insertMarkdown(new Date().toDateString());
}
}
],
exclude: ['divider']
})
];Pass plugins to the editor, built once for the whole app. There are two options, and you can skip both:
entriesadds rows of your own, listed after the built-in ones. Each has anidand alabel(and, if you like, aniconandkeywords), plus exactly one ofinsert(Markdown to drop in) orrun(a function). A row with both or neither makes the factory throw (in one editor's{ plugin, options }entry, the editor reports it on itserrorevent instead). Reuse a built-in id and your row replaces that built-in one.runis handed aneditorto write through (insertMarkdown, as above), plus the word typed after a space if the row setstakesArgument: true. It can be async. If it waits on something (a picker, a fetch), keep writing through that sameeditor. It quietly writes nothing once the app has loaded another note, so a late answer can't land in the wrong document.excludehides built-in rows by id.
What you pass the factory is every editor's default. An editor's own { plugin, options } entry swaps out only the fields it names, so { exclude: ['table'] } still keeps the factory's entries, and { entries: [] } is how one editor drops them.
More
The consumer guide has the other bundled plugins, and the plugin API reference's section on insert menus is how a plugin's own block gets into this list (and takes a word after a space, the way /table 3x4 does).
License
Free software, released under MPL-2.0 like the editor itself: use it, study it, fork it, embed it in whatever you're building, closed source included. The one string attached: if you change this plugin's own files, you share those changes under the same license.
