Skip to content

Paste plugin #137

@gohabereg

Description

@gohabereg

When content is pasted to the editor and contains HTML or multi-line plain text, it should be converted into the blocks.

  1. Each tool registers a tag or tags it accepts. Inline tools should also register the tag/tags to convert inline tags into fragments within model.

  2. Tools can also register file extensions to handle.

  3. Tools can also register Regex patterns to be replaced with that tool (e.g. video/image links)

Some requirements extracted from the V2. Please refer to V2 codebase and docs for details.

# Requirement
R1 If a tool sets pasteConfig = false, the native paste event must be allowed to bubble. However, we should still not allow default behaviour.
R2 In read-only mode, all paste handling must be disabled.
R3 If the clipboard contains application/x-editor-js JSON, blocks must be deserialized and inserted
R4 If the clipboard or drop data contains files and at least one tool handles files, each file must be routed to the matching tool by extension (case-insensitive) or MIME type (with wildcard subtype support). Unrecognized files must be silently skipped.
R5 HTML paste must must be processed in a way that doesn't create an XSS attack possibility.
R6 If HTML equals the plain text equivalent or is not valid HTML, it must be processed as plain text.
R7 Plain text must be split on newlines into separate blocks using the default tool.
R8 HTML must be recursively split into block nodes and inline fragments.
R9 Block HTML elements whose tag is registered by a tool must be processed by that tool.
R10 If two tools register the same HTML tag, the first-registered tool wins; a warning must be logged.
R11 A single inline paste into a default tool's block must attempt pattern matching if text length ≤ 450 chars.
R12 Pattern matching must require a full-string match (not substring).
R13 If a pattern matches, the matched tool should process it
R14 If no pattern matches and there is a focused input, text is inserted at caret
R15 Pasting a single block of the same tool type with inline-only content must insert at caret position, not create a new block.
R16 When multiple blocks are pasted, if the current block is the default tool and empty, the first pasted block replaces it.
R17 Invalid MIME types in a tool's files.mimeTypes must be filtered with a warning.
R18 Non-RegExp patterns in a tool's patterns config must be skipped with a warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions