If I cut some HTML from a Pidgin instant messenger window, I can easily paste it verbatim into a new HTML email in Thunderbird. All formatting (fonts, colors, etc) are preserved, so it appears that my Ubuntu 13.10 desktop clipboard must have the HTML source somewhere.
But I'd like to tweak the HTML source.
How can I actually get at the HTML source when it is in the clipboard? I'd like to just throw it into a text file, work on the markup in Vim or whatever, then use this HTML source in a webpage or feed it to Thunderbird's "Insert → HTML".
Hmm, maybe something like PasteImg (mentioned in Getting a graphic on the clipboard to the disk?), but using request_rich_text()
instead of request_image()
? I wouldn't mind using a small Python script the rare times I want to get HTML source from the clipboard.
What's in the clipboard may actually be "rich text".
The Python script from this answer outputs
Current clipboard offers formats: ('TIMESTAMP', 'TARGETS', 'MULTIPLE',
'SAVE_TARGETS', 'COMPOUND_TEXT', 'STRING', 'TEXT', 'UTF8_STRING', 'text/html',
'text/plain')
Turns out my Pidgin logs are in HTML, so that's one way to get at this HTML source, bypassing the clipboard entirely. I'm still interested in the answer to the original question (how to retrieve HTML from the clipboard).
Found it! Here's how to get at the HTML source when there's some on your clipboard:
This helped.
This didn't work for me. My callback was never entered.
I see what you're trying to get at. Try pasting into something that takes wysiwyg, edit it there, then copy paste into Thunderbird?
Maybe bluegriffon or libreoffice writer will work.
Here's a modification of your script, which actually allows editing the html directly.
It also handles problems with character encoding: if you reply to an e-mail from someone using Windows, chances are the encoding is stuck in UTF-16, which is no good for editing. You may need to install the
chardet
module in Python.Replace
'vi'
with your text editor of choice, insubprocess.call(...
.This does a full edit cycle, modifying the clipboard “in place”.
I use it to make up for Thunderbird's annoying lack of a html-editor feature:
I don't really use Thunderbird, but you should be able to use an extension to help edit the source in Thnderbird - e.g:
https://addons.mozilla.org/en-us/thunderbird/addon/edit-html-source/ not been updated for ages
https://addons.mozilla.org/en-us/thunderbird/addon/stationery/
There is an answer at which directly uses the
xclip
utility:I find it the easiest and most reliable now, since GTK3/Python3 seems to have introduced some changes that broke the original answer.
To get the HTML source code of the "rich text":
You have several TARGETs, like text/plain (default) to get just the rendered text.
I manipulate the plain/text content of the clipboard using
xsel
:Pretty useful to for e.g. change a list to a TOP n cases, with
sort | uniq -c | sort -rn | head -20
.In your case change the first
xsel -b
with the abovexclip
command.