my link in the clipboard to be able to past it in HTML mode (and not source code) in an HT" /> my link in the clipboard to be able to past it in HTML mode (and not source code) in an HT" /> my link in the clipboard to be able to past it in HTML mode (and not source code) in an HT"/>

Python3: storing a link recognized as HTML format in clipboard

645 Views Asked by At

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

2

There are 2 best solutions below

0
MagTun On

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>")
0
phispi On

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