0

現在、MarsEdit.app でスクリプトを使用していますが、これには欠陥があります。次のように、段落が<p>タグで囲まれている場合について、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

ここでの問題は、段落 (または 1 行) がタグ以外の 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 と "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

彼の別の推奨事項は、このWebサイトでも見つけることができますAppleScriptのタグで行をラップする

これらの推奨事項を MarsEdit.app で実装することは、私にとって別の問題です。

スクリプト全体をペーストビンにアップロードしました。Pastebin: MarsEdit.app で行を折り返す

タグ スクリプト@lri の推奨事項に合わせてスクリプトを編集するのを手伝ってくれる人がいれば、それは素晴らしいことです。前もって感謝します。

4

2 に答える 2

1

AppleScriptでシェルコマンドを実行することにより、別のより強力な言語を使用してこのプロセスを実行できます

基本的に、このようなターミナルウィンドウで実行することは何でも実行できます

デスクトップに test.txt ファイルがあると仮定して、これを実行すると、すべての行が p タグでラップされます。

set dir to quoted form of POSIX path of (path to desktop)
set results to do shell script "cd " & dir & "
awk ' { print \"<p>\"$0\"</p>\" } ' test.txt"

phpファイルを実行したい場合は、次のようにします

set dir to quoted form of POSIX path of 'path:to:php_folder")
set results to do shell script "cd " & dir & "
php test.php"
于 2011-05-09T19:01:42.720 に答える
1

アップルスクリプト:

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

Ruby アプリスクリプト:

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"))

これらは、(空白と) で始まるものはすべて<タグであると想定しています。

于 2011-05-10T13:49:18.653 に答える