[[wiki links]], pass an adapter at mount. Without one, that Markdown stays literal source and saves unchanged.
Adapters are fixed at mount. The adapters reference has every member and type.
Images
AnImageAdapter has three members:
presentation(reference)returns a display URL, orundefinedwhen the image is unavailable, which shows the alt text. It is synchronous, so make it a lookup.importImage(input, context)stores bytes that a paste or drop captured, and returns the reference to write into the Markdown.exportImage(reference, context)returns the stored bytes for clipboard and print output.
[Name: image unavailable] in place of the image and reports image-unavailable through events.error. Reject with an ordinary Error or InkKitError with code image-unavailable. Both HTML and image-file pastes keep the remaining content. Other InkKitError codes cancel the paste.
importImage receives no abort signal, and Inkkit sets no time limit. While an import is pending, snapshot() and every edit throw operation-pending, so the document can’t be saved. Settle the promise promptly, and give a store that can stall its own timeout. Cancellation is tracked in #325.
Files
AFileAdapter resolves path images and ![[name]] embeds. resolve(reference, context) decides what the file is and returns a FilePresentation. Inkkit never guesses the kind from an extension. Look the file up by reference.target; reference.fragment holds what follows the #, such as t=10 or page=3, which you map onto the display URL.
image,audio,videoorpdfshows the resource aturl. ThemimeType, when given, must match the kind.fileshows a card with no preview.missingshows a card with thefileMissinglabel.errorshows a card whose status is yourmessage, a short reason written for the person.- A rejected or invalid result shows a card with the
fileErrorlabel and reportsfile-unavailablethroughevents.error.
resolve again. Setting open adds an Open button to every card, and contextMenu receives right-clicks with a ClientPoint. An exception they throw is reported as file-unavailable. Both return nothing, so handle failures of asynchronous work inside them.
Abandon the work when context.signal aborts. Inkkit aborts a request when the reference changes, the person retries, the mode changes, the document reloads or the editor is destroyed, and it ignores late results even if you don’t stop.
When files is set, it presents every image, including path images, and ImageAdapter.presentation isn’t called. Keep images as well if people paste or drop images: only ImageAdapter.importImage stores new bytes.
Wiki links
AWikiLinkAdapter turns [[Note]], [[Note#Heading]] and [[Note|alias]] into links. Only open is required.
open(reference, context)runs on a Mod-click, or Enter or Space on the focused link, including in a read-only editor.reference.targetis the note name with escapes removed. It is empty for a link to a heading in the same note, such as[[#Heading]].resolve(reference, context)is synchronous and only marks a link as missing, with thewikiMissinglabel as its tooltip. Answer from an index you already hold.suggest(query, context)returns note names, in display order, for the text typed after[[. Inkkit inserts the chosen name, escaped. A newer query aborts the previous request, and Inkkit ignores late answers. Return only names that are valid link targets: one invalid name closes the list and reportsfile-unavailable.
wikiLinks is set, typing the closing ]] of a complete link also makes a link. See Markdown support for the syntax.
References and display URLs
References are opaque. Inkkit passes them to your adapter exactly as authored, writes the reference yourimportImage returns as the image’s Markdown destination, and never infers a path, fetches from the network or rewrites a reference. A path reference is read like a URL: a # that belongs to a file name must be written %23, and Inkkit doesn’t decode it.
Display URLs are private to your app. Return a URL that works offline in your page, such as an object URL or a custom scheme your web view serves. Inkkit never writes a display URL into the document, the clipboard or printable output.
Portable output
Copy and print carry image bytes, not display URLs, so they call your export function:- For path images without a file adapter,
ImageAdapter.exportImage. - With a file adapter,
FileAdapter.exportImage. If you leave it out, path images fall back toImageAdapter.exportImage, and named images,![[name]], have no portable bytes.
mimeType. Print checks the bytes against the type. Other formats, such as SVG, can’t be exported. When export fails, clipboard output keeps a description and an error for that image, and printableSnapshot() rejects with image-unavailable. See Copy, paste and print.
Retention and cleanup
Your app owns stored bytes, their lifetime and their deletion. Inkkit never tells you when an image or file stops being used.- Keep imported bytes after insertion and before the document is saved. Undo can bring back a deleted image, and an unsaved edit can refer to bytes that no saved file mentions.
- Expect orphans. Loading another document,
setEditable(false)anddestroy()cancel a pending import without telling the adapter, so bytes it stored late are never inserted. - Sweep with care. A sweep based only on saved Markdown can delete bytes that a pending import or an unsaved edit still needs.
- Revoke object URLs when you delete the bytes, not when an image leaves the document.
DocumentContext with documentId, generation and an operationId unique to that call. Use it to tie stored bytes to the document and the request that made them.
