« mobileconfigを使ったフォントインストール | トップページ | Acrobat21.007.20096xアップデート »

htmlentities

ホームページやBLOG等にHTMLやXMLなんかを投稿する場合の
htmlentities変換
CotEditor用とJedit Ω用
選択部分のテキストを変換します。


ダウンロード - scripts.zip


Htmlentities


tell application "Jedit Ω"
tell front document
set TheTextToEncode to selected text
end tell
end tell

----スラッシュ文字のエスケープ
set TheTextToEncode to my doReplace(TheTextToEncode, "'", "\\'")
set TheTextToEncode to my doReplace(TheTextToEncode, "\"", "\\\"")


set theHtmlEntitiesText to do shell script ("echo \"<?php print(htmlentities('" & TheTextToEncode & "'));?>\" | php")

----改行変換とスペース変換タブ変換はお好みで
set theHtmlEntitiesText to my doReplace(theHtmlEntitiesText, "\r", "\n")
set theHtmlEntitiesText to my doReplace(theHtmlEntitiesText, " ", "&nbsp;")
set theHtmlEntitiesText to my doReplace(theHtmlEntitiesText, "\t", "&#9;")


tell application "Jedit Ω"
tell front document
set selected text to theHtmlEntitiesText
end tell
end tell




--------------文字の置き換えサブルーチン
to doReplace(theText, theOrgStr, theNewStr)
set theOldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to theOrgStr
set theTmpList to every text item of theText
set AppleScript's text item delimiters to theNewStr
set theReplaceStr to theTmpList as text
set AppleScript's text item delimiters to theOldDelim
return theReplaceStr
end doReplace



tell application "CotEditor"
tell front document
set TheTextToEncode to contents of selection
end tell
end tell


----スラッシュ文字のエスケープ
set TheTextToEncode to my doReplace(TheTextToEncode, "'", "\\'")
set TheTextToEncode to my doReplace(TheTextToEncode, "\"", "\\\"")


set theHtmlEntitiesText to do shell script ("echo \"<?php print(htmlentities('" & TheTextToEncode & "'));?>\" | php")

----改行変換とスペース変換タブ変換はお好みで
set theHtmlEntitiesText to my doReplace(theHtmlEntitiesText, "\r", "\n")
set theHtmlEntitiesText to my doReplace(theHtmlEntitiesText, " ", "&nbsp;")
set theHtmlEntitiesText to my doReplace(theHtmlEntitiesText, "\t", "&#9;")


tell application "CotEditor"
tell front document
set contents of selection to theHtmlEntitiesText
end tell
end tell




--------------文字の置き換えサブルーチン
to doReplace(theText, theOrgStr, theNewStr)
set theOldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to theOrgStr
set theTmpList to every text item of theText
set AppleScript's text item delimiters to theNewStr
set theReplaceStr to theTmpList as text
set AppleScript's text item delimiters to theOldDelim
return theReplaceStr
end doReplace

|

« mobileconfigを使ったフォントインストール | トップページ | Acrobat21.007.20096xアップデート »

JeditXAppleScript」カテゴリの記事