AI
Markon logov2.0.0

Slash Commands

Nofinite Markon includes a Notion-style contextual command palette activated by typing / anywhere on an empty line or after whitespace.

The slash command menu enables authors to quickly format text, insert structural elements, embed rich media, and execute custom workflows entirely from the keyboard.

typescript
// Framework-Agnostic Core
import { MarkonEditor, createSlashCommandExtension } from '@nofinite/markon';

// React Adapter
import { MarkonEditor as ReactMarkonEditor } from '@nofinite/markon/react';

Overview

  • Trigger: Type / on a new line or after whitespace.
  • Navigation: Use ↑ and ↓ arrow keys to navigate options.
  • Selection: Press Enter or Tab to execute the selected command.
  • Dismissal: Press Escape or continue typing to dismiss the popover.

1. Framework-Agnostic Core Usage

Enable slash commands when initializing MarkonEditor:

typescript
import { MarkonEditor } from '@nofinite/markon';
import '@nofinite/nuicss/styles.css';

const container = document.querySelector('#editor')!;

const editor = new MarkonEditor({
  element: container,
  initialValue: '<p>Type <code>/</code> for commands...</p>',
  showSlashCommands: true, // Enabled by default
  placeholder: "Type '/' for commands..."
});

2. React Adapter Usage

In React applications, configure slash commands via component props:

tsx
import React, { useState } from 'react';
import { MarkonEditor } from '@nofinite/markon/react';
import '@nofinite/nuicss/styles.css';

export function EditorWithCommands() {
  const [content, setContent] = useState('<p>Type <code>/</code> to see commands...</p>');

  return (
    <div className="w-full max-w-4xl mx-auto p-6 bg-surface border border-default rounded-2xl shadow-sm">
      <MarkonEditor
        content={content}
        onChange={setContent}
        slashCommands={true}
        placeholder="Type '/' for commands..."
      />
    </div>
  );
}

Built-In Commands Registry

The default registry includes 20 production-ready commands:

CommandTitleDescriptionResulting Action
/h1Heading 1Large section headingInserts <h1> node
/h2Heading 2Medium section headingInserts <h2> node
/h3Heading 3Small section headingInserts <h3> node
/bulletBullet ListUnordered bulleted listToggles unordered <ul> list
/numberNumbered ListOrdered numerical listToggles ordered <ol> list
/todoTask ListInteractive checklist with boxesInserts task list with checkboxes
/quoteBlockquoteEditorial block quoteInserts <blockquote> node
/codeCode BlockSyntax-highlighted code containerInserts fenced code block with language selector
/tableTable (3x3)Data table with header rowInserts 3x3 table with headers
/mathMath FormulaLaTeX / KaTeX blockInserts mathematical formula editor
/videoVideo EmbedResponsive YouTube, Vimeo, MP4Opens modal for video URL
/toggleCollapsible SectionNotion-style accordionInserts <details> and <summary>
/imageImageMedia image with alignmentOpens file picker or URL modal
/fileFile AttachmentDownloadable document pillOpens file attachment picker
/dividerHorizontal RuleVisual dividing lineInserts <hr> separator
/highlightHighlightPastel color text backgroundApplies semantic text highlight
/infoInfo CalloutBlue informational note boxInserts Info alert container
/successSuccess CalloutGreen confirmation tip boxInserts Success alert container
/warningWarning CalloutAmber advisory caution boxInserts Warning alert container
/dangerDanger CalloutRed error or danger boxInserts Danger alert container