纯文本网址为HTML code(的Automator /的AppleScript) [英] plain text URL to HTML code (Automator/AppleScript)

查看:221
本文介绍了纯文本网址为HTML code(的Automator /的AppleScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个文本编辑器(如TextEdit)一个普通的txt文件:

Suppose I have a plain txt file in a text editor such as Text

title 1
http://a.b/c

title 2
http://d.e/f

...

我想以http开头的所有行转换://为HTML code的URL,因此,上述内容将变为:

I'd like to convert all the lines beginning with http:// to HTML code for URL, so that the aforementioned content will become:

title 1
<a href="http://a.b/c">http://a.b/c</a>

title 2
<a href="http://d.e/f">http://d.e/f</a>

...

我怎样才能在这样的Automator或AppleScript的呢? (我现在的解决方案是使用Gmail,但它涉及多步骤的复制粘贴)。

How can I get this done in Automator or AppleScript? (My current solution is using Gmail, but it involves multi-step copy-paste.)

非常感谢你在前进。

推荐答案

这将让你避免再次编辑:

This will let you avoid another editor:

set inFile to "/Users/you/Desktop/Urls.txt"
set outFile to "/Users/you/Desktop/Urls2.txt"

do shell script "sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g' " & quoted form of inFile & " >" & quoted form of outFile

这篇关于纯文本网址为HTML code(的Automator /的AppleScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆