以前から、HTMLタグを削除するちょっとしたマクロを使っていましたが、今回、OutlookからHTMLメールを開くと、HTMLタグが入っているので、かなり、多用することになりました。
で、いろいろと、拡張をする必要があったので、以下のようなものになってしまいました。(いやはや、10,000文字を越えてしまったので、コメントアウト部分の008~249を省略)
-----------------
// HTMLタグの削除
// copyright (C) by 甘党のプログラマ
// 基本的には、レイアウトが崩れて見づらいが、とりあえず、テキストに変換したい場合に便利マクロ
// <style> ~ </style>の削除
// 今後も、削除漏れがあれば、この手法で削除できるはず
gofiletop;
while(1) {
// まず、<style>を検索
searchdown "<style>" , nocasesense;
if( result ) {
// 現在のカーソルの保持
#top_x = x;
#top_y = y;
// </style>を検索して
searchdown "</style>" , nocasesense;
if( result ) {
// 範囲選択後、削除
searchdown ">";
right;
if( result ) {
beginsel;
moveto #top_x, #top_y;
delete;
}
}
else {
break;
}
}
else {
break;
}
}
// <div...>と</div...>に、区切りを入れる。
gofiletop;
while (1) {
searchdown "^</?div" , regular, nocasesense;
if( result ) {
insertline;
insert "------------------------------------------------------------------[[br]]";
down;
}
else {
break;
}
}
// 改行コードの保持 ([todo]本当は、適当なコントロールコードが良いはず)
replaceallfast "<br>" , "[[br]]" , nocasesense;
// <...>タグの削除
replaceallfast "(<(n|[^>])+>)" , "" , regular, nocasesense;
// 空白行の削除の削除
// replaceallfast "^ *n" , "" , regular, nocasesense;
replaceallfast "n" , "" , regular, nocasesense;
// 元が<br>(現[[br]])を改行 ([todo]本当は、適当なコントロールコードが良いはず)
replaceallfast "[[br]]" , "n" , nocasesense;
if( ! result ) beep;
// 特殊文字の変換 (遅くなるので、最小限のものを有効にしたいので、変換しそこなったものに気が付いたら、コメントアウトを外すようにすると良い
//001 " " " """ クォーテーション quotation mark = APL quote
replaceallfast """ , """ ; //クォーテーション quotation mark = APL quote
// replaceallfast """ , """ ; //クォーテーション quotation mark = APL quote
// replaceallfast """ , """ ; //クォーテーション quotation mark = APL quote
//002 & & & "&" アンパサンド ampersand
replaceallfast "&" , "&" ; //アンパサンド ampersand
// replaceallfast "&" , "&" ; //アンパサンド ampersand
// replaceallfast "&" , "&" ; //アンパサンド ampersand
//003 < < < "<" 小なり less-than sign
replaceallfast "<" , "<" ; //小なり less-than sign
// replaceallfast "<" , "<" ; //小なり less-than sign
// replaceallfast "<" , "<" ; //小なり less-than sign
//004 > > > ">" 大なり greater-than sign
replaceallfast ">" , ">" ; //大なり greater-than sign
// replaceallfast ">" , ">" ; //大なり greater-than sign
// replaceallfast ">" , ">" ; //大なり greater-than sign
//005     " " 空白 no-break space = non-breaking space
replaceallfast " " , " "; //空白 no-break space = non-breaking space
// replaceallfast " ", " "; //空白 no-break space = non-breaking space
// replaceallfast " " , " "; //空白 no-break space = non-breaking space
// //006 ¡ ¡ ¡ "!" inverted exclamation mark
// replaceallfast "¡" , "!"; // inverted exclamation mark
// replaceallfast "¡", "!"; // inverted exclamation mark
// replaceallfast "¡" , "!"; // inverted exclamation mark
// //007 ¢ ¢ ¢ "¢" セント cent sign
// replaceallfast "¢" , "¢"; //セント cent sign
// replaceallfast "¢", "¢"; //セント cent sign
// replaceallfast "¢" , "¢"; //セント cent sign
// ....(省略)
// //250 ‹ ‹ ‹ "?" single left-pointing angle quotation mark
// replaceallfast "‹" , "?"; // single left-pointing angle quotation mark
// replaceallfast "‹", "?"; // single left-pointing angle quotation mark
// replaceallfast "‹" , "?"; // single left-pointing angle quotation mark
gofiletop;
endmacro;
で、いろいろと、拡張をする必要があったので、以下のようなものになってしまいました。(いやはや、10,000文字を越えてしまったので、コメントアウト部分の008~249を省略)
-----------------
// HTMLタグの削除
// copyright (C) by 甘党のプログラマ
// 基本的には、レイアウトが崩れて見づらいが、とりあえず、テキストに変換したい場合に便利マクロ
// <style> ~ </style>の削除
// 今後も、削除漏れがあれば、この手法で削除できるはず
gofiletop;
while(1) {
// まず、<style>を検索
searchdown "<style>" , nocasesense;
if( result ) {
// 現在のカーソルの保持
#top_x = x;
#top_y = y;
// </style>を検索して
searchdown "</style>" , nocasesense;
if( result ) {
// 範囲選択後、削除
searchdown ">";
right;
if( result ) {
beginsel;
moveto #top_x, #top_y;
delete;
}
}
else {
break;
}
}
else {
break;
}
}
// <div...>と</div...>に、区切りを入れる。
gofiletop;
while (1) {
searchdown "^</?div" , regular, nocasesense;
if( result ) {
insertline;
insert "------------------------------------------------------------------[[br]]";
down;
}
else {
break;
}
}
// 改行コードの保持 ([todo]本当は、適当なコントロールコードが良いはず)
replaceallfast "<br>" , "[[br]]" , nocasesense;
// <...>タグの削除
replaceallfast "(<(n|[^>])+>)" , "" , regular, nocasesense;
// 空白行の削除の削除
// replaceallfast "^ *n" , "" , regular, nocasesense;
replaceallfast "n" , "" , regular, nocasesense;
// 元が<br>(現[[br]])を改行 ([todo]本当は、適当なコントロールコードが良いはず)
replaceallfast "[[br]]" , "n" , nocasesense;
if( ! result ) beep;
// 特殊文字の変換 (遅くなるので、最小限のものを有効にしたいので、変換しそこなったものに気が付いたら、コメントアウトを外すようにすると良い
//001 " " " """ クォーテーション quotation mark = APL quote
replaceallfast """ , """ ; //クォーテーション quotation mark = APL quote
// replaceallfast """ , """ ; //クォーテーション quotation mark = APL quote
// replaceallfast """ , """ ; //クォーテーション quotation mark = APL quote
//002 & & & "&" アンパサンド ampersand
replaceallfast "&" , "&" ; //アンパサンド ampersand
// replaceallfast "&" , "&" ; //アンパサンド ampersand
// replaceallfast "&" , "&" ; //アンパサンド ampersand
//003 < < < "<" 小なり less-than sign
replaceallfast "<" , "<" ; //小なり less-than sign
// replaceallfast "<" , "<" ; //小なり less-than sign
// replaceallfast "<" , "<" ; //小なり less-than sign
//004 > > > ">" 大なり greater-than sign
replaceallfast ">" , ">" ; //大なり greater-than sign
// replaceallfast ">" , ">" ; //大なり greater-than sign
// replaceallfast ">" , ">" ; //大なり greater-than sign
//005     " " 空白 no-break space = non-breaking space
replaceallfast " " , " "; //空白 no-break space = non-breaking space
// replaceallfast " ", " "; //空白 no-break space = non-breaking space
// replaceallfast " " , " "; //空白 no-break space = non-breaking space
// //006 ¡ ¡ ¡ "!" inverted exclamation mark
// replaceallfast "¡" , "!"; // inverted exclamation mark
// replaceallfast "¡", "!"; // inverted exclamation mark
// replaceallfast "¡" , "!"; // inverted exclamation mark
// //007 ¢ ¢ ¢ "¢" セント cent sign
// replaceallfast "¢" , "¢"; //セント cent sign
// replaceallfast "¢", "¢"; //セント cent sign
// replaceallfast "¢" , "¢"; //セント cent sign
// ....(省略)
// //250 ‹ ‹ ‹ "?" single left-pointing angle quotation mark
// replaceallfast "‹" , "?"; // single left-pointing angle quotation mark
// replaceallfast "‹", "?"; // single left-pointing angle quotation mark
// replaceallfast "‹" , "?"; // single left-pointing angle quotation mark
gofiletop;
endmacro;
※コメント投稿者のブログIDはブログ作成者のみに通知されます