Applescript 使用 HTML 标签换行和 MarsEdit.app 脚本问题
我目前在 MarsEdit.app 中使用的脚本有一个缺陷。它检查 HTML 文档中是否有段落用
标记包裹的情况,如下所示:
-- If already starts with <p>, don't prepend another one
if not {oneParagraph starts with "<p>"} then
set newBodyText to newBodyText & "<p>"
end if
set newBodyText to newBodyText & oneParagraph
这里的问题是,如果段落(或单行)用除 a 之外的任何其他 HTML 标记包裹,
标签 该脚本全面包裹
标签。
脚本的另一部分检查段落末尾的结束标签,其作用几乎相同。
-- If already ends with </p>, don't append another one
if not (oneParagraph ends with "</p>") then
set newBodyText to newBodyText & "</p>"
end if
set newBodyText to newBodyText & return
示例:
Foobar
变为
Foobar
;
在另一个问题中Applescript 和“开头为”运算符,@lri 很友善地为我提供了一个与它。
on startswith(txt, l)
repeat with v in l
if txt starts with v then return true
end repeat
false
end startswith
startswith("abc", {"a", "d", "e"}) -- true
他的另一个建议也可以在此网站上找到用applescript 上的标签
使用 MarsEdit.app 实施这些建议对我来说是另一个问题。
我将整个脚本上传到pastebin 上。 Pastebin:MarsEdit.app,用 换行
标签脚本 如果有人可以帮助我根据 @lri 的建议编辑脚本,那就太好了。提前致谢。
Im currently using a script in MarsEdit.app which has a flaw. It checks the HTML document for cases where paragraphs are wrapped with <p>
tags as follows:
-- If already starts with <p>, don't prepend another one
if not {oneParagraph starts with "<p>"} then
set newBodyText to newBodyText & "<p>"
end if
set newBodyText to newBodyText & oneParagraph
The problem here is that if the paragraph (or single line) is wrapped with any other HTML tag other than a <p>
tag the script wraps <p>
tags across the board.
Another portion of the script, which checks for ending tags at the end of the paragraph does pretty much the same thing.
-- If already ends with </p>, don't append another one
if not (oneParagraph ends with "</p>") then
set newBodyText to newBodyText & "</p>"
end if
set newBodyText to newBodyText & return
Example:
<h5>
Foobar </h5>
becomes
<p><h5>
Foobar </h5></p>
In another question Applescript and "starts with" operator, @lri was kind enough to provide me a solution related to it.
on startswith(txt, l)
repeat with v in l
if txt starts with v then return true
end repeat
false
end startswith
startswith("abc", {"a", "d", "e"}) -- true
and another of his recommendations can be found on this website as well Wrap lines with tags on applescript
Implementing these recommendations with MarsEdit.app is another issue for me.
I uploaded the entire script on pastebin. Pastebin: MarsEdit.app, wrap line with
tags script If anyone can help me edit the script to @lri's recommendations that would be great. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AppleScript:
Ruby appscript:
这些假设以(空格和)< 开头的任何内容code>< 是一个标签。
AppleScript:
Ruby appscript:
These assume that anything starting with (white space and)
<
is a tag.你可以使用另一种更强大的语言通过在applescript中运行shell命令来完成这个过程
基本上你可以在终端窗口中运行任何你想运行的东西,就像这样
假设你的桌面上有一个test.txt文件你可以运行它并且它会包装所有带有 p 标签的行
,如果你想运行一个 php 文件,你只需这样做
you could do this process using another stronger language by running shell commands in applescript
basiclly you can run anything that you would in a terminal window like this
lets assume you have a test.txt file on your desktop you could run this and it would wrap all the lines with p tag
and if you want to run a php file you just do