AgentSkillsCN

rte-slash-commands

在富文本编辑器中使用斜杠命令。当您需要添加自定义命令,或深入了解可用的格式化选项时,这一功能将助您事半功倍。

SKILL.md
--- frontmatter
name: rte-slash-commands
description: Work with slash commands in Rich Text Editor. Use when adding custom commands or understanding available formatting options.

Slash Commands

Type / at line start to open command menu.

Default Commands

Basic

CommandAliasesAction
Textparagraph, pPlain paragraph
Heading 1h1, titleLarge heading
Heading 2h2, subtitleMedium heading
Heading 3h3Small heading

Lists

CommandAliasesAction
Bullet Listul, unordered, bulletsUnordered list
Numbered Listol, ordered, numbersOrdered list
Task Listtodo, checkbox, checklistCheckboxes

Formatting

CommandAliasesAction
Inline Codecode, monospaceCode style
Highlightmark, marker, yellowHighlight
Linkurl, href, anchorAdd link

Advanced

CommandAliasesAction
Quoteblockquote, quotationBlock quote
Code Blockcodeblock, pre, syntaxCode with highlighting
Dividerhr, horizontal, separatorHorizontal rule
Tabletable, grid3x3 table
Calloutnote, info, alertHighlighted block
Toggleexpand, collapse, detailsCollapsible

Adding Custom Commands

tsx
import {
  RichTextEditor,
  type EditorPlugin,
  type SlashCommand,
} from '@/components/ui/editor'
import { Sparkles } from 'lucide-react'

const myCommand: SlashCommand = {
  name: 'Magic',
  description: 'Insert magic content',
  icon: Sparkles,
  aliases: ['magic', 'special'],
  group: 'custom',
  action: (editor) => {
    editor.chain().focus().insertContent('<p>✨ Magic!</p>').run()
  },
}

const myPlugin: EditorPlugin = {
  name: 'magic-plugin',
  slashCommands: [myCommand],
}

<RichTextEditor plugins={[myPlugin]} />

SlashCommand Interface

tsx
interface SlashCommand {
  name: string
  description: string
  icon: LucideIcon
  aliases?: string[]
  group: 'basic' | 'lists' | 'formatting' | 'advanced' | 'media' | 'custom'
  action: (editor: Editor, context?: EditorActionContext) => void
}

Command Groups (by priority)

GroupPriorityContent
basic1Text, headings
lists2Bullet, numbered, tasks
formatting3Code, highlight, link
advanced4Quote, table, callout, toggle
media5File attachments
custom6Your commands

Working with Commands

tsx
import {
  defaultSlashCommands,
  filterCommands,
  groupCommands,
  commandGroups,
} from '@/components/ui/editor'

// Get all default commands
const commands = defaultSlashCommands

// Filter by query
const filtered = filterCommands(commands, 'head')

// Group by category
const grouped = groupCommands(commands) // Map<GroupInfo, SlashCommand[]>

// Get group definitions
const groups = commandGroups // [{id, label, priority}, ...]

EditorActionContext

For commands needing UI (like link popover):

tsx
const linkCommand: SlashCommand = {
  name: 'Link',
  icon: Link,
  group: 'formatting',
  action: (editor, context) => {
    context?.openLinkPopover()
  },
}