Keep line breaks upon WinClip.SetHTML

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
techmon
Posts: 54
Joined: 16 May 2017, 13:30

Keep line breaks upon WinClip.SetHTML

Post by techmon » 01 Dec 2021, 12:08

Hi,

I'm using WinClip https://www.autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/ to format some text (change font color to blue) from the Clipboard upon pressing Ctrl + j. The text in the Clipboard has line breaks.

but when I use this code, it pastes without line breaks.

Code: Select all

#Include WinClipAPI.ahk
#Include WinClip.ahk
wc := new WinClip

^j::
html:="<font color='blue'>" . Clipboard . "</font></div>"
WinClip.SetHTML(html)
WinClip.Paste()
Return
[Mod edit: [code][/code] tags added.]

How can I make it keep the line breaks? :-)

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Keep line breaks upon WinClip.SetHTML

Post by mikeyww » 01 Dec 2021, 12:34

SetHTML puts data onto the clipboard in HTML format. What is on your clipboard?


techmon
Posts: 54
Joined: 16 May 2017, 13:30

Re: Keep line breaks upon WinClip.SetHTML

Post by techmon » 07 Dec 2021, 14:56

Thanks Mikey,
mikeyww wrote:
01 Dec 2021, 12:34
SetHTML puts data onto the clipboard in HTML format. What is on your clipboard?
I think it's usually html format that is on my clipboard.
Also, thanks Xtra for your suggestion. I don't think I'm fully understanding though. Can you elaborate on that?

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Keep line breaks upon WinClip.SetHTML

Post by Xtra » 07 Dec 2021, 14:59

You want to StrReplace() the linebreaks `n or `r`n with <br>
Example:

Code: Select all

Clipboard := StrReplace(Clipboard, "`n", "<br>")

techmon
Posts: 54
Joined: 16 May 2017, 13:30

Re: Keep line breaks upon WinClip.SetHTML

Post by techmon » 07 Dec 2021, 16:48

Thanks so much Xtra, that did the trick! :D

Post Reply

Return to “Ask for Help (v1)”