python - Modifying a clipboard content to be treated as HTML -
when “copy image” on web (by highlighting image , ctrl+c) , passed text view of html wysiwyg editor (not source code editor) picture displayed. though paste in text editor ( source code editor), content of clipboard understood editor html code.
for example, if paste “<img src="someurl" />
in text editor, added in source code “<p><img src="someurl" /></p>”
clipboard isn’t understood editor html code.
so how should modify content of clipboard html wysiwyg editor understand html code though pasting in text view (not source code editor)?
what want in more details:
when have url of image stored in clipboard, want able add image html wysiwyg editor without having switch source code editor. transform content of clipboard (by adding code before , after url) understood html code (just example mentioned above) html wysiwyg editor.
edit: better target answer here try achieve. when use sharex upload picture, sharex store automatically (private) shareable url in clipboard. https://drive.google.com/open?id=xxxx code convert in embedded format. i'm still looking way store html format.
#url_to_picture.py # #(xxx=fileid) # #you need kind of url able embed picture in editor: https://drive.google.com/uc?export=view&id=xxxx # #this script part of job converting google drive url embedded (and permanent) link: jaraco import clipboard urlsharex = clipboard.paste_text() urlsharex=urlsharex.replace("https://drive.google.com/file/d/", "") urlsharex=urlsharex.replace("/view?usp=drivesdk", "") urlsharex=urlsharex.replace("/view?usp=sharing", "") urlsharex=urlsharex.replace("https://drive.google.com/open?id=", "") url= '<img src="https://drive.google.com/uc?export=view&id={}" />'.format(urlsharex) clipboard.copy_html(url)
to try on sharex:
- you must set access google drive in sharex menu: destination/destination settings/google drive.
- you must set sharex menu: “after upload task” “copy url clipboard”
you can this:
- install htmlclipboard : copy script, save
htmlclipboard.py
in c:\python##\lib\site-packages\ - save script below
image_link_as_html.py
(i used of code in question): - create shorcut script in step (right click on file
image_link_as_html.py
, , select create shorcut) - right click on shorcut, select
properties
, , and add keyboard shorcut in shorcut key.
that's it. when have image url in our clipboard, can press keyboard shorcut , can paste image directly in html mode of editor.
image_link_as_html.py (python34):
from tkinter import tk root = tk() root.withdraw() image_url = root.clipboard_get() # send <img src="https://image_url" alt="" /> "html format clipboard" import htmlclipboard htmlclipboard.puthtml("<img src=\"http://"+image_url+" \" alt=\"\"/>")
to address part sharex, use scrip instead:
from tkinter import tk root = tk() root.withdraw() urlsharex = root.clipboard_get() # remove except file google id: part not needed urlsharex=urlsharex.replace("https://drive.google.com/file/d/", "") urlsharex=urlsharex.replace("/view?usp=drivesdk", "") urlsharex=urlsharex.replace("/view?usp=sharing", "") urlsharex=urlsharex.replace("https://drive.google.com/open?id=", "") urlsharex=urlsharex.replace("/view", "") # send <img src="https://drive.google.com/uc?export=view&id=xxx " alt="" /> "html format clipboard" import htmlclipboard htmlclipboard.puthtml("<img src=\"https://drive.google.com/uc?export=view&id="+urlsharex+" \" alt=\"\"/>")
Comments
Post a Comment