What copy writes
When a person copies or cuts in the editor, Inkkit handles the browser’s event and writes two formats:- Plain text: the text a reader sees, with no Markdown syntax or escapes.
- HTML: semantic markup, such as headings, lists,
<strong>,<mark>, tables, links and footnotes.
[label]: address "title". A link whose address isn’t kept is copied as its text.
Inkkit’s HTML also carries inert metadata that only Inkkit’s own paste reads, so reference links, footnotes and callouts survive a copy and paste between Inkkit editors. Other apps ignore it. Comments copied and pasted back into the same loaded editor are kept, as long as the clipboard text and HTML come back unchanged; loading a document, destroying the editor or copying another selection ends that.
In source mode, copy writes the readable text and HTML of the selected Markdown, not the source characters. The source is in markdown from clipboardSnapshot.
Copy as Markdown
Markdown source is an explicit operation. To offer Copy as Markdown, callclipboardSnapshot and write its markdown to the clipboard. For the whole document, markdown is the exact source. For a selection, it includes the definitions that the copied references and footnotes need.
stale-document if the document, its revision or the editing mode changes before the copy is ready.
Images and diagrams on a native clipboard
A web view can’t put image bytes on the system clipboard by itself. When a copied or cut selection holds an image or a Mermaid diagram, Inkkit callsevents.clipboard with a ClipboardOutput and writes nothing to the clipboard itself. Your handler writes the native clipboard and returns a promise that resolves after the write succeeds.
htmlembeds each image as adata:URL.imageslists the portable bytes, which come from your adapter’s export, in the order they appear inhtml. A diagram’s image has an emptyreference.diagramsholds each complete diagram’s source and a PNG. A diagram that can’t be exported has anerrorand stays readable code inhtml.- An image or diagram whose bytes aren’t available has an
errorand appears as text, such as[Photo: image unavailable]. Degraded output describes itself and isn’t also reported as an error. - A cut removes the selection only after the handler resolves. If the handler throws or rejects, or a selected image or diagram can’t be copied, the cut removes nothing and
events.errorreceives the reason.
clipboard-unavailable. A web view with a Content Security Policy must allow local blob: image URLs, which diagram export uses. Embed in a web view shows how to pass the bytes across a bridge.
How paste is imported
A paste the person makes and a call topaste with what your app read from the native clipboard run the same import. In formatted mode, Inkkit picks the first route that fits:
- Into a code block: the text is inserted as is.
- Explicit Markdown:
markdown, which onlypastecan supply, is read as Markdown. HTML that comes with it is used only to find its images. - A spreadsheet: HTML that is one table, or text that contains a tab, becomes a table. See Spreadsheets.
- HTML: a web page, notes app or word processor imports as readable content. See Web pages.
- Images without HTML: each image goes through your image adapter and becomes its own paragraph.
- Plain text: read as Markdown. A web address pasted over selected text links that text instead.
markdown when it’s given. pasteAsPlainText is the way to insert literal text in formatted mode, for a Paste as Plain Text command. When the person pastes code copied from Visual Studio Code, it becomes a code block in its language.
A paragraph at either end of the pasted content joins the text at the caret, so a pasted phrase stays in its sentence. Other blocks, such as headings, lists and code blocks, are inserted whole. After the paste, the caret is after the pasted content.
Images in pasted HTML go through your adapter’s importImage. An image that can’t be imported becomes the text [Name: image unavailable], and events.error receives image-unavailable. paste captures one operation, so don’t read the system clipboard again while it runs. An import that the editor can’t save is refused with preservation; offer plain text instead:
insertImages or insertPaths with the drop point; see Images, files and wiki links.
Web pages
Pasted or dropped HTML keeps only what reads back as the same structure. Before inserting it, Inkkit writes the content as Markdown and reads it back as GitHub Flavored Markdown, as strict CommonMark and as CommonMark with raw HTML turned off. A part that would read back differently in any of them, or would hold a link address that Inkkit doesn’t keep, is imported in a simpler form: first without Inkkit’s metadata, such as a callout or reference label, then without its formatting, keeping its text.- Left out: HTML comments,
style,meta,title,input, the contents oftemplateandnoscript, and elements hidden with thehiddenattribute or an inlinedisplay: none. - Simplified:
u,sub,small,abbr,citeand similar wrappers keep their text without the wrapper.figurekeeps its image and caption text. A definition list becomes a bold term and a plain paragraph for each entry. A checkbox at the start of a list item makes a task item. - Whitespace collapses as in a browser, except in
pre,codeand elements whose inline style preserves whitespace, so copied code keeps its indentation. Style sheets aren’t read. - Literal source: custom elements,
script,iframe,svg,math,object, form controls such asbuttonandtextarea, and other unrecognized elements stay literal source when it reads back as written, and otherwise import as a code block with the same text. HTML is never executed. - Images are never saved by address: your adapter stores the bytes and returns the reference.
Spreadsheets
Tab-separated text and simple HTML tables paste as table cells, without flattening them:- Rows can end in LF, CRLF or CR, and fields can use paired double quotes with doubled quotes inside. Short rows are padded with empty cells.
- Outside a table, the first row becomes the header of a new table. HTML column alignment carries over.
- Inside a table, the paste fills and grows a rectangle from the selected cell. Header cells stay headers.
- Tables are limited to 100 rows and 100 columns, including growth.
- Cell text is literal: Markdown punctuation in it is escaped on save.
preservation before any cell changes. Malformed tab-separated text without HTML is refused anywhere.
Text that contains a tab becomes a table even when it isn’t from a spreadsheet, such as tab-indented code copied as plain text. Use pasteAsPlainText to insert it literally (#331).
Links that Inkkit keeps
Inkkit keeps and opens links whose address has no scheme, such asnotes/a.md, #intro or ?q=1, and links whose scheme is http, https, mailto or tel, in any letter case. An address with a control character other than leading or trailing whitespace isn’t kept.
A link with any other scheme, such as javascript:, data:, file: or an app’s own scheme:
- shows without an address in the editor, so Mod-click doesn’t open it;
- is refused by
format('link')withinvalid-argument; - is copied, imported from HTML and printed as its text.
printableSnapshot returns the whole document as a standalone HTML page for printing. Your app owns the Print and PDF commands, dialogs and files: load html into a print view and print it.
- It doesn’t depend on the selection, scrolling, folding or comment visibility, and it doesn’t change the source, revision or history.
- It includes footnotes, resolved reference links, tables, images, highlights, Mermaid diagrams as images, and the full body of folded callouts. It leaves out author comments and editor controls, even when comments are shown. TXT prints as literal text.
- Images are embedded as
data:URLs from your adapter, andassetsholds copies of their bytes.stylesholds the print CSS on its own, which wraps long text and fits images to the page; adapt it to your paper and layout.
warnings:
The export never returns partial content. It rejects with
image-unavailable when an authored image has no adapter or its bytes don’t decode, with diagram-unavailable when a diagram that rendered can’t be turned into an image, and with stale-document when the document is edited, undone or reloaded during the export. Like clipboardSnapshot, it needs blob: image URLs.
The editor reference has the exact signatures of clipboardSnapshot, paste, pasteAsPlainText and printableSnapshot, and Errors lists every code.
