rich text to clipboard

38 views
Skip to first unread message

Emiliano Heyns

unread,
Apr 25, 2021, 10:41:45 AM4/25/21
to zotero-dev

This should do it:

```
const content =  <HTML string with may include links>
const clipboard = Components.classes['@mozilla.org/widget/clipboard;1'].getService(Components.interfaces.nsIClipboard)
const transferable = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable)

const str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString)
str.data = content
transferable.addDataFlavor('text/html')
transferable.setTransferData('text/html', str, content.length * 2) // don't recall why the * 2 is there but it doesn't work without it.

// you can add RTF as mimetype text/richtext in a similar way, and yes, this is the wrong mimetype for RTF, but this is the only thing Firefox accepts

clipboard.setData(transferable, null, Components.interfaces.nsIClipboard.kGlobalClipboard)
```

Bjoern Hassler

unread,
Apr 25, 2021, 11:42:19 AM4/25/21
to zotero-dev
Thank you so much!
Björn

Reply all
Reply to author
Forward
0 new messages