| HTMLでの名前 | RGBのコード | Jedit4での名前 | RGBのコード | |
| ■ | black | #000000 | 黒 | {0, 0, 0} |
| ■ | gray | #808080 | 灰 | {32768, 32768, 32768} |
| ■ | silver | #C0C0C0 | 銀 | {49152, 49152, 49152} |
| ■ | white | #FFFFFF | 白 | {65535, 65535, 65535} |
| ■ | maroon | #800000 | えび茶 | {32768, 0, 0} |
| ■ | red | #FF0000 | 赤 | {65535, 0, 0} |
| ■ | purple | #800080 | 紫 | {32768, 0, 32768} |
| ■ | fuchsia | #FF00FF | ピンク | {65535, 0, 65535} |
| ■ | green | #008000 | 緑 | {0, 32768, 0} |
| ■ | lime | #00FF00 | 黄緑 | {0, 65535, 0} |
| ■ | olive | #808000 | うぐいす | {32768, 32768, 0} |
| ■ | yellow | #FFFF00 | 黄 | {65535, 65535, 0} |
| ■ | navy | #000080 | 紺 | {0, 0, 32768} |
| ■ | blue | #0000FF | 青 | {0, 0, 65535} |
| ■ | teal | #008080 | 青緑 | {0, 32768, 32768} |
| ■ | aqua | #00FFFF | 水 | {0, 65535, 65535} |
言うまでもないですけど、あるアプリケーションでの文字の色のコードなんかを調べるには、次のようなスクリプトを実行してみて、履歴や結果のウィンドウに表示されるのを確認すればいいですね。
tell application "Jedit4"
get fore color of first word of selection of front document
-- get style of first word of selection of front document
end tell
tell front document of application "Jedit4"
repeat with theParagraph in every paragraph
find "^%.*$|[^\\\\]%.*$" in theParagraph with grep and zenkaku sensitive
-- [^\\\\]?%.*$ではなぜか^%.*$のところが無視されるので
-- つまり?があっても無視されて[^\\\\]%.*$と解釈されちゃう?
-- でもこの正規表現も本当に適切なものなのか?たぶんいいと思うのですがご指摘下さい
if result is true then
tell selection
if first character is not "%" then -- 余分な先頭文字を除くため
find "%.*$" in it with grep and zenkaku sensitive
end if
set fore color to {65535, 0, 65535}
-- ピンクにしてみました,黒にすれば元に戻すスクリプトになりますね
-- 以下のようにするとコメントの部分を削除することができます
-- set contents to ""
-- また、以下のようにすれば%を消して、アンコメント (コメントでなく) します
-- set first character to ""
end tell
end if
end repeat
end tell
tell front document of application "Jedit4"
set first_paraid to paragraph number of first paragraph of selection
set last_paraid to paragraph number of last paragraph of selection
repeat with paraid from first_paraid to last_paraid
find "^%.*$|[^\\\\]%.*$" in paragraph paraid with grep and zenkaku sensitive
if result is true then
if paragraph number of selection is paraid then
-- このif文は不要に思えるんだけど、findでパラグラフを指定しているのに、
-- 間違った(その上?の)パラグラフを処理する場合があるから
tell selection
if first character is not "%" then
find "%.*$" in it with grep and zenkaku sensitive
end if
set fore color to {65535, 0, 65535}
-- 以下のようにすれば、選択行内にあるコメントの頭から%を取ってアンコメントします
-- 下のスクリプトの逆操作になりますね
-- set first character to ""
end tell
end if
end if
end repeat
set selection to paragraphs first_paraid thru last_paraid
-- 上の文はなくてもいいけど、処理したパラグラフを選択状態にする
end tell
tell front document of application "Jedit4"
set first_paraid to paragraph number of first paragraph of selection
set last_paraid to paragraph number of last paragraph of selection
repeat with paraid from first_paraid to last_paraid
replace "^" to "%" in paragraph paraid with grep, case sensitive and zenkaku sensitive
-- set fore color of paragraph paraid to {65535, 0, 65535}
-- 後でアンコメントする可能性があれば、無理に色を変えたりしない方がいいかも
end repeat
set selection to paragraphs first_paraid thru last_paraid
-- 上の文はなくてもいいけど、処理したパラグラフを選択状態にする
end tell
set basicColors to {¬
{name:"black", RGBcolor:{0, 0, 0}, hexRGB256:"000000"}, ¬
{name:"gray", RGBcolor:{32768, 32768, 32768}, hexRGB256:"808080"}, ¬
{name:"silver", RGBcolor:{49152, 49152, 49152}, hexRGB256:"C0C0C0"}, ¬
{name:"white", RGBcolor:{65535, 65535, 65535}, hexRGB256:"FFFFFF"}, ¬
{name:"maroon", RGBcolor:{32768, 0, 0}, hexRGB256:"800000"}, ¬
{name:"red", RGBcolor:{65535, 0, 0}, hexRGB256:"FF0000"}, ¬
{name:"purple", RGBcolor:{32768, 0, 32768}, hexRGB256:"800080"}, ¬
{name:"fuchsia", RGBcolor:{65535, 0, 65535}, hexRGB256:"FF00FF"}, ¬
{name:"green", RGBcolor:{0, 32768, 0}, hexRGB256:"008000"}, ¬
{name:"lime", RGBcolor:{0, 65535, 0}, hexRGB256:"00FF00"}, ¬
{name:"olive", RGBcolor:{32768, 32768, 0}, hexRGB256:"808000"}, ¬
{name:"yellow", RGBcolor:{65535, 65535, 0}, hexRGB256:"FFFF00"}, ¬
{name:"navy", RGBcolor:{0, 0, 32768}, hexRGB256:"000080"}, ¬
{name:"blue", RGBcolor:{0, 0, 65535}, hexRGB256:"0000FF"}, ¬
{name:"teal", RGBcolor:{0, 32768, 32768}, hexRGB256:"008080"}, ¬
{name:"aqua", RGBcolor:{0, 65535, 65535}, hexRGB256:"00FFFF"}}
tell front document of application "Jedit4"
replace tab to " " in it -- タブを4つのスペースにしてみました
replace "&" to "&" in it with case sensitive and zenkaku sensitive
replace "\"" to """ in it with case sensitive and zenkaku sensitive
replace "<" to "<" in it with case sensitive and zenkaku sensitive
replace ">" to ">" in it with case sensitive and zenkaku sensitive
replace "≤" to "≤" in it with case sensitive and zenkaku sensitive
replace "≥" to "≥" in it with case sensitive and zenkaku sensitive
replace "«" to "«" in it with case sensitive and zenkaku sensitive
replace "»" to "»" in it with case sensitive and zenkaku sensitive
replace "≠" to "≠" in it with case sensitive and zenkaku sensitive
replace "¬" to "¬" in it with case sensitive and zenkaku sensitive
-- replace "\\\\" to "\" in it with case sensitive and zenkaku sensitive -- 円記号がバックスラッシュで表示される?
-- replace "'" to "'" in it with case sensitive and zenkaku sensitive -- シングルクォート、これもやるべきなのかしら?'と書いてもいい?
-- 必要ならば上のような文を、もっと追加するといいでしょう
repeat with idx from (number of every style run) to 1 by -1
-- 文書中の何番目であるかというのを利用している場合、後ろから扱うことでうまく処理できる
-- この場合は前からでも大丈夫だと思うけど、前から処理すると番号 (順番) が変わってしまう場合があるので
select style run idx
tell selection
set digitHex to "0123456789ABCDEF"
set codeStyle to ""
set theColor to fore color
if theColor is not {0, 0, 0} then -- 黒のところはそのままにして、表1の残り15色だったら
set theRGB256 to {(item 1 of theColor) div 256, (item 2 of theColor) div 256, (item 3 of theColor) div 256}
repeat with idxRGB from 1 to 3
set decNum to item idxRGB of theRGB256
set hexNum to ((character (decNum div 16 + 1) of digitHex) & (character (decNum mod 16 + 1) of digitHex)) as string
set item idxRGB of theRGB256 to hexNum
end repeat
set theRGB256 to ((item 1 of theRGB256) & (item 2 of theRGB256) & (item 3 of theRGB256)) as string
repeat with basicColor in basicColors
if (theColor is RGBcolor of basicColor) or (theRGB256 is hexRGB256 of basicColor) then
set codeStyle to "color:" & (name of basicColor) & ";"
exit repeat
end if
end repeat
if codeStyle is "" then set codeStyle to "color:#" & theRGB256 & ";"
end if
set theStyle to style
if theStyle is not plain then -- プレインテクストでなかったら
if theStyle contains bold then set codeStyle to codeStyle & space & "font-weight:bold;"
if theStyle contains italic then set codeStyle to codeStyle & space & "font-style:italic;"
if theStyle contains underline then set codeStyle to codeStyle & space & "text-decoration:underline;"
end if
-- 他にもスタイルの形式はありますが、一般にはこれで十分でしょうか
if codeStyle is not "" then
if first character of codeStyle is space then set codeStyle to text 2 thru -1 in codeStyle
if last character of codeStyle is ";" then set codeStyle to text 1 thru -2 in codeStyle
set contents to "<span style=\"" & codeStyle & "\">" & it & "</span>"
end if
end tell
end repeat
end tell