How to Paste HTML

32 views
Skip to first unread message

Dennis Bareis

unread,
Apr 20, 2021, 8:48:37 PM4/20/21
to CopyQ
Hi,

I can't work out how to past some HTML (<b>Some bold test for starters<b>) to a control that accepts HTML text.

Some examples below (I commented out all but 1 attempt at a time), am I expected to add "<html><body><!--StartFragment-->" at the start  (and bit on end) as COPYQ does when it captures?  I'd have thought if that was required copyq would do so....


     var html    = "<b>Some bold test for starters<b>"
     MyLog("HTML: " + HTML)   //Passed sanity check, is properly formatted HTML...

     copy(mimeHtml, html)     //FAILED ATTEMPT 1 (as per example in doco)

     copy("text/html", html)  //FAILED ATTEMPT 2  

     //FAILED ATTEMPT 3  (as per example in doco)
     var item = {}
        item[mimeText] = 'Some Text'
        item[mimeHtml] = html
     copy(item)               //paste() pastes "[object Object]"

     //ATTEMPT 4  - TEXT ONLY
    copy(html)               //Works but as text not HTML mimetype

    paste()

Dennis Bareis

unread,
Apr 20, 2021, 9:32:13 PM4/20/21
to CopyQ
OOPS: DIDN'T MATTER but HTML was not correct should have been:  var html    = "<b>Some bold text for starters</b>"

Nothing is logged to "copyq.log" when it doesn't work.

Lukáš Holeček

unread,
Apr 22, 2021, 12:06:55 PM4/22/21
to Dennis Bareis, CopyQ
Which version of CopyQ are you using?

Tested from terminal:

❯ copyq 'copy({"text/html": "<b>BOLD</b>"})'  
❯ copyq clipboard "?"                      
text/html
application/x-copyq-owner
❯ copyq clipboard "text/html"
<b>BOLD</b>

Calling `copy(mimeHtml, html)` should also work. Maybe the target application requires also plain text to be set or does not see the changed clipboard yet.
--
You received this message because you are subscribed to the Google Groups "CopyQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to copyq+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/copyq/907a92a3-680c-4e36-a6ae-7fff55ea83f2n%40googlegroups.com.

Dennis Bareis

unread,
Apr 22, 2021, 7:29:17 PM4/22/21
to Lukáš Holeček, CopyQ
Hi,

I don't know what you mean by a "terminal" but if that is the same as a Windows command prompt (shell: cmd.exe) then that doesn't work there. I was originally on the most recent v3 qcopy release but am now on v4.0.0.

I just tried this to set text (but one of my original failed attempts should also did this):

var html = "<b>some bold text</b>"

copy(mimeHtml, html) //as HTML

copy(mimeText, html) //as TEXT

paste()


That doesn't change what is copied in (whatever was on the clipboard before the above code executed). 

RE: "does not see the changed clipboard yet"
Is this a common issue? What to do about it?

When I use copy(), it never shows up as a capture in the copyq interface, should it?  If not then can I add it for diagnostic purposes?  Also you have the "SHIFT-CONTROL-C" diagnostic on items in your interface to show the mime types, is there a way to do the same sort of sanity check on what is in the clipboard?

---
Thanks
Dennis
cloudHQPowered by
cloudHQ

Lukáš Holeček

unread,
Apr 23, 2021, 12:16:43 AM4/23/21
to Dennis Bareis, CopyQ
Calling `copy(mimeText, text)` replaces all data in clipboard and removes any "text/html". The command should be:

copyq(
    mimeHtml, html,
    mimeText, text
)

Also, anything copied withing CopyQ (item list or scripting) won't trigger automatic commands and won't store the copied content.

To fix the pasting to other apps, you can try changing some intervals:

copyq config window_wait_for_modifiers_released_ms 2000
copyq config window_wait_after_raised_ms 500


The second line would wait 500 milliseconds before sending a shortcut to paste.

To show data formats currently in clipboard:

popup('Clipboard', clipboard('?'))

Lukas

Dennis Bareis

unread,
Apr 23, 2021, 3:02:31 AM4/23/21
to CopyQ
Hi,

The two settings haven't changed anything (I did check copyq.ini and can see the changes there).  Does that mean that I don't need to restart CopyQ to test the changes done this way (either way, made no diff)?

What did make a difference was reversing the order to: copy(mimeText, html, mimeHtml, html)
Is the order of mime types significant, the best format first?  If so your copy() seems to reverse them?

The "popup" function (on Windows at least) is useless in version 4, they quickly timeout before disappearing from the notification UI and only display a small amount of data and don't do anything such as displaying the rest when clicked, and no buttons to perform actions?  Is there a setting to get the blue boxes back?

Thanks
Dennis

Lukáš Holeček

unread,
Apr 23, 2021, 3:50:08 AM4/23/21
to Dennis Bareis, CopyQ
On Fri, Apr 23, 2021 at 9:02 AM Dennis Bareis <dba...@gmail.com> wrote:
Hi,

The two settings haven't changed anything (I did check copyq.ini and can see the changes there).  Does that mean that I don't need to restart CopyQ to test the changes done this way (either way, made no diff)?

This is strange, the options should be definitely stored in the configuration; restart is not needed.
 

What did make a difference was reversing the order to: copy(mimeText, html, mimeHtml, html)
Is the order of mime types significant, the best format first?  If so your copy() seems to reverse them?

Order does not matter.


The "popup" function (on Windows at least) is useless in version 4, they quickly timeout before disappearing from the notification UI and only display a small amount of data and don't do anything such as displaying the rest when clicked, and no buttons to perform actions?  Is there a setting to get the blue boxes back?

Dennis Bareis

unread,
Apr 23, 2021, 4:08:08 AM4/23/21
to Lukáš Holeček, CopyQ
HI,

I was just just asking if I needed a restart (for future).

Anyway I tried after restart anyway, after working the one time it is now failing again. I will try to increase the values you gave me :-(

Any chance you can put the option into prod (is that what you are doing) or fix Windows Notifications.  I will use dev forever if I have to.

---
Thanks
Dennis
cloudHQPowered by
cloudHQ

Lukáš Holeček

unread,
Apr 23, 2021, 6:27:12 AM4/23/21
to Dennis Bareis, CopyQ
On Fri, Apr 23, 2021 at 10:08 AM Dennis Bareis <dba...@gmail.com> wrote:
HI,

I was just just asking if I needed a restart (for future).

Anyway I tried after restart anyway, after working the one time it is now failing again. I will try to increase the values you gave me :-(

Any chance you can put the option into prod (is that what you are doing) or fix Windows Notifications.  I will use dev forever if I have to.

The option will be in the next CopyQ release.

Dennis Bareis

unread,
Apr 23, 2021, 5:45:16 PM4/23/21
to CopyQ
Hi,

Doubling the values on the 2 timeouts you mentioned as follows recently didn't change anything:
copyq config window_wait_for_modifiers_released_ms 4000
copyq config window_wait_after_raised_ms 1000


Going back and retrying (cmd.exe):
copyq 'copy({"text/html": "<b>BOLD</b>"}
then
copyq clipboard "text/html"
shows nothing (I still suspect the command line doesn't work) and in any case pasting does paste BOLD.

My code (pastes the text):

copy(mimeHtml, html, mimeText, text)
  //copy(mimeText, html, mimeHtml, HTML)
  //copy(mimeHtml, HTML)
  //copy(mimeText, text, mimeHtml, HTML)
MyDebugLogClipboard('AFTER COPY')

paste()
MyDebugLogClipboard('AFTER PASTE')

Pastes (some plain text :-() and logs:
DB$: CLIPBOARD[AFTER COPY]:
   text/html
   text/plain
   application/x-copyq-owner
   
   * text/plain: some plain text :-(
   * text/html: <b><i>some bold italic text</i></b>
DB$: CLIPBOARD[AFTER PASTE]:
   text/html
   text/plain
   application/x-copyq-owner
   
   * text/plain: some plain text :-(
   * text/html: <b><i>some bold italic text</i></b>

Any other ideas or debug tips?

Is there any option/way to make the prefix of these log lines different or shorter?

Dennis Bareis

unread,
Apr 24, 2021, 12:18:29 AM4/24/21
to CopyQ
Hi,

I think I've proven this is a copyq bug of some type.  

I decided to save the HTML in a TAB and manually copy and paste it, this failed
  1. I end up with 2 things saved in the tab, my HTML displaying correctly (without a HTML mimetype) plus a 2nd entry "Opening in existing browser session.".
  2. Nothing gets pasted (not even the "Opening in existing browser session." text)


Please see the picture.

Html not saved correctly.png

Dennis Bareis

unread,
Apr 25, 2021, 4:12:51 AM4/25/21
to CopyQ
Hi,

I can't see the message I got on email here so I'm not sure what is going on but...

Re: Logs; yes "copyq.log", I don't use the viewer because it's not very useful particularly without a clear option, I delete the file then do something and view in notepad.

The clipboard data when it works inspected with SHIFT+CTRL+C (which is what I assume you mean), is as per a previous post/picture with just "text/plain" & " text/html" (with the fragment text that I now assume I don't need).   

You don't think the feature/bug in my previous message is related? In any case looking at "text/plain" & " text/html" in that HTML fragment I saved both the mime types basically only contain the literal text "text/plain"!

Thanks
Dennis

Dennis Bareis

unread,
Apr 25, 2021, 4:15:26 AM4/25/21
to CopyQ
Sorry forgot to add these images of the "text/plain"  literal text:

HTML But COPYQ is broken 1.pngHTML But COPYQ is broken 2.png

Lukáš Holeček

unread,
Apr 27, 2021, 12:23:41 AM4/27/21
to Dennis Bareis, CopyQ
On Fri, Apr 23, 2021 at 11:45 PM Dennis Bareis <dba...@gmail.com> wrote:
Hi,

Doubling the values on the 2 timeouts you mentioned as follows recently didn't change anything:
copyq config window_wait_for_modifiers_released_ms 4000
copyq config window_wait_after_raised_ms 1000


Going back and retrying (cmd.exe):
copyq 'copy({"text/html": "<b>BOLD</b>"}
then
copyq clipboard "text/html"
shows nothing (I still suspect the command line doesn't work) and in any case pasting does paste BOLD.

I think the console output on Windows is still broken so the second command won't print anything there.


Or use popups: copyq 'popup(clipboard("text/html"))'


My code (pastes the text):

copy(mimeHtml, html, mimeText, text)
  //copy(mimeText, html, mimeHtml, HTML)
  //copy(mimeHtml, HTML)
  //copy(mimeText, text, mimeHtml, HTML)
MyDebugLogClipboard('AFTER COPY')

paste()
MyDebugLogClipboard('AFTER PASTE')

Pastes (some plain text :-() and logs:
DB$: CLIPBOARD[AFTER COPY]:
   text/html
   text/plain
   application/x-copyq-owner
   
   * text/plain: some plain text :-(
   * text/html: <b><i>some bold italic text</i></b>
DB$: CLIPBOARD[AFTER PASTE]:
   text/html
   text/plain
   application/x-copyq-owner
   
   * text/plain: some plain text :-(
   * text/html: <b><i>some bold italic text</i></b>

Any other ideas or debug tips?

Try inspecting the clipboard data when pasting HTML works (copy from some other app). Maybe the target app expects slightly different format then "text/html".
 

Is there any option/way to make the prefix of these log lines different or shorter?

I don't know which log lines you mean. In the Log dialog in CopyQ?
 

Dennis Bareis

unread,
May 22, 2021, 7:48:34 PM5/22/21
to CopyQ
Hi,

I have worked out the answer, I should have tried this earlier as I did ask a very similar question originally, oh well.

For the app, the HTML needs to be complete and not just a fragment, for example I added this and it now works (I haven't tried minimising this to see the least that is required):

html = '<html><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"></head><body>' + html + '</body></html>'

Is there an online web page that makes a good testbed for future similar questions?  That was everyone is on the same page...

I also got confused somewhere along the line that SHIFT+CTRL+C showed the information about the highlighted entry and not the clipboard data...

Thanks
Dennis

Lukáš Holeček

unread,
May 23, 2021, 1:30:41 AM5/23/21
to Dennis Bareis, CopyQ
It depends on the target application what clipboard formats and data it accepts.

Usually to debug these problems, I would copy something from from the target app and check clipboard content (Shift+Ctrl+C, or commands `copyq clipboard "?"`, `copyq clipboard text/html`) and then check what is in the item in CopyQ (F4, or commands `copyq read "?" 0`, `copyq read "text/html" 0`).

BTW, it might be easier to follow the discussion on github, either on a separate issue (https://github.com/hluk/CopyQ/issues) or in Discussions section (https://github.com/hluk/CopyQ/discussions).

Lukas


Reply all
Reply to author
Forward
0 new messages