Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Html and other targets/formats #13

Open
MagTun opened this issue Apr 13, 2021 · 4 comments
Open

Issue with Html and other targets/formats #13

MagTun opened this issue Apr 13, 2021 · 4 comments

Comments

@MagTun
Copy link

MagTun commented Apr 13, 2021

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

@johnsdouglass
Copy link

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.

@MagTun
Copy link
Author

MagTun commented May 5, 2021

Thanks for your help @johnsdouglass !
I have remove the three description_size+ from lines 220, 221, and 222

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

@johnsdouglass
Copy link

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
		)

@MagTun
Copy link
Author

MagTun commented May 6, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants