![如果选定的文本包含网站网址和电子邮件地址,那么我想将所有网址和电子邮件地址转换为链接?](https://linux22.com/image/1228941/%E5%A6%82%E6%9E%9C%E9%80%89%E5%AE%9A%E7%9A%84%E6%96%87%E6%9C%AC%E5%8C%85%E5%90%AB%E7%BD%91%E7%AB%99%E7%BD%91%E5%9D%80%E5%92%8C%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6%E5%9C%B0%E5%9D%80%EF%BC%8C%E9%82%A3%E4%B9%88%E6%88%91%E6%83%B3%E5%B0%86%E6%89%80%E6%9C%89%E7%BD%91%E5%9D%80%E5%92%8C%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6%E5%9C%B0%E5%9D%80%E8%BD%AC%E6%8D%A2%E4%B8%BA%E9%93%BE%E6%8E%A5%EF%BC%9F.png)
例如
这
这些快捷方式都不是你在 Windows 中通过几次点击或使用第三方小应用程序无法实现的,但是http://JDContextMenu.com只需单击一下即可将它们捆绑到一个小菜单中。您可以复制完整的[电子邮件保护]到剪贴板
应该转换成这个
None of the shortcuts are things you couldn't do within Windows with a few extra clicks or with a small 3rd-party app, but <a href="http://JDContextMenu.com" title="Opens in a new window" target="_blank">http://JDContextMenu.com</a> bundles them together into a small menu with one-click ease. You can copy the full <a href="mailto:[email protected]">[email protected]</a> to the clipboard
我想将此功能与此脚本结合起来如何选择文本然后使用 html 标签进行转换?
答案1
此 AutoHotkey 脚本应该可以工作,识别 URL 和电子邮件地址。
ALT+p是定义的热键:
!p::
ClipSaved := ClipboardAll
Clipboard=
Send ^c
ClipWait, 2
clipcontent = %Clipboard%
; Regular Expressions from RegExLib.com
; First lets search for the URLs
clipcontent := RegExReplace(clipcontent, "Si)(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)?", "<a href=""$0"">$0</a>")
; And then for the email addresses
clipcontent := RegExReplace(clipcontent, "Si)[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))", "<a href=""mailto:$0"">$0</a>")
Clipboard = <p>%clipcontent%</p>
ClipWait, 2
Send ^v
Clipboard := ClipSaved
ClipWait, 2
ClipSaved=
return