htmlentities
ホームページやBLOG等にHTMLやXMLなんかを投稿する場合の
htmlentities変換
CotEditor用とJedit Ω用
選択部分のテキストを変換します。
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, " ", " ")
set theHtmlEntitiesText to my doReplace(theHtmlEntitiesText, "\t", "	")
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, " ", " ")
set theHtmlEntitiesText to my doReplace(theHtmlEntitiesText, "\t", "	")
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
| 固定リンク
「JeditXAppleScript」カテゴリの記事
- htmlentities(2021.10.04)
- 【Jedit Ω】選択HTMLをhtmlentities変換してBLOG等に貼り付けられるようにする(2021.09.12)
- AppleScriptでの改行(2011.12.24)
- [make new document] properties付きでドキュメントを作る(2011.12.23)