我目前在 MarsEdit.app 中使用一个有缺陷的脚本。它会检查 HTML 文档中是否有段落被标签包裹的情况,<p>
如下所示:
-- 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
这里的问题是,如果段落(或单行)被任何其他 HTML 标记而不是<p>
标记包裹,则脚本<p>
会全面包裹标记。
脚本的另一部分,它检查段落末尾的结束标签,它的作用几乎相同。
-- 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
例子:
<h5>
富吧</h5>
变成
<p><h5>
富吧</h5></p>
在另一个问题Applescript and "starts with" operator中,@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
他的另一个建议也可以在这个网站上找到
使用 MarsEdit.app 实施这些建议对我来说是另一个问题。
我将整个脚本上传到了 pastebin。Pastebin:MarsEdit.app,换行
标记脚本如果有人可以帮助我将脚本编辑为@lri 的建议,那就太好了。提前致谢。