Extensions

smartPaste

Behaviour takes options 1.76 kB gzipped

Paste what was meant, not what was copied.

A spreadsheet copied as text is tabs and newlines; a README copied from a terminal is Markdown; both arrive as a paragraph with the punctuation in it. This looks at plain text before the editor does and, when the shape is unmistakable, builds the table or parses the Markdown instead. Anything with real HTML on the clipboard is left to the parser, which already reads a table copied from a browser.

Needs the table nodes for the table half and whatever nodes the Markdown names for the other: a heading pasted into an editor with no heading extension stays text, because that editor cannot hold one.

1 · Install

One package for every extension · there is no @matrajs/smartPaste to install.

npm i @matrajs/core

2 · Add it to the editor

Import it and put it in the extensions array. That array is the whole feature list: what is not in it is not in your bundle and not in the document's schema.

import { createEditor, document, paragraph, text, smartPaste } from '@matrajs/core'

const editor = createEditor({
  extensions: [document, paragraph, text, smartPaste({ … })],
  element: document.querySelector('#editor'),
})

3 · Use it

Nothing to call · this one works once it is in the array. Paste what was meant, not what was copied.

Options

smartPaste is a function · call it with an options object.

Option Type What it does
tables boolean Tab-separated and comma-separated text becomes a table. Default true.
csv boolean Comma-separated text counts as a table too. Default true.
headerRow boolean The first row of a pasted table is a header row. Default true.
markdown boolean Text that reads as Markdown is parsed as Markdown. Default true.

← All 83 extensions

Edit this page on GitHub