Last active
April 14, 2020 06:46
-
-
Save db93n2/b85e1470d2dd886053ef3415e7198508 to your computer and use it in GitHub Desktop.
(autohotkey) - generate a html/markdown/bbcode link from the clipboard or selected text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^![::linker("markdown") | |
^!,::linker("html") | |
^!/::linker("bbcode") | |
linker(link_type) { | |
revert_clipboard := clipboardAll | |
1st_clipboard := trim(clipboard) | |
clipboard := "" | |
send ^{c} | |
clipwait, 0.3 | |
2nd_clipboard := trim(clipboard) | |
if regExMatch(1st_clipboard, "^(https?://|www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$") | |
link := 1st_clipboard ; clipboard is url | |
else link := "link" | |
if 2nd_clipboard is space ; (if empty, space, tab or linefeed) | |
text := "text" | |
else text := 2nd_clipboard ; text was highlighted | |
if (link_type = "markdown") | |
clipboard = [%text%](%link%) ; [text](link) | |
else if (link_type = "html") | |
clipboard = <a href="%link%">%text%</a> ; <a href="link">text</a> | |
else if (link_type = "bbcode") | |
clipboard = [url=%link%]%text%[/url] ; [url=link]text[/url] | |
send ^{v} | |
if (text = "text") ; if text wasnt highlighted, add a space at the end | |
send % a_space "{left}" | |
if (text = "text") ; move caret to "link" or "text" and highlight it | |
word := "text" | |
else if (link = "link") | |
word := "link" | |
strReplace(clipboard, word, , count) | |
if (word != "") and (count < 2) | |
{ | |
sleep 200 | |
stringGetPos, pos, clipboard, % word | |
send % "{left " (strLen(clipboard) - pos) "}+{right " strLen(word) "}" | |
} | |
sleep 100 | |
clipboard := revert_clipboard | |
} | |
/* | |
[script info] | |
version = 2.1 | |
description = generate a html/markdown/bbcode link from the clipboard or selected text | |
author = davebrny | |
source = https://gist.github.com/davebrny/b85e1470d2dd886053ef3415e7198508 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
markdown: ctrl alt + [
html: ctrl alt + ,
bbcode: ctrl alt + /
if a word is selected then "text" will be replaced with that word
if a url is in the clipboard then "link" will be replaced with the url