2

How can to store this link <a href="http://www.web.com">my link</a> in the clipboard to be able to past it in HTML mode (and not source code) in an HTML editor? Pasting it in an editor should only show the text my link with a clickable link.

Using Tkinter or pywin32 (or others), how to tell the clipboard that it contain html content (and not just raw text)?

JinSnow
  • 1,553
  • 4
  • 27
  • 49
  • 1
    I can't help with your specific case, but I think you are looking for storing "rich text" in the clipboard, e.g. http://stackoverflow.com/questions/17298897/how-can-i-copy-from-an-html-file-to-the-clipboard-in-python-in-formatted-text – chrki Nov 23 '16 at 20:12
  • The code.activestate.com link looks very interesting. But apparently it's a python 2. I will try to see what I can do with that. Someone already manage to make it work in python 3, I'll try. – JinSnow Nov 23 '16 at 20:25

2 Answers2

0

Based on the link suggested by @chrki.

You can do this:

  1. Install HtmlClipboard : copy the script, save it as HtmlClipboard.py in C:\Python##\Lib\site-packages\
  2. Save the script below as link_as_html.py(I used some of your code in your question):
  3. Create a shorcut for the script in step to (right click on the file link_as_html.py, and select create a shorcut)
  4. Right click on the shorcut, select Properties, and and add a keyboard shorcut in Shorcut key.

That's it. When you have an link in our clipboard, you can just press your keyboard shorcut and you can paste your image directly in the html mode of you editor.


link_as_html.py (Python34). I assume you have your url http://www.web.com in the clipboard:

from tkinter import Tk
root = Tk()
root.withdraw()
url = root.clipboard_get()

# send <a href="http://www.web.com" target="_blank">my link</a>  to an "HTML format clipboard"
import HtmlClipboard
HtmlClipboard.PutHtml("<a href=\"http://"+url+" \" target=\"_blank\"/>my link</a>")
MagTun
  • 5,619
  • 5
  • 63
  • 104
0

The Python package klembord supports formatted text:

import klembord  # pip install klembord
klembord.init()
klembord.set_with_rich_text('http://www.web.com', '<a href="http://www.web.com">my link</a>')
phispi
  • 604
  • 7
  • 15