7

I want to copy+paste HTML from a mail in Thunderbird to a text editor.

It works to copy+paste it to LibreOffice, but I want to see the "raw" HTML.

If I use Gedit, then I only get pure text ...

Any hint?

Update: I want to get the HTML from the clipboard

I have other use cases where the source application is not Thunderbird.

6 Answers 6

5

You can do it with Python!

From How can I edit the source of HTML in the clipboard? ...

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

(just save that in a file called, say, clip.py, then execute python clip.py in the Terminal application)

See also: https://stackoverflow.com/questions/2346924/dump-x-clipboard-data-with-gtk-or-pygtk

3
  • If it is an email you received which you would like to see its HTML source:

    • View → Message Source
    • Press Ctrl+U
  • If it is an email you are currently writing which you would like to see its HTML source:

    • Edit → Select All, then click the Insert → HTML menu option on your message window.

More info

1
  • thank you for this answer. My question was about getting the HTML from the clipboard. You answer solves this particular use case. But maybe there are other use cases where the source is not thunderbird. Can you understand this comment? If not please tell me.
    – guettli
    Jun 2, 2017 at 8:33
2

Yaron's answer is totally correct. There is another option, too:

  1. Once you have selected the message, either

    • go to File > Save as > File, or
    • press Ctrl+S.
  2. Then in the drop down at the bottom right, select "HTML files" and change the file name to match.

  3. Then select a location to save the message locally and, voilà, you have the HTML stored locally.

1

The answers that are already there stand for what your question appeared to be, and that will still work for Firefox, but in view of your edit, I'll give you what I know.

To my knowledge there is no tool in Ubuntu that will allow you to take copied formatted text and convert to plain HTML. However, there are online tools like this one from wordtohtml.net that will allow you to do this.

Essentially, you'll have to copy your text, then paste it to the left text input box, then you can copy out the html rendering of it from the box on the right.

Hope it helps!

1
xclip -selection clipboard -t text/html -o # Source of HTML on clipboard

You can change it and send it back also with pipes and xclip or xsel.

1

You can also:

  • Copy from the formatted source.
  • Run this command to extract from the clipboard, convert to HTML, and then (with a pipe |) put that HTML back in the clipboard, again using the same xclip:
xclip -selection clipboard -o -t text/html | xclip -selection clipboard
  • Next, when you paste with Ctrl+v, it will paste the HTML source.

Going further, you can make it a shortcut, so that you don't have to open the terminal and run the exact command each time. ✨

To do that:

  • Open the settings for your OS (in my case it's Ubuntu)
  • Find the section for the Keyboard
  • Then find the section for shortcuts
  • Create a new shortcut
  • Set a Name, e.g.: Copy as HTML
  • Then as the command for the shortcut, put:
bash -c "xclip -selection clipboard -o -t text/html | xclip -selection clipboard"

Note: notice that it's the same command as above, but put inside of an inline Bash script. This is necessary to be able to use the | (pipe) to send the output from one command as input to the next.

  • Set the shortcut to whatever combination you want, preferably not overwriting another shortcut you use. In my case, I set it to: Ctrl+Shift+c

  • After this, you can copy some formatted text as normally with: Ctrl+c
  • And then, before pasting it, convert it to HTML with: Ctrl+Shift+c
  • Next, when you paste it with: Ctrl+v, it will paste the contents as HTML. 🧙✨

Note: cross-posted from: https://stackoverflow.com/a/65540366/219530 , but it's also relevant here. 🤷

Shortcut edition window

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .