Clipboard formating Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arkay38
Posts: 18
Joined: 25 Mar 2017, 11:06

Clipboard formating

Post by arkay38 » 24 Aug 2017, 13:48

Hi :)

I tried to play with the clipboard functions and StringReplace but cound't managed to achieve what I aimed...

I would like to format saved-to-clipboard text like this:
1) embed every paragraph with "<p> ... </p>"
2) replace every end of line by "<br>" + new line (except empty lines)

Example
I copy to clipboard :

Code: Select all

Aaa
Bbb
Ccc

Ddd
Eee
Fff
I perform the AHK script and it pastes:

Code: Select all

<p>Aaa<br>
Bbb<br>
Ccc</p>

<p>Ddd<br>
Eee<br>
Fff</p>

Can someone help me please ? The only thing I can do for now is embed a selection with <p></p> or add <br> to a selection.

Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Clipboard formating  Topic is solved

Post by Nightwolf85 » 24 Aug 2017, 14:05

Press Ctrl+Shift+c to get your desired copy:

Code: Select all

^+c::
	clipboard := ""
	Send, ^c
	ClipWait, 1
	IF (ErrorLevel)
		Return
	temp := clipboard
	temp := StrReplace(temp, "`r`n", "<br>`r`n")
	temp := StrReplace(temp, "<br>`r`n<br>`r`n", "</p>`r`n`r`n<p>")
	clipboard := "<p>" . temp . "</p>"
Return
Only tested with your sample text. Let me know if it works the way you want.

arkay38
Posts: 18
Joined: 25 Mar 2017, 11:06

Re: Clipboard formating

Post by arkay38 » 24 Aug 2017, 14:36

Wow you were so fast, and it works as intended, you're a genius!
Thanks, it will save me some time :)

Post Reply

Return to “Ask for Help (v1)”