klembord
klembord copied to clipboard
Issue with Html and other targets/formats
I am using this old HTMLClibpboard script but I wanted to change for your package but I didn't succeed in making it work.
When I use this
import klembord
klembord.set_with_rich_text('plain text', '<b><a href="www.google.com">plain text</a></b>')
and then paste in some HTML editor (like the one from zotero which use TinyMCE) then it's the plain text that is sent and not HTML. (I tried on Zotero on two different computers.)
I also tried this
content = {'UTF8_STRING': 'some text'.encode(), 'text/html': '<s>string</s>'.encode()}
klembord.set(content)
but then the clipboard is empty: nothing happens when I paste and
Windows 10, python 3.6
I had a similar issue. It turns out the size calculations around line 220 in winclipboard.py are incorrect for EndHtml, StartFragment, and EndFragment, because html_header_size already includes the description_size. The code as it is now makes the EndHtml, StartFragment, and EndFragment values too big. Removing description_size+
from lines 220, 221, and 222 make it work OK.
It was a little challenging to debug because it looks like Excel and other programs are more forgiving of invalid values so it appeared to be an issue with Word in my case.
Thanks for your help @johnsdouglass !
I have remove the three description_size+
from lines 220, 221, and 222
- When I run
import klembord
klembord.set_with_rich_text('plain text', '<b>plain text</b>')
Then I have this error:
File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\klembord\winclipboard.py", line 225, in wrap_html
*[str(x).zfill(8) for x in sizes]
IndexError: tuple index out of range
- After that I tried with
import klembord
content = {'UTF8_STRING': 'some text'.encode(), 'text/html': '<s>string</s>'.encode()}
klembord.set(content)
Now I don't get any error but nothing is paste.
Hmm. I just tried your example and it works fine for me.
Can you verify that lines 218-233 look like this:
sizes = (
description_size, # StartHtml
html_header_size+fragment_size+html_footer_size, # EndHtml
html_header_size, # StartFragment
html_header_size+fragment_size, # EndFragment
)
Sorry I misunderstood your post. I corrected it and now the klembord.set_with_rich_text
is working and I get html on all the programs I tested so that's really great!
But still nothing with the klembord.set(content)
.
At least there is a way to make it work, so thanks a lot for help!