0

I am working on parsing clipboard data in a web app to paste into various formats. In order to correctly determine how to parse the data, I need to see exactly what is in the clipboard. My current best approach is pasting into vim with set list and various characters to look at whitespace, however this is still missing some information.

In this example I two excel tables, where one has a merged cell in the middle. excel

Both of these copy the same data into the clipboard (according to pasting into (vim symbols represent whitespace))

enter image description here

Yet when pasting into google sheets it knows to preserve the merged cell (similar to my use case). What is this magic?

Justin Olson
  • 126
  • 2
  • 13
  • 1
    The answer is that the clipboard holds more than one kind of data at a time, and what comes out depends on where you paste it. The exact mechanism (and how to view that data directly) will depend a lot on what flavor of unix and window manager you're using. – Jordan Running Jun 06 '18 at 19:08
  • Presumably this needs to work on all OSes (mainly windows) if this is a web app? – kabanus Jun 06 '18 at 19:12
  • For example using Javascript on a Windows machine: https://stackoverflow.com/questions/6413036/get-current-clipboard-content/6413100#6413100 - so you can check exactly what you get. – kabanus Jun 06 '18 at 19:14

1 Answers1

0

The answer is that the clipboard holds more than one kind of data at a time

Jordan Running was absolutely correct here, I was only seeing one data type of the clipboard, and different types were being requesting in different places. Per https://www.w3.org/TR/clipboard-apis/#reading-from-clipboard there are many different types.

  • text/plain
  • text/uri-list
  • text/csv
  • text/css
  • text/html
  • application/xhtml+xml
  • image/png
  • image/jpg, image/jpeg
  • image/gif
  • image/svg+xml
  • application/xml, text/xml
  • application/javascript
  • application/json
  • application/octet-stream

In my case when pasting into Vim I was only seeing text/plain. While the plain text strings were exactly the same TSV data from excel, The data contained in text/html is how google sheets knows about the merged cell.

Justin Olson
  • 126
  • 2
  • 13