EditorEvents as the second argument and EditorOptions as the third argument to mount. mount checks both: an unknown key, or a value of the wrong type, makes it reject with invalid-argument. A null value counts as omitted.
Editor options
Three options can change after mount, through a method. The rest are fixed at mount; to change one, destroy the editor and mount a new one.ImageAdapter
Shows, imports and exports the images your app stores. See
ImageAdapter. Without images and files, image Markdown stays literal source, and pasted or dropped images can’t be imported.FileAdapter
Resolves path images and
![[name]] embeds into images, audio, video, PDFs and file cards. See FileAdapter. With files set, every path image is shown through FileAdapter.resolve, not ImageAdapter.presentation.WikiLinkAdapter
Resolves, opens and suggests
[[wiki links]]. See WikiLinkAdapter. Without it, wiki links stay literal source and typed brackets stay text.boolean
default:"true"
Whether the person can edit.
false permits selection, copying, find, navigation, folding and mode switches, and makes every method that changes the document throw read-only. See setEditable.TextInputPreferences
default:"{}"
A
TextInputPreferences object: input hints for both editing surfaces, and smart punctuation. Every field is optional. setTextInputPreferences replaces the whole set, so a field you leave out returns to its default.The three attributes are hints: the browser and the operating system decide whether they take effect.Partial<EditorLabels>
default:"English defaults"
A
Partial<EditorLabels> that replaces built-in text and accessible names, key by key. Omitted keys keep their defaults. A value that isn’t a string makes mount reject with invalid-argument. Inkkit inserts every label as text, never as markup. See Labels for every key and its default.Keymap
default:"History, block moves and table exit"
Shortcut bindings, by
ShortcutName, in ProseMirror key notation. Formatting has no default bindings. See Shortcuts for every name, its default keys and how setKeymap replaces the map.object
default:"Both true"
Turns presentation plugins off. Code and diagram source stay editable and keep their authored spelling either way.
A
SlashMenuOptions object. It offers block commands when the person types / on an empty line. See Slash menu.Events
Onlychanged is required. A handler that isn’t a function, or a name that isn’t listed here, makes mount reject with invalid-argument.
During a method call, changed and commandStateChanged arrive before the call returns, and are dropped if it fails. An exception thrown by your handler stays yours: Inkkit passes it to the platform’s reportError() and carries on. The exception is clipboard, whose failure is clipboard-unavailable.
(snapshot: DocumentSnapshot) => void
required
The document’s text changed: an edit, undo, redo, paste, source replacement or typing in source mode. It doesn’t fire for a load, a reload or a refused edit. A change that leaves the saved text as it was advances the revision without firing
changed.It receives a DocumentSnapshot of the new text: documentId, generation, revision, format, text and dirty. Its revision is the revision of this change, the same one that output taken in the handler carries. Use it to schedule a save, and take a fresh snapshot when you write the file. See Documents and saving.(state: CommandState) => void
What the editor can do, or the caret, changed: the selection, the document, history, the editing mode, editability, input preferences, composition or a pending image import. It also fires once after each load or reload, without the intermediate states. It receives the current
CommandState. This is the only event that reports the caret.(href: string) => void
The person clicked a rendered Markdown link with Mod held (Command on Apple platforms, Control elsewhere) in formatted mode, whether or not the editor is editable. It receives the destination as authored; a relative address or fragment isn’t resolved against the page. It doesn’t fire for an empty address or for a scheme that Inkkit doesn’t open; see links. Without this handler, Markdown links don’t open. Wiki links go to
WikiLinkAdapter.open instead.(text: string) => void
The person clicked the Copy button on a code block. It receives the code block’s text; your app writes the clipboard. Without this handler, Inkkit draws no Copy button. Whether it is set is fixed at mount.
(error: InkKitError) => void
A failure that no call is waiting for, such as an edit the person made that the preservation check refused, or a file that couldn’t be resolved. It always receives an
InkKitError. See Errors for the sources and codes.(content: ClipboardOutput) => void | Promise<void>
The person copied or cut a selection that holds an image or a diagram. It receives a
ClipboardOutput of the selection, with the version the copy started from. Write it to the native clipboard and resolve after the write succeeds: a cut removes the selection only then. With this handler, Inkkit writes nothing to the web clipboard for that copy.If the handler throws or rejects, Inkkit reports clipboard-unavailable and a cut removes nothing. Without the handler, such a copy puts readable text and HTML on the clipboard and reports clipboard-unavailable. See Copy, paste and print.Command state
commandState returns a CommandState, and commandStateChanged sends one. It describes the moment you ask; it doesn’t promise that a later call succeeds, so handle the result and errors when the person acts. Reading it never dirties the document.
DocumentVersion
The document this state describes.
'md' | 'txt'
The document format.
EditingMode
An
EditingMode: 'formatted' or 'source'. A TXT document is always 'source'.boolean
The editing policy.
boolean
Text composition (IME) is in progress.
boolean
An image import is running.
CaretState
A
CaretState: the formatting at the selection. In source and TXT modes it is always { marks: [], block: { type: 'paragraph' }, quoted: false }.object | undefined
Present only when the selection is in a table in formatted mode.
object
What each command can do now. Every entry is
false while the editor is read-only, composing or has an image import pending.Format commands
format takes a FormatCommand and optional FormatOptions. It works in formatted mode only.
FormatOptions has two optional fields. Any other field, a field with another command, or an unknown command throws invalid-argument.
string
Only with
link. It must be a relative address, a fragment, a query, or an http, https, mailto or tel address, with no control characters, and Markdown must be able to write it so that it reads back the same. Otherwise format throws invalid-argument. In a reference link, the shared definition changes, so every link that uses it changes.string
Only with
codeBlock. The info string of the new code block.Table commands
table takes a TableCommand and optional TableOptions. It works in formatted mode only. Every command except insert works on the table that holds the selection. Movement and sorting work only in a regular table of at most 100 rows and 100 columns.
Each
TableOptions field belongs to one command. A field with another command, an unknown field, or a value outside its range throws invalid-argument.
Smart punctuation
WithtextInput.smartPunctuation set to true, typing in formatted mode changes only the character being typed. A change to the setting takes effect on the next key press.
- Nothing already in the note changes, on open or on save. The curly character is saved as typed.
- Undo or Backspace straight after a rule puts back what was typed. A second Undo removes the typing.
- The rules don’t apply in source and TXT modes, in code, front matter, comments, blocks kept as literal Markdown, or in Markdown syntax being typed: a code span, a link destination, a web address, an unclosed wiki link, footnote label, HTML tag or comment, a reference definition, and
--in a line that starts with|. - A dead-key quote, as on US International, follows the rules when its composition commits exactly one
"or'at the caret.
Slash menu
WithslashMenu.enabled, typing / at the end of an empty paragraph or heading, or after a line break that ends one, opens a menu of block commands. This includes empty paragraphs in list items, quotes and callouts. It doesn’t open in a read-only editor, in source or TXT mode, in code blocks, table cells, front matter or literal Markdown blocks, or during composition. A slash anywhere else stays text.
The text typed after the slash filters the menu. A command matches when its displayed name, or one of its additional words, starts with the filter, ignoring case. Choosing a command replaces the slash and filter in one edit; one Undo restores the line as it was before the slash. A refused edit changes nothing and reports preservation through events.error. The menu uses the suggestions and suggestionsEmpty labels and the --inkkit-menu-* tokens.
Built-in slash commands
callout opens a second list: Note, Tip, Important, Warning and Caution (slashNote, slashTip, slashImportant, slashWarning, slashCaution). diagram appears only when previews are available: not with the core entry, and not when rendering.diagramPreview is false. Changing a name through labels changes what it matches; the additional words stay.
SlashCommand
ASlashCommand is a command your app adds through customCommands. A blank name, keywords that aren’t strings, a missing action or an unknown field makes mount reject with invalid-argument.
string
required
The displayed name. It must not be blank.
readonly string[]
Additional words that match the filter, compared as for built-in commands.
(context: DocumentContext) => string | undefined | Promise<string | undefined>
required
Called when the person chooses the command, with the current
documentId, generation and a new operationId. The menu closes when it is called, and a promise doesn’t block typing.- A string is Markdown that Inkkit parses and inserts in place of the trigger line, through the same preservation checks and single undo step as a built-in command.
''removes the slash and filter and restores the line as it was before the slash.undefinedcancels and keeps the text as typed.
stale-document. A result that isn’t a string or undefined reports invalid-argument. A thrown or rejected error is reported through events.error: an InkKitError as it is, anything else as internal with the error as cause. A failed action keeps the trigger text. After destroy, late results and errors are ignored.
