Wednesday, May 1, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 1054  / 1 Year ago, sat, march 25, 2023, 4:41:35

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).


More From » desktop-environments

 Answers
6

Found it! Here's how to get at the HTML source when there's some on your clipboard:


#!/usr/bin/env python
import gtk
print (gtk.Clipboard().wait_for_contents('text/html')).data

This helped.


This didn't work for me. My callback was never entered.


[#26756] Saturday, March 25, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tionavocad

Total Points: 189
Total Questions: 101
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
2 Years ago
tionavocad questions
Tue, May 23, 23, 00:07, 1 Year ago
Tue, Jan 17, 23, 20:38, 1 Year ago
Sun, Oct 10, 21, 04:50, 3 Years ago
Tue, Jun 7, 22, 08:50, 2 Years ago
;