View as Markdown

API reference: @salmonui/rich-text

EngineOptionsinterface

import type { EngineOptions } from '@salmonui/rich-text';
interface EngineOptions {
    readonly html?: string | undefined;
    readonly embedHosts?: readonly string[] | undefined;
    readonly extensions?: readonly RichTextExtension[] | undefined;
    readonly sanitize?: SanitizeHook | undefined;
    readonly undoLimit?: number | undefined;
    readonly undoGroupDelay?: number | undefined;
    readonly enterKey?: 'p' | 'div' | 'br' | undefined;
    readonly paragraphTag?: 'p' | 'div' | undefined;
    readonly shiftEnterKey?: 'p' | 'div' | 'br' | undefined;
    readonly tabKey?: 'indent' | 'focus' | undefined;
    readonly keyBindings?: RichTextKeyBindings | undefined;
    readonly placeholder?: (() => string | undefined) | undefined;
    readonly maxLength?: (() => number | undefined) | undefined;
    readonly highlight?: (() => HighlightFn | undefined) | undefined;
    readonly codeLanguages?: (() => readonly {
        readonly value: string;
        readonly label: string;
    }[] | undefined) | undefined;
    readonly suggestTriggers?: (() => readonly SuggestTrigger[]) | undefined;
    readonly onSuggestKey?: ((event: KeyboardEvent) => boolean) | undefined;
    readonly onAction?: ((id: string, args: readonly unknown[]) => boolean) | undefined;
    readonly onBeforeCommand?: ((command: string, args: readonly unknown[]) => boolean) | undefined;
    readonly onCommand?: ((command: string, args: readonly unknown[], applied: boolean) => void) | undefined;
    readonly upload?: (() => UploadHandler | undefined) | undefined;
    readonly imageInsert?: (() => 'base64' | 'blob') | undefined;
    readonly uploadLabel?: (() => string) | undefined;
    readonly onUploadError?: ((error: unknown, file: File) => void) | undefined;
    readonly pasteMode?: (() => PasteMode) | undefined;
    readonly cleanPaste?: ((html: string, mode: 'keep' | 'clean') => string) | undefined;
    readonly pastePrompt?: (() => Promise<'keep' | 'clean' | 'plainText' | null>) | undefined;
    readonly editable?: (() => boolean) | undefined;
    readonly attributes?: (() => Record<string, string>) | undefined;
}
EngineOptions members (29)
NameSignatureDescription
htmloptionalreadonly html?: string | undefined;
embedHostsoptionalreadonly embedHosts?: readonly string[] | undefined;
extensionsoptionalreadonly extensions?: readonly RichTextExtension[] | undefined;
sanitizeoptionalreadonly sanitize?: SanitizeHook | undefined;

Extends the always-on sanitizer applied before parsing and to getHtml output.

undoLimitoptionalreadonly undoLimit?: number | undefined;
undoGroupDelayoptionalreadonly undoGroupDelay?: number | undefined;
enterKeyoptionalreadonly enterKey?: 'p' | 'div' | 'br' | undefined;
paragraphTagoptionalreadonly paragraphTag?: 'p' | 'div' | undefined;

Paragraphs are written as <div> in getHtml (enterKey: 'div'); <div> parses back to a paragraph.

shiftEnterKeyoptionalreadonly shiftEnterKey?: 'p' | 'div' | 'br' | undefined;
tabKeyoptionalreadonly tabKey?: 'indent' | 'focus' | undefined;
keyBindingsoptionalreadonly keyBindings?: RichTextKeyBindings | undefined;
placeholderoptionalreadonly placeholder?: (() => string | undefined) | undefined;
maxLengthoptionalreadonly maxLength?: (() => number | undefined) | undefined;
highlightoptionalreadonly highlight?: (() => HighlightFn | undefined) | undefined;
codeLanguagesoptionalreadonly codeLanguages?: (() => readonly { readonly value: string; readonly label: string; }[] | undefined) | undefined;
suggestTriggersoptionalreadonly suggestTriggers?: (() => readonly SuggestTrigger[]) | undefined;
onSuggestKeyoptionalreadonly onSuggestKey?: ((event: KeyboardEvent) => boolean) | undefined;
onActionoptionalreadonly onAction?: ((id: string, args: readonly unknown[]) => boolean) | undefined;

UI actions (dialogs, fullscreen, source view) reached from key bindings and run.

onBeforeCommandoptionalreadonly onBeforeCommand?: ((command: string, args: readonly unknown[]) => boolean) | undefined;

Return false to cancel a command (onBeforeCommand).

onCommandoptionalreadonly onCommand?: ((command: string, args: readonly unknown[], applied: boolean) => void) | undefined;
uploadoptionalreadonly upload?: (() => UploadHandler | undefined) | undefined;
imageInsertoptionalreadonly imageInsert?: (() => 'base64' | 'blob') | undefined;
uploadLabeloptionalreadonly uploadLabel?: (() => string) | undefined;
onUploadErroroptionalreadonly onUploadError?: ((error: unknown, file: File) => void) | undefined;
pasteModeoptionalreadonly pasteMode?: (() => PasteMode) | undefined;
cleanPasteoptionalreadonly cleanPaste?: ((html: string, mode: 'keep' | 'clean') => string) | undefined;

Paste cleanup: returns the HTML to parse for keep or clean.

pastePromptoptionalreadonly pastePrompt?: (() => Promise<'keep' | 'clean' | 'plainText' | null>) | undefined;
editableoptionalreadonly editable?: (() => boolean) | undefined;
attributesoptionalreadonly attributes?: (() => Record<string, string>) | undefined;