HTML 代码的纯文本 URL(Automator/AppleScript) [英] plain text URL to HTML code (Automator/AppleScript)

查看:29
本文介绍了HTML 代码的纯文本 URL(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://开头的行都转换成URL的HTML代码,这样上面的内容就变成了:

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 代码的纯文本 URL(Automator/AppleScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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