EDIT: Might as well add support for ahk code blocks too...
EDIT 3: The chr(93) allows us to share the below code block, but also will paste the tag appropriately. Cool tip Andy!
Code: Select all
;===============================================================================
; https://www.autohotkey.com/boards/viewtopic.php?f=83&t=129926
; Put url on clipboard, then select some text and press key to embed link in text.
; If code block, imgur, or username, just put on clipboard, then press key.
#HotIf WinActive("AutoHotkey Community")
^k::
{ If InStr(A_Clipboard, "#Requires AutoHotkey") || InStr(A_Clipboard, "::")
{ A_Clipboard := "[Codebox=autohotkey file=Untitled.ahk]" A_Clipboard "[/Codebox" chr(93)
}
Else If InStr(A_Clipboard, "imgur") || InStr(A_Clipboard, "screencast") || InStr(A_Clipboard, "prnt")
{ A_Clipboard := "[Img]" A_Clipboard "[/Img]"
}
Else If RegExMatch(A_Clipboard, "^(https?://|www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$")
{ holdClip := A_Clipboard
A_Clipboard := ''
Send "^c"
Sleep 100
A_Clipboard := "[url=" holdClip "]" A_Clipboard "[/url]"
}
Else
{ A_Clipboard := "[mention]" A_Clipboard "[/mention]"
}
Send "^v"
}
#HotIf
-Uses hotkey Ctrl+K, which is the one that MS Office apps use to insert a link.
-Hotkey is only active in AHK Forums.
-First, select
* a block of AHK code
* an imgur url
* a URL that is not imgur
* or a username
-Press Ctrl+C to copy to clipboard.
-Click in your forum post (that you are writing/editing)
-If it's a code block, an imgur URL, or a username, just press Ctrl+K
-If it's a non-imgur URL, then first select the text in your post that you want to embed the hyperlink in, and press Ctrl+K.