Support pasting markdown

I want to support pasting markdown directly into the editor, and have it parsed and transformed into nodes.

One option is to have the signature of transformPastedText allow returning a Slice:

transformPastedText(string) → union<string, Slice>

An alternative is to add a clipboardTextParser prop as a partner to clipboardParser.

Thoughts?

A concern with hooking into the parsing for pasted content is that it’s a rather subtle process, partially driven by the context into which you’re pasting. Though I guess in simpler schemas in most situations you would get an okay result even if you ignore that.

I’m also kind of worried about the proliferation of props around clipboard handling. We’re probably not really hitting the right abstraction there yet. A ‘fully reimplement it yourself’ prop handlePaste(view, clipboardHTML, clipboardText) → bool might be a good stopgap for supporting custom behavior without digging us even further into a poor framing. Would that work for you?

Yes that would be perfect.

Is this something that you can squeeze into 0.20?

Why not use transformPasted and match text slices?

Yes, definitely. It looks like I’ll need something like it myself, too.

That almost works, but you can no longer tell the difference between single and multiple newlines at that point, so it would go wrong for things like line-wrapped markdown or tight lists.

2 Likes

This patch adds handleDrop and handlePaste events which can be used to do something like this. It’ll be part of 0.20.0, to be released early next week (or, if I’m ridiculously fast today, tonight).

2 Likes