My search-fu is failing me but I remember a similar issue where you would paste an image into the composer and there would be both the image and the url of that image inserted.
What would be awesome here is if we check for a format that excel has and just format the results as a proper CommonMark table (cause it exists in the clipboard as xml), this would be so much magic and so much cool.
If you request the clipboard data as plain text you get probably the most useful thing for turning into a table:
'1\t3\n2\t4\n'
(the closest you have to XML is text/html and that’s a standalone page)
All of them? Very common to have the same object on the clipboard in multiple formats so different programs can use it in the way they see fit. e.g. copy an image in your browser (Right-Click, Copy) and you can retrieve it as any of: TIMESTAMP,TARGETS,SAVE_TARGETS,MULTIPLE,image/png,text/html,text/x-moz-url. That’s why sometimes you get the URL, sometimes you get the image itself depending on the application. Or an object embed.
As much fun as it would be to do something super nifty here, all I think this needs is “just paste the image” for now.
What other apps cause an error on paste though, specifically? Where two sets of data appear when you paste? I believe Excel and its clones are the only one.
I copy and paste tables from Excel all the time. With forumlas in Excel to turn columns into Markdown format. The always forget to copy to notepad before pastuing otherwise it will paste an image. Frustrating, if you post Excel content a lot.
That does not sound like the issue I encountered. The try topic is gone due to the daily reset. Here’re the steps I completed to cause the issue:
Created a test document in Word for Mac. I used https://www.lipsum.com/ to generate 5 paragraphs of text. I did not include any formatting or images in the document.
I copied the entirety of the document using Command + A and Command + C
I created a new topic on Discourse, and pasted the content in using Command + V
The text was pasted into the composer. In addition, an “image” of the text was also uploaded.
PR created to prevent duplicate pasting if both image and text available in clipboard.
While copy paste from Word, Excel, etc., composer receives multiple inputs with data types like text/plain, text/html, text/rtf and file image/png from clipboard. (for the same copied content)
By default text/plain getting used. Instead if we use text/html by converting it to markdown then not only tables we can support more HTML tags while copy paste.
Else I can convert plain text to markdown table for now.
Only when both paste types are detected, then we should skip one of them,
the image one. We should not prioritize image pastes unless there is no
other way to do this.
As per Jeff’s advice I am doing it in other way. The images will be skipped if clipboard have file data.
The original example is excel and excel-clones. I can’t think of any reason, ever, that you would want a picture of a table of numbers rather than … an actual table of numbers.