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