AppleScript的包装线,HTML标签和MarsEdit.app脚本问题 [英] Applescript wrap lines with HTML tags and MarsEdit.app script problem

查看:226
本文介绍了AppleScript的包装线,HTML标签和MarsEdit.app脚本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯目前使用MarsEdit.app一个脚本,有一个缺陷。它检查的情况下HTML文档,其中段落包裹着< P> 标签如下:

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

这里的问题是,如果段落(或单行)是包裹着比&LT以外的任何其他HTML标记; P&GT; 标记脚本包&LT; p&GT; 全线标记

的脚本,它检查在段末结束标记的另一部分做pretty同样的事情。

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

例如:

&LT;&H5 GT; Foobar的&LT; / H5&GT;

变为

&LT; P&GT;&LT; H5&GT; Foobar的&LT; / H5&GT;&LT; / P&GT;

在另一个问题的AppleScript和&QUOT与......开始;运营商,@lri还跟我提供与此相关的一个解决方案。

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

和另一个他的建议可以在这个网站上找到,以及总结对AppleScript的与标记线

and another of his recommendations can be found on this website as well Wrap lines with tags on applescript

实现与MarsEdit.app这些建议是另外一个问题对我来说。

Implementing these recommendations with MarsEdit.app is another issue for me.

我上载引擎收录整个脚本。 引擎收录:MarsEdit.app,用

标签的脚本包线如果有人能帮助我编辑脚本@ LRI的建议,将是巨大的。先谢谢了。

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.

推荐答案

AppleScript的:

AppleScript:

tell application "MarsEdit" to set txt to current text of document 1
set paras to paragraphs of txt

repeat with i from 1 to (count paras)
    set v to item i of paras
    ignoring white space
        if not (v is "" or v starts with "<") then
            set item i of paras to "<p>" & v & "</p>"
        end if
    end ignoring
end repeat

set text item delimiters to ASCII character 10
tell application "MarsEdit" to set current text of document 1 to paras as text


红宝石appscript

require 'appscript'; include Appscript

doc = app('MarsEdit').documents[0]
lines = doc.current_text.get.gsub(/\r\n?/, "\n").split("\n")

for i in 0...lines.size
    next if lines[i] =~ /^\s*$/ or lines[i] =~ /^\s*</
    lines[i] = "<p>#{lines[i]}</p>"
end

doc.current_text.set(lines.join("\n"))


这些假设任何事情,从(空格和)&LT; 是一个标记

这篇关于AppleScript的包装线,HTML标签和MarsEdit.app脚本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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