# @salmonui/editors/markdown-editor API reference

> 27 exported symbols of @salmonui/editors/markdown-editor: 5 functions, 11 interfaces, 6 types and 5 constants.

Canonical: https://salmonui.dev/docs/reference/editors/markdown-editor

```ts
import { … } from '@salmonui/editors/markdown-editor';
```

## Functions

### MarkdownEditor

Kind: function

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownEditor

```ts
function MarkdownEditor(props: MarkdownEditorProps): ReactElement;
```

### applyMarkdownCommand

Kind: function

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/applyMarkdownCommand

```ts
function applyCommand(id: MarkdownTextCommand, state: TextState, syntax?: MarkdownSyntax, locale?: string | readonly string[]): TextState;
```

Runs a text command; returns the new state.

### continueMarkdownList

Kind: function

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/continueMarkdownList

```ts
function continueList(state: TextState): TextState | null;
```

Enter inside a list item: continues the marker on a new line
(the next number for ordered lists, an unchecked box for task lists); on
an empty item it removes the marker and ends the list. Null when the
caret line is not a list item or the selection is not a caret.

### shortcutCommand

Kind: function

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/shortcutCommand

```ts
function shortcutCommand(event: Pick<KeyboardEvent, 'key' | 'code' | 'ctrlKey' | 'metaKey' | 'shiftKey' | 'altKey'>): MarkdownToolbarItemId | null;
```

The command of a Mod shortcut, or null. Undo / redo stay native.

### tableMarkdown

Kind: function

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/tableMarkdown

```ts
function tableMarkdown(rows: number, cols: number, header?: (index: number) => string): string;
```

A GFM table of `rows` body rows and `cols` columns, with header cells `header(i)`.

## Interfaces

### MarkdownBeforeCommandEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownBeforeCommandEvent

```ts
interface MarkdownBeforeCommandEvent extends MarkdownCommandEvent {
    readonly defaultPrevented: boolean;
    preventDefault(): void;
}
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `defaultPrevented` | `readonly defaultPrevented: boolean;` |  |  |
| `preventDefault` | `preventDefault(): void;` |  |  |
| `id` | `id: string;` | inherited |  |
| `source` | `source: MarkdownEditorSource;` | inherited |  |

### MarkdownCommandEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownCommandEvent

```ts
interface MarkdownCommandEvent {
    readonly id: string;
    readonly source: MarkdownEditorSource;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `id` | `readonly id: string;` |  |  |
| `source` | `readonly source: MarkdownEditorSource;` |  |  |

### MarkdownEditorApi

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownEditorApi

```ts
interface MarkdownEditorApi {
    readonly element: HTMLTextAreaElement | null;
    runCommand(id: string): void;
    insertText(text: string): void;
    wrapSelection(before: string, after: string): void;
    focus(): void;
    blur(): void;
    getSelection(): {
        readonly start: number;
        readonly end: number;
        readonly text: string;
    };
    setSelection(start: number, end: number): void;
}
```

Ref handle.

Members (8):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `element` | `readonly element: HTMLTextAreaElement \| null;` |  | The textarea. |
| `runCommand` | `runCommand(id: string): void;` |  | Runs a toolbar item by id (built-in or custom). |
| `insertText` | `insertText(text: string): void;` |  | Replaces the selection with `text` (undoable). |
| `wrapSelection` | `wrapSelection(before: string, after: string): void;` |  | Toggles `before` / `after` around the selection. |
| `focus` | `focus(): void;` |  |  |
| `blur` | `blur(): void;` |  |  |
| `getSelection` | `getSelection(): {     readonly start: number;     readonly end: number;     readonly text: string; };` |  |  |
| `setSelection` | `setSelection(start: number, end: number): void;` |  |  |

### MarkdownEditorLocaleText

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownEditorLocaleText

```ts
interface MarkdownEditorLocaleText {
    readonly toolbar: string;
    readonly editor: string;
    readonly previewRegion: string;
    readonly more: string;
    readonly bold: string;
    readonly italic: string;
    readonly strikethrough: string;
    readonly superscript: string;
    readonly subscript: string;
    readonly uppercase: string;
    readonly lowercase: string;
    readonly heading: string;
    readonly headingLevel: string;
    readonly paragraph: string;
    readonly blockquote: string;
    readonly code: string;
    readonly codeBlock: string;
    readonly orderedList: string;
    readonly unorderedList: string;
    readonly link: string;
    readonly image: string;
    readonly table: string;
    readonly undo: string;
    readonly redo: string;
    readonly preview: string;
    readonly fullscreen: string;
    readonly linkText: string;
    readonly linkUrl: string;
    readonly imageUrl: string;
    readonly imageAlt: string;
    readonly imageFile: string;
    readonly uploading: string;
    readonly uploadFailed: string;
    readonly tableRows: string;
    readonly tableColumns: string;
    readonly tableHeader: string;
    readonly insert: string;
    readonly cancel: string;
    readonly countNearLimit: string;
    readonly countAtLimit: string;
}
```

Text of the toolbar, dialogs and count. `{0}` is the heading level or column number.

Members (40):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `toolbar` | `readonly toolbar: string;` |  |  |
| `editor` | `readonly editor: string;` |  |  |
| `previewRegion` | `readonly previewRegion: string;` |  |  |
| `more` | `readonly more: string;` |  |  |
| `bold` | `readonly bold: string;` |  |  |
| `italic` | `readonly italic: string;` |  |  |
| `strikethrough` | `readonly strikethrough: string;` |  |  |
| `superscript` | `readonly superscript: string;` |  |  |
| `subscript` | `readonly subscript: string;` |  |  |
| `uppercase` | `readonly uppercase: string;` |  |  |
| `lowercase` | `readonly lowercase: string;` |  |  |
| `heading` | `readonly heading: string;` |  |  |
| `headingLevel` | `readonly headingLevel: string;` |  |  |
| `paragraph` | `readonly paragraph: string;` |  |  |
| `blockquote` | `readonly blockquote: string;` |  |  |
| `code` | `readonly code: string;` |  |  |
| `codeBlock` | `readonly codeBlock: string;` |  |  |
| `orderedList` | `readonly orderedList: string;` |  |  |
| `unorderedList` | `readonly unorderedList: string;` |  |  |
| `link` | `readonly link: string;` |  |  |
| `image` | `readonly image: string;` |  |  |
| `table` | `readonly table: string;` |  |  |
| `undo` | `readonly undo: string;` |  |  |
| `redo` | `readonly redo: string;` |  |  |
| `preview` | `readonly preview: string;` |  |  |
| `fullscreen` | `readonly fullscreen: string;` |  |  |
| `linkText` | `readonly linkText: string;` |  |  |
| `linkUrl` | `readonly linkUrl: string;` |  |  |
| `imageUrl` | `readonly imageUrl: string;` |  |  |
| `imageAlt` | `readonly imageAlt: string;` |  |  |
| `imageFile` | `readonly imageFile: string;` |  |  |
| `uploading` | `readonly uploading: string;` |  |  |
| `uploadFailed` | `readonly uploadFailed: string;` |  |  |
| `tableRows` | `readonly tableRows: string;` |  |  |
| `tableColumns` | `readonly tableColumns: string;` |  |  |
| `tableHeader` | `readonly tableHeader: string;` |  |  |
| `insert` | `readonly insert: string;` |  |  |
| `cancel` | `readonly cancel: string;` |  |  |
| `countNearLimit` | `readonly countNearLimit: string;` |  |  |
| `countAtLimit` | `readonly countAtLimit: string;` |  |  |

### MarkdownEditorProps

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownEditorProps

```ts
interface MarkdownEditorProps extends TextareaProps {
    readonly value?: string | undefined;
    readonly defaultValue?: string | undefined;
    readonly onValueChange?: ((value: string, event: MarkdownValueChangeEvent) => void) | undefined;
    readonly toolbar?: readonly MarkdownToolbarItem[] | undefined;
    readonly toolbarOverflow?: 'menu' | 'wrap' | 'scroll' | undefined;
    readonly stickyToolbar?: boolean | undefined;
    readonly preview?: MarkdownPreviewMode | undefined;
    readonly defaultPreview?: MarkdownPreviewMode | undefined;
    readonly onPreviewChange?: ((mode: MarkdownPreviewMode, event: MarkdownToggleEvent) => void) | undefined;
    readonly renderPreview?: ((markdown: string) => ReactNode) | undefined;
    readonly fullscreen?: boolean | undefined;
    readonly defaultFullscreen?: boolean | undefined;
    readonly onFullscreenChange?: ((fullscreen: boolean, event: MarkdownToggleEvent) => void) | undefined;
    readonly onUpload?: ((file: File, options: {
        readonly signal: AbortSignal;
    }) => PromiseLike<MarkdownUploadResult>) | undefined;
    readonly syntax?: Partial<MarkdownSyntax> | undefined;
    readonly showCount?: boolean | undefined;
    readonly resizable?: boolean | undefined;
    readonly tabIndents?: boolean | undefined;
    readonly undoLimit?: number | undefined;
    readonly locale?: string | undefined;
    readonly localeText?: Partial<MarkdownEditorLocaleText> | undefined;
    readonly onBeforeCommand?: ((event: MarkdownBeforeCommandEvent) => void) | undefined;
    readonly onCommand?: ((event: MarkdownCommandEvent) => void) | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
    readonly classNames?: Partial<Record<MarkdownEditorPart, string>> | undefined;
    readonly styles?: Partial<Record<MarkdownEditorPart, CSSProperties>> | undefined;
    readonly ref?: Ref<MarkdownEditorApi> | undefined;
}
```

Members (28):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value?: string \| undefined;` | optional | Markdown source (controlled). |
| `defaultValue` | `readonly defaultValue?: string \| undefined;` | optional |  |
| `onValueChange` | `readonly onValueChange?: ((value: string, event: MarkdownValueChangeEvent) => void) \| undefined;` | optional | Every edit: typing, a command, a form reset. |
| `toolbar` | `readonly toolbar?: readonly MarkdownToolbarItem[] \| undefined;` | optional | Toolbar entries; default `MARKDOWN_DEFAULT_TOOLBAR`. An empty array hides the toolbar. |
| `toolbarOverflow` | `readonly toolbarOverflow?: 'menu' \| 'wrap' \| 'scroll' \| undefined;` | optional | Items that do not fit: in a More menu (default), wrapped, or scrolled. |
| `stickyToolbar` | `readonly stickyToolbar?: boolean \| undefined;` | optional | Keeps the toolbar visible while the page scrolls. |
| `preview` | `readonly preview?: MarkdownPreviewMode \| undefined;` | optional |  |
| `defaultPreview` | `readonly defaultPreview?: MarkdownPreviewMode \| undefined;` | optional |  |
| `onPreviewChange` | `readonly onPreviewChange?: ((mode: MarkdownPreviewMode, event: MarkdownToggleEvent) => void) \| undefined;` | optional |  |
| `renderPreview` | `readonly renderPreview?: ((markdown: string) => ReactNode) \| undefined;` | optional | Renders the preview; receives the deferred source. No parser is bundled. |
| `fullscreen` | `readonly fullscreen?: boolean \| undefined;` | optional |  |
| `defaultFullscreen` | `readonly defaultFullscreen?: boolean \| undefined;` | optional |  |
| `onFullscreenChange` | `readonly onFullscreenChange?: ((fullscreen: boolean, event: MarkdownToggleEvent) => void) \| undefined;` | optional |  |
| `onUpload` | `readonly onUpload?: ((file: File, options: {     readonly signal: AbortSignal; }) => PromiseLike<MarkdownUploadResult>) \| undefined;` | optional | Uploads an image file from the image dialog or a paste. |
| `syntax` | `readonly syntax?: Partial<MarkdownSyntax> \| undefined;` | optional | Marker overrides per command. |
| `showCount` | `readonly showCount?: boolean \| undefined;` | optional | Shows the character count (with `maxLength`, `n / max`). |
| `resizable` | `readonly resizable?: boolean \| undefined;` | optional | Vertical resize handle on the textarea. Default true. |
| `tabIndents` | `readonly tabIndents?: boolean \| undefined;` | optional | Tab and Shift+Tab indent instead of moving focus. Default false. |
| `undoLimit` | `readonly undoLimit?: number \| undefined;` | optional | Steps of the internal history used where native undo is unavailable. Default 100. |
| `locale` | `readonly locale?: string \| undefined;` | optional | Locale of uppercase / lowercase. |
| `localeText` | `readonly localeText?: Partial<MarkdownEditorLocaleText> \| undefined;` | optional |  |
| `onBeforeCommand` | `readonly onBeforeCommand?: ((event: MarkdownBeforeCommandEvent) => void) \| undefined;` | optional |  |
| `onCommand` | `readonly onCommand?: ((event: MarkdownCommandEvent) => void) \| undefined;` | optional |  |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |
| `classNames` | `readonly classNames?: Partial<Record<MarkdownEditorPart, string>> \| undefined;` | optional |  |
| `styles` | `readonly styles?: Partial<Record<MarkdownEditorPart, CSSProperties>> \| undefined;` | optional |  |
| `ref` | `readonly ref?: Ref<MarkdownEditorApi> \| undefined;` | optional |  |

### MarkdownSyntax

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownSyntax

```ts
interface MarkdownSyntax {
    readonly bold: readonly [
        string,
        string
    ];
    readonly italic: readonly [
        string,
        string
    ];
    readonly strikethrough: readonly [
        string,
        string
    ];
    readonly code: readonly [
        string,
        string
    ];
    readonly superscript: readonly [
        string,
        string
    ];
    readonly subscript: readonly [
        string,
        string
    ];
    readonly codeBlock: string;
    readonly blockquote: string;
    readonly unorderedList: string;
    readonly orderedList: string;
    readonly heading: string;
}
```

Markers per command: merged over the CommonMark / GFM defaults by the `syntax` prop.

Members (11):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `bold` | `readonly bold: readonly [     string,     string ];` |  |  |
| `italic` | `readonly italic: readonly [     string,     string ];` |  |  |
| `strikethrough` | `readonly strikethrough: readonly [     string,     string ];` |  |  |
| `code` | `readonly code: readonly [     string,     string ];` |  |  |
| `superscript` | `readonly superscript: readonly [     string,     string ];` |  |  |
| `subscript` | `readonly subscript: readonly [     string,     string ];` |  |  |
| `codeBlock` | `readonly codeBlock: string;` |  | Fence of `codeBlock`. |
| `blockquote` | `readonly blockquote: string;` |  | Line prefix of `blockquote`. |
| `unorderedList` | `readonly unorderedList: string;` |  | Line prefix of `unorderedList`. |
| `orderedList` | `readonly orderedList: string;` |  | Delimiter after the number of `orderedList` items (`'.'` gives `1. `). |
| `heading` | `readonly heading: string;` |  | Heading marker character. |

### MarkdownTextState

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownTextState

```ts
interface TextState {
    readonly text: string;
    readonly start: number;
    readonly end: number;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `text` | `readonly text: string;` |  |  |
| `start` | `readonly start: number;` |  | Selection start (UTF-16 offset). |
| `end` | `readonly end: number;` |  | Selection end; equal to `start` for a caret. |

### MarkdownToggleEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownToggleEvent

```ts
interface MarkdownToggleEvent {
    readonly source: MarkdownEditorSource;
}
```

Second argument of `onPreviewChange` / `onFullscreenChange` (frozen).

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: MarkdownEditorSource;` |  |  |

### MarkdownToolbarCustomItem

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownToolbarCustomItem

```ts
interface MarkdownToolbarCustomItem {
    readonly id: string;
    readonly label: string;
    readonly icon?: ReactNode;
    readonly disabled?: boolean | undefined;
    readonly onSelect: (api: MarkdownEditorApi) => void;
}
```

A custom toolbar item.

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `id` | `readonly id: string;` |  |  |
| `label` | `readonly label: string;` |  | Accessible name and tooltip. |
| `icon` | `readonly icon?: ReactNode;` | optional | Icon (decorative); without one the label is shown. |
| `disabled` | `readonly disabled?: boolean \| undefined;` | optional |  |
| `onSelect` | `readonly onSelect: (api: MarkdownEditorApi) => void;` |  |  |

### MarkdownUploadResult

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownUploadResult

```ts
interface MarkdownUploadResult {
    readonly src: string;
    readonly alt?: string | undefined;
}
```

Upload hook result.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `src` | `readonly src: string;` |  |  |
| `alt` | `readonly alt?: string \| undefined;` | optional |  |

### MarkdownValueChangeEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownValueChangeEvent

```ts
interface MarkdownValueChangeEvent {
    readonly source: MarkdownEditorSource;
    readonly reason: 'input' | 'command' | 'reset';
}
```

Second argument of `onValueChange` (frozen).

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: MarkdownEditorSource;` |  |  |
| `reason` | `readonly reason: 'input' \| 'command' \| 'reset';` |  |  |

## Types

### MarkdownEditorPart

Kind: type

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownEditorPart

```ts
type MarkdownEditorPart = 'toolbar' | 'textarea' | 'preview' | 'count';
```

### MarkdownEditorSource

Kind: type

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownEditorSource

```ts
type MarkdownEditorSource = 'pointer' | 'keyboard' | 'touch' | 'api';
```

Input that ran a command.

### MarkdownPreviewMode

Kind: type

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownPreviewMode

```ts
type MarkdownPreviewMode = 'off' | 'tab' | 'split';
```

Preview state: hidden, instead of the source (tab), or beside it (split).

### MarkdownTextCommand

Kind: type

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownTextCommand

```ts
type MarkdownTextCommand = 'bold' | 'italic' | 'strikethrough' | 'superscript' | 'subscript' | 'uppercase' | 'lowercase' | 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'blockquote' | 'code' | 'codeBlock' | 'orderedList' | 'unorderedList';
```

Text commands `applyCommand` runs (the toolbar adds dialogs, history, preview and fullscreen).

### MarkdownToolbarItem

Kind: type

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownToolbarItem

```ts
type MarkdownToolbarItem = MarkdownToolbarItemId | '|' | MarkdownToolbarCustomItem;
```

A toolbar entry: a built-in id, `'|'` for a separator, or a custom item.

### MarkdownToolbarItemId

Kind: type

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MarkdownToolbarItemId

```ts
type MarkdownToolbarItemId = MarkdownTextCommand | 'heading' | 'link' | 'image' | 'table' | 'undo' | 'redo' | 'preview' | 'fullscreen';
```

Built-in toolbar item ids.

## Constants

### DEFAULT_MARKDOWN_SYNTAX

Kind: const

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/DEFAULT_MARKDOWN_SYNTAX

```ts
const DEFAULT_MARKDOWN_SYNTAX: MarkdownSyntax;
```

### MARKDOWN_DEFAULT_LOCALE_TEXT

Kind: const

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MARKDOWN_DEFAULT_LOCALE_TEXT

```ts
const MARKDOWN_DEFAULT_LOCALE_TEXT: MarkdownEditorLocaleText;
```

### MARKDOWN_DEFAULT_TOOLBAR

Kind: const

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/MARKDOWN_DEFAULT_TOOLBAR

```ts
const MARKDOWN_DEFAULT_TOOLBAR: readonly MarkdownToolbarItem[];
```

The default toolbar.

### imageMarkdown

Kind: const

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/imageMarkdown

```ts
const imageMarkdown: (alt: string, src: string) => string;
```

`![alt](src)`.

### linkMarkdown

Kind: const

Page: https://salmonui.dev/docs/reference/editors/markdown-editor/linkMarkdown

```ts
const linkMarkdown: (text: string, url: string) => string;
```

`[text](url)`; an empty text uses the URL.
