# RichTextEngine (@salmonui/rich-text)

> The RichTextEngine class of @salmonui/rich-text.

Canonical: https://salmonui.dev/docs/reference/rich-text/RichTextEngine

```ts
import { RichTextEngine } from '@salmonui/rich-text';
```

Entry index: https://salmonui.dev/docs/reference/rich-text (Markdown with every symbol of the entry: https://salmonui.dev/docs/reference/rich-text.md).

## Reference

Kind: class

```ts
class RichTextEngine {
    #private;
    readonly schema: Schema;
    readonly commands: RichTextCommands;
    readonly extensionCommands: Record<string, (...args: never[]) => Command>;
    readonly historyCommands: {
        readonly undo: Command;
        readonly redo: Command;
    } | null;
    state: EditorState;
    view: EditorView | null;
    constructor(options: EngineOptions, extensionPlugins: readonly Plugin[], schema?: Schema);
    parseHtml(html: string): PMNode;
    parseSlice(html: string): Slice;
    getHtml(options?: {
        readonly xhtml?: boolean | undefined;
    }): string;
    getText(): string;
    get characterCount(): number;
    get isEmpty(): boolean;
    setHtml(html: string, options?: {
        readonly addToHistory?: boolean;
    }): void;
    dispatch(tr: Transaction): void;
    exec(command: Command): boolean;
    run(id: string, ...args: unknown[]): unknown;
    subscribe(listener: Listener): () => void;
    getSelection(): RichTextSelection;
    setSelection(anchor: number, head?: number): void;
    clearHistory(): void;
    get suggest(): SuggestState | null;
    dismissSuggest(): void;
    completeSuggest(content: string | null): void;
    get findState(): import("./plugins.js").FindState | undefined;
    get painterActive(): boolean;
    insertFiles(files: readonly File[], at?: number): Promise<void>;
    mount(element: HTMLElement): EditorView;
    get mentionTarget(): MentionEditorTarget | null;
    focus(): void;
    refresh(): void;
    destroy(): void;
    selectedNode(): PMNode | null;
    sliceHtml(): string;
}
```

Members (34):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `__#4@#private` | `#private;` |  |  |
| `schema` | `readonly schema: Schema;` |  |  |
| `commands` | `readonly commands: RichTextCommands;` |  |  |
| `extensionCommands` | `readonly extensionCommands: Record<string, (...args: never[]) => Command>;` |  |  |
| `historyCommands` | `readonly historyCommands: {     readonly undo: Command;     readonly redo: Command; } \| null;` |  | Undo and redo of an extension that replaces the history, else null. |
| `state` | `state: EditorState;` |  |  |
| `view` | `view: EditorView \| null;` |  |  |
| `parseHtml` | `parseHtml(html: string): PMNode;` |  |  |
| `parseSlice` | `parseSlice(html: string): Slice;` |  |  |
| `getHtml` | `getHtml(options?: {     readonly xhtml?: boolean \| undefined; }): string;` |  |  |
| `getText` | `getText(): string;` |  |  |
| `characterCount` | `get characterCount(): number;` |  |  |
| `isEmpty` | `get isEmpty(): boolean;` |  |  |
| `setHtml` | `setHtml(html: string, options?: {     readonly addToHistory?: boolean; }): void;` |  | Replaces the document (controlled `value`, form reset, source view). |
| `dispatch` | `dispatch(tr: Transaction): void;` |  |  |
| `exec` | `exec(command: Command): boolean;` |  |  |
| `run` | `run(id: string, ...args: unknown[]): unknown;` |  | Runs a command, an alias, an extension command or a UI action by id; `false` when cancelled or not applied. |
| `subscribe` | `subscribe(listener: Listener): () => void;` |  |  |
| `getSelection` | `getSelection(): RichTextSelection;` |  |  |
| `setSelection` | `setSelection(anchor: number, head?: number): void;` |  |  |
| `clearHistory` | `clearHistory(): void;` |  |  |
| `suggest` | `get suggest(): SuggestState \| null;` |  |  |
| `dismissSuggest` | `dismissSuggest(): void;` |  |  |
| `completeSuggest` | `completeSuggest(content: string \| null): void;` |  | Replaces the active trigger and query (`/head`, `:smi`) with content. |
| `findState` | `get findState(): import("./plugins.js").FindState \| undefined;` |  |  |
| `painterActive` | `get painterActive(): boolean;` |  |  |
| `insertFiles` | `insertFiles(files: readonly File[], at?: number): Promise<void>;` |  |  |
| `mount` | `mount(element: HTMLElement): EditorView;` |  |  |
| `mentionTarget` | `get mentionTarget(): MentionEditorTarget \| null;` |  | The `@salmonui/dropdowns/mention` editor target over this view; one per view. |
| `focus` | `focus(): void;` |  |  |
| `refresh` | `refresh(): void;` |  | Refreshes decorations and editable state after option changes. |
| `destroy` | `destroy(): void;` |  |  |
| `selectedNode` | `selectedNode(): PMNode \| null;` |  | Selection as a NodeSelection of an image, figure, audio, video or embed, if any. |
| `sliceHtml` | `sliceHtml(): string;` |  |  |
