Open simonbengtsson opened 1 month ago
In addition to the above issue there is also a minor issue that pasting adds an extra new line when the last item is a list item. Except for these issues the following class works for copy pasting all types of text formatting (lists, bold etc) both inside fleather editor and from/to other editors such as Notion.
class SimpleMarkdownClipboardManager extends ClipboardManager {
const SimpleMarkdownClipboardManager();
@override
Future<void> setData(FleatherClipboardData data) async {
final plainText = data.plainText;
final clipboardDelta = data.delta;
if (clipboardDelta != null && clipboardDelta.length > 0) {
// Add new line since required by ParchmentDocument.fromDelta
final delta = clipboardDelta.concat(Delta()..insert('\n'));
final doc = ParchmentDocument.fromDelta(delta);
final markdown = parchmentMarkdown.encode(doc);
await Clipboard.setData(ClipboardData(text: markdown));
} else if (plainText != null) {
await Clipboard.setData(ClipboardData(text: plainText));
}
}
@override
Future<FleatherClipboardData?> getData() async {
final data = await Clipboard.getData(Clipboard.kTextPlain);
final markdown = data?.text ?? '';
// Many editors such as Notion use "- " as plaint text format for unordered lists
markdown = markdown.replaceAll('\n- ', '\n* ');
final doc = parchmentMarkdown.decode(markdown);
return FleatherClipboardData(delta: doc.toDelta());
}
}
After diving into the "extra new line when pasting bullet list" issue mentioned above I realized it is actually reproducible in the quilljs playground as well. And they have an issue describing it here: https://github.com/slab/quill/issues/1483.
Steps to Reproduce
Environment
Logs
Document delta:
FleatherClipboardData delta: